Forums

Output boards, SPI vs I2C

Started by David Lesher March 24, 2017
I pondering a microcontroller project that will need a number (say 24)
output relays.

Is there a reason to use I2C over SPI? It looks like there are 8-channel
boards of both ilks, and I don't know if one has an advantage in this case.

-- 
A host is a host from coast to coast.................wb8foz@nrk.com
& no one will talk to a host that's close..........................
Unless the host (that isn't close).........................pob 1433
is busy, hung or dead....................................20915-1433
On Sat, 25 Mar 2017 02:46:33 +0000 (UTC), David Lesher
<wb8foz@panix.com> wrote:

>I pondering a microcontroller project that will need a number (say 24) >output relays. > >Is there a reason to use I2C over SPI? It looks like there are 8-channel >boards of both ilks, and I don't know if one has an advantage in this case.
I2C across connectors isn't recommended. SPI is far more robust, though can be a bit more complicated in large systems.
On 3/24/2017 10:46 PM, David Lesher wrote:
> I pondering a microcontroller project that will need a number (say 24) > output relays. > > Is there a reason to use I2C over SPI? It looks like there are 8-channel > boards of both ilks, and I don't know if one has an advantage in this case.
I2C is a serial bus (with a spec) with all devices connected in parallel. SPI is a functional description rather than a real spec, but is so simple it is not hard to make it work. SPI devices can be connected in parallel with separate select pins, or all in series being controlled as one long shift register. I2C runs at a basic rate of 100 kbps with a 400 kbps mode as well as faster modes at 1 Mbps and up. 400 kbps is generally supported, but the faster modes are not universal. SPI runs at whatever speed the devices work at. I2C has a protocol that you will need to program. SPI specified no protocol other than shifting data in and out. Any protocol is defined by the slaves you choose. All things being equal (whatever that means as I2C and SPI have very little equal) I would pick SPI for driving 24 relays because the "protocol" should be very simple (shift out the data) and I2C can be more complex to implement. I'd probably wire three boards serially and see if that works. If not, I would wire them in parallel with three separate chip selects. -- Rick C
rickman <gnuarm@gmail.com> writes:



....

>All things being equal (whatever that means as I2C and SPI >have very little equal) I would pick SPI for driving 24 relays >because the "protocol" should be very simple (shift out the >data) and I2C can be more complex to implement.
>I'd probably wire three boards serially and see if that works. >If not, I would wire them in parallel with three separate chip >selects.
This would be driven by a <http://www.digital-loggers.com/plchw.html> which claims to support both flavors. Data rate is virtally irrelevent here; I need a response time far slower than the relays themselves are..... My hand may be forced by what boards are actually available. I found <https://www.industrologic.com/r8spiprod.htm> and <http://lightsosoft.com/sites/default/files/I2C-Relay8-H_040813_1240.pdf> but many other boards are not what they seem to be, or are from across the pond. <http://jap.hu/electronic/relay_module.html> Not sure I grasp "wire three boards serially" but we can spare chip select outputs. -- A host is a host from coast to coast.................wb8foz@nrk.com & no one will talk to a host that's close.......................... Unless the host (that isn't close).........................pob 1433 is busy, hung or dead....................................20915-1433
krw@notreal.com writes:

>>Is there a reason to use I2C over SPI? It looks like there are 8-channel >>boards of both ilks, and I don't know if one has an advantage in this case.
>I2C across connectors isn't recommended. SPI is far more robust, >though can be a bit more complicated in large systems.
By this you mean ribbon cable jumpers & headers are ixnay? -- A host is a host from coast to coast.................wb8foz@nrk.com & no one will talk to a host that's close.......................... Unless the host (that isn't close).........................pob 1433 is busy, hung or dead....................................20915-1433
On 3/26/2017 12:11 AM, David Lesher wrote:
> rickman <gnuarm@gmail.com> writes: > > > > ..... > >> All things being equal (whatever that means as I2C and SPI >> have very little equal) I would pick SPI for driving 24 relays >> because the "protocol" should be very simple (shift out the >> data) and I2C can be more complex to implement. > >> I'd probably wire three boards serially and see if that works. >> If not, I would wire them in parallel with three separate chip >> selects. > > This would be driven by a > <http://www.digital-loggers.com/plchw.html> > which claims to support both flavors.
I can't find how this "PLC Hardware" item fits into their product line. Your web page shows this item, but every page I find on their site only points to a wifi PLC. Is this the same thing? They also have videos on every page which I hate! Oh, I see. The page you link to is for the "hardware" and the other pages are a general PLC page and a software PLC page, etc. $89 sounds like a bargain.
> Data rate is virtally irrelevent here; I need a response time > far slower than the relays themselves are..... > > My hand may be forced by what boards are actually available. I > found <https://www.industrologic.com/r8spiprod.htm> and
The manual for this one says it uses optoisolators on the inputs with a 1 kohm current limiting resistor. They recommend a minimum of 0.5 mA current, bit prefer 10 mA. 10 mA would require 12 volt drive. The digital outputs on the PLC are open collector relay drivers. They will be compatible and you can use the power supply to the PLC as the common power to the + terminal on each of the three SPI signals. Or I think I see a direct input connector for the open collector outputs, J1. They don't mention using these inputs, but what's the diff? The optos will be less sensitive to noise I expect. There is some irony in that they are using the same relay drivers your PLC uses for the digital outputs. This unit has no serial output, so the SPI protocol will require this unit to be used *only* in the parallel mode with a dedicated strobe. To drive 24 relays will use five digital outputs.
> <http://lightsosoft.com/sites/default/files/I2C-Relay8-H_040813_1240.pdf>
This board seems to be I2C only. That would require I2C support in your PLC. Does the PLC have that in the software?
> but many other boards are not what they seem to be, or are from across the pond. > <http://jap.hu/electronic/relay_module.html>
Another I2C board.
> Not sure I grasp "wire three boards serially" but we can spare chip select > outputs.
Normally SPI devices have a serial data input MOSI (master out, slave in) and and serial output MISO (care to guess what this one means?). If you connect the MISO of the first module to the MOSI of the second module, etc before connecting the MISO of the last module to the MISO of the master module it will form a daisy chain of N * 8 bits. So the PLC will need to shift out 24 bits before removing the strobe. But the one SPI relay board has no serial output (MISO) and must be used in parallel. Then the PLC output will drive all the MOSI (aka data) inputs together as well as a PLC output that will drive all the Clock inputs together. The Strobe signals will all have to be separate. With I2C, you just wire the two outputs to each of the two inputs on all three boards (with a pullup resistor somewhere in the path). The relay boards will need to have jumpers to set a unique address on the bus. Each byte you wish to send to control a set of relays requires two bytes, one to set the address and one to set the data. Just a comment, some of the lightsosoft.com documentation isn't so clear. I'm not sure how to wire up the I2C interface. This is what they say: The specific pins you need for I2C communications are: TB19, &ldquo;SDA&rdquo; TB20, &ldquo;SCL&rdquo; TB18, &ldquo;GND&rdquo; TB19, &ldquo;5V&rdquo; I see none of these notations in any of the illustrations. I could make an educated guess, but why can't they make it clear in the manual *AND* on the board? The notation they show looks like JTAG and SPI labels. Ask if they have an SPI version of the board. I bet they do. -- Rick C
rickman <gnuarm@gmail.com> writes:

>> This would be driven by a >> <http://www.digital-loggers.com/plchw.html> >> which claims to support both flavors.
>Oh, I see. The page you link to is for the "hardware" and the other >pages are a general PLC page and a software PLC page, etc. $89 sounds >like a bargain.
>> Data rate is virtally irrelevent here; I need a response time >> far slower than the relays themselves are..... >> >> My hand may be forced by what boards are actually available. I >> found <https://www.industrologic.com/r8spiprod.htm> and
>The manual for this one says it uses optoisolators on the inputs with a >1 kohm current limiting resistor. They recommend a minimum of 0.5 mA >current, bit prefer 10 mA. 10 mA would require 12 volt drive. The >digital outputs on the PLC are open collector relay drivers. They will >be compatible and you can use the power supply to the PLC as the common >power to the + terminal on each of the three SPI signals. Or I think I >see a direct input connector for the open collector outputs, J1. They >don't mention using these inputs, but what's the diff? The optos will >be less sensitive to noise I expect. There is some irony in that they >are using the same relay drivers your PLC uses for the digital outputs.
Yes, I noticed that aspect.
>This unit has no serial output, so the SPI protocol will require this >unit to be used *only* in the parallel mode with a dedicated strobe.
>To drive 24 relays will use five digital outputs.
Not sure I follow; there is SPI on the board, but thinking out loud, we would have to add selection to the existing SPI users, the display, touch screen, and flash.....
>> <http://lightsosoft.com/sites/default/files/I2C-Relay8-H_040813_1240.pdf>
>This board seems to be I2C only. That would require I2C support in your >PLC. Does the PLC have that in the software?
<http://www.digital-loggers.com/plchw.html> I2C Memory Expansion Socket There is a 32K socketed EEPROM that can be used for non-volatile storage that's also connected to the I2C bus. Because it has a large write-endurance, EEPROM is usually the best place to store data that's frequently updated. Other 5V chips a standard 8 pin DIP package such as FRAM, SRAM, Larger EEPROM etc can be substituted. The pinout is 1 = AO 2 = A1 3 = A2 4 = GND 5 = SBA 6 = SCL 7 = TEST (grounded) 8 = 5V VCC. ` The socket could also be used as an expansion port via an 8-pin ribbon cable plug. Although it's a bit inconvenient, this chip has been located beneath the clock module to gain space for reprogramming headers.
>> but many other boards are not what they seem to be, or are from across the pond. >> <http://jap.hu/electronic/relay_module.html>
>Another I2C board.
>> Not sure I grasp "wire three boards serially" but we can spare chip select >> outputs.
>Normally SPI devices have a serial data input MOSI (master out, slave >in) and and serial output MISO (care to guess what this one means?). If >you connect the MISO of the first module to the MOSI of the second >module, etc before connecting the MISO of the last module to the MISO of >the master module it will form a daisy chain of N * 8 bits. So the PLC >will need to shift out 24 bits before removing the strobe. But the one >SPI relay board has no serial output (MISO) and must be used in >parallel. Then the PLC output will drive all the MOSI (aka data) inputs >together as well as a PLC output that will drive all the Clock inputs >together. The Strobe signals will all have to be separate.
>With I2C, you just wire the two outputs to each of the two inputs on all >three boards (with a pullup resistor somewhere in the path). The relay >boards will need to have jumpers to set a unique address on the bus. >Each byte you wish to send to control a set of relays requires two >bytes, one to set the address and one to set the data.
Do you echo krw's concerns on I2C cabling?
>Just a comment, some of the lightsosoft.com documentation isn't so >clear. I'm not sure how to wire up the I2C interface. This is what >they say:
>The specific pins you need for I2C communications are:
>TB19, SD >TB20, SCL >TB18, GND >TB19, 5V
>I could make an educated guess, but why can't they make it >clear in the manual *AND* on the board?
I have asked such questions about every board I have found so far. -- A host is a host from coast to coast.................wb8foz@nrk.com & no one will talk to a host that's close.......................... Unless the host (that isn't close).........................pob 1433 is busy, hung or dead....................................20915-1433
On 3/26/2017 10:41 AM, David Lesher wrote:
> rickman <gnuarm@gmail.com> writes: > >>> This would be driven by a >>> <http://www.digital-loggers.com/plchw.html> >>> which claims to support both flavors. > >> Oh, I see. The page you link to is for the "hardware" and the other >> pages are a general PLC page and a software PLC page, etc. $89 sounds >> like a bargain. > > >>> Data rate is virtally irrelevent here; I need a response time >>> far slower than the relays themselves are..... >>> >>> My hand may be forced by what boards are actually available. I >>> found <https://www.industrologic.com/r8spiprod.htm> and > >> The manual for this one says it uses optoisolators on the inputs with a >> 1 kohm current limiting resistor. They recommend a minimum of 0.5 mA >> current, bit prefer 10 mA. 10 mA would require 12 volt drive. The >> digital outputs on the PLC are open collector relay drivers. They will >> be compatible and you can use the power supply to the PLC as the common >> power to the + terminal on each of the three SPI signals. Or I think I >> see a direct input connector for the open collector outputs, J1. They >> don't mention using these inputs, but what's the diff? The optos will >> be less sensitive to noise I expect. There is some irony in that they >> are using the same relay drivers your PLC uses for the digital outputs. > > Yes, I noticed that aspect. > >> This unit has no serial output, so the SPI protocol will require this >> unit to be used *only* in the parallel mode with a dedicated strobe. > >> To drive 24 relays will use five digital outputs. > > Not sure I follow; there is SPI on the board, but thinking out > loud, we would have to add selection to the existing SPI users, > the display, touch screen, and flash.....
Flash??? The other stuff is up to you. I"m just talking about the 24 relays. You didn't mention the other items. Is everything going to be on the 8 digital outputs? SPI Data -->>-- | |--- To all SPI controlled device ports SPI Clk -->>-- | SPI Sel1 -->>-- |--- To SPI relay unit 1 Sel input SPI Sel2 -->>-- |--- To SPI relay unit 2 Sel input SPI Sel3 -->>-- |--- To SPI relay unit 3 Sel input Five signals for 3 relay boards. The display, touch screen and other things they talk about connecting through SPI or I2C connect directly to the CPU. This will not be the same as using the digital outputs. If you want to use the dedicated I/Os on the CPU for the relay drivers you might as well not use the PLC but get a CPU card instead and save some bucks. What does the PLC unit do for you exactly? Does it provide a way of programming it that you understand well that an Arduino won't?
>>> <http://lightsosoft.com/sites/default/files/I2C-Relay8-H_040813_1240.pdf> > >> This board seems to be I2C only. That would require I2C support in your >> PLC. Does the PLC have that in the software? > > <http://www.digital-loggers.com/plchw.html> > I2C Memory Expansion Socket > > There is a 32K socketed EEPROM that can be used for non-volatile > storage that's also connected to the I2C bus. Because it has > a large write-endurance, EEPROM is usually the best place to > store data that's frequently updated. Other 5V chips a standard > 8 pin DIP package such as FRAM, SRAM, Larger EEPROM etc can be > substituted. The pinout is > > 1 = AO > 2 = A1 > 3 = A2 > 4 = GND > 5 = SBA > 6 = SCL > 7 = TEST (grounded) > 8 = 5V VCC. > ` > The socket could also be used as an expansion port via an 8-pin > ribbon cable plug. Although it's a bit inconvenient, this chip > has been located beneath the clock module to gain space for > reprogramming headers.
See my comments above.
>>> but many other boards are not what they seem to be, or are from across the pond. >>> <http://jap.hu/electronic/relay_module.html> > >> Another I2C board. > >>> Not sure I grasp "wire three boards serially" but we can spare chip select >>> outputs. > >> Normally SPI devices have a serial data input MOSI (master out, slave >> in) and and serial output MISO (care to guess what this one means?). If >> you connect the MISO of the first module to the MOSI of the second >> module, etc before connecting the MISO of the last module to the MISO of >> the master module it will form a daisy chain of N * 8 bits. So the PLC >> will need to shift out 24 bits before removing the strobe. But the one >> SPI relay board has no serial output (MISO) and must be used in >> parallel. Then the PLC output will drive all the MOSI (aka data) inputs >> together as well as a PLC output that will drive all the Clock inputs >> together. The Strobe signals will all have to be separate. > >> With I2C, you just wire the two outputs to each of the two inputs on all >> three boards (with a pullup resistor somewhere in the path). The relay >> boards will need to have jumpers to set a unique address on the bus. >> Each byte you wish to send to control a set of relays requires two >> bytes, one to set the address and one to set the data. > > Do you echo krw's concerns on I2C cabling?
It's not an absolute on leaving the CPU board. But both SPI and I2C are sensitive to noise and poor impedance matches. If your wire runs are short you should be ok. Use ribbon cable with every other wire a ground or twisted pairs with a signal wire mated with a ground. How far apart are the PLC and the relay boards?
>> Just a comment, some of the lightsosoft.com documentation isn't so >> clear. I'm not sure how to wire up the I2C interface. This is what >> they say: > >> The specific pins you need for I2C communications are: > >> TB19, SD >> TB20, SCL >> TB18, GND >> TB19, 5V > >> I could make an educated guess, but why can't they make it >> clear in the manual *AND* on the board? > > I have asked such questions about every board I have found so far.
-- Rick C
rickman <gnuarm@gmail.com> writes:

>> Not sure I follow; there is SPI on the board, but thinking out >> loud, we would have to add selection to the existing SPI users, >> the display, touch screen, and flash.....
>Flash??? The other stuff is up to you. I"m just talking about the 24 >relays. You didn't mention the other items. Is everything going to be >on the 8 digital outputs?
I was talking about using the existing I2C or SPI system to also drive the outboard relay boards. It's mentioned only in passing in the writeup.
>The display, touch screen and other things they talk about connecting >through SPI or I2C connect directly to the CPU. This will not be the >same as using the digital outputs. If you want to use the dedicated >I/Os on the CPU for the relay drivers you might as well not use the PLC >but get a CPU card instead and save some bucks. What does the PLC unit >do for you exactly? Does it provide a way of programming it that you >understand well that an Arduino won't?
No, because I'm not the programmer at all; (To paraphrase Bob Pease) <https://tinyurl.com/kby566u> I just solder wires. Two people working with it suggested this platform for this project. ....
>> Do you echo krw's concerns on I2C cabling?
>It's not an absolute on leaving the CPU board. But both SPI and I2C are >sensitive to noise and poor impedance matches. If your wire runs are >short you should be ok. Use ribbon cable with every other wire a ground >or twisted pairs with a signal wire mated with a ground. How far apart >are the PLC and the relay boards?
A few inches; directly adjacent. -- A host is a host from coast to coast.................wb8foz@nrk.com & no one will talk to a host that's close.......................... Unless the host (that isn't close).........................pob 1433 is busy, hung or dead....................................20915-1433
On 3/26/2017 3:49 PM, David Lesher wrote:
> rickman <gnuarm@gmail.com> writes: > >>> Not sure I follow; there is SPI on the board, but thinking out >>> loud, we would have to add selection to the existing SPI users, >>> the display, touch screen, and flash..... > >> Flash??? The other stuff is up to you. I"m just talking about the 24 >> relays. You didn't mention the other items. Is everything going to be >> on the 8 digital outputs? > > I was talking about using the existing I2C or SPI system to also > drive the outboard relay boards. It's mentioned only in passing in the > writeup.
Yes, I saw that. I don't have the various web pages open at the moment, but you may have trouble using the built in SPI port because each port will need an enable. If you go this route you will need to use I2C.
>> The display, touch screen and other things they talk about connecting >> through SPI or I2C connect directly to the CPU. This will not be the >> same as using the digital outputs. If you want to use the dedicated >> I/Os on the CPU for the relay drivers you might as well not use the PLC >> but get a CPU card instead and save some bucks. What does the PLC unit >> do for you exactly? Does it provide a way of programming it that you >> understand well that an Arduino won't? > > No, because I'm not the programmer at all; (To paraphrase Bob > Pease) <https://tinyurl.com/kby566u> I just solder wires. > Two people working with it suggested this platform for this project.
I'm no expert on PLC, but if you aren't using any of the hardware I would suggest you get a microcontroller board instead. There are TONs of good products that are smaller and more cost effective. But I believe PLCs often have a special language for programming, ladder logic. I didn't think it was used much even for PLCs though. Arduinos mostly are programmed in Python. Everything can be programmed in Forth. I'm working with Mecrisp these days. Commercial versions of Forth are SwiftForth from Forth, Inc https://www.forth.com/ and VFX from MPE (Microprocessor Engineering) http://www.mpeforth.com/. Not likely you can change the programmer's point of view, but if they are suggesting using a PLC just to get a CPU they aren't very informed in my opinion.
>>> Do you echo krw's concerns on I2C cabling? > >> It's not an absolute on leaving the CPU board. But both SPI and I2C are >> sensitive to noise and poor impedance matches. If your wire runs are >> short you should be ok. Use ribbon cable with every other wire a ground >> or twisted pairs with a signal wire mated with a ground. How far apart >> are the PLC and the relay boards? > > A few inches; directly adjacent.
Make sure your power connections are solid and direct. A few inches won't hurt. I2C isn't magic. It uses a pullup resistor, about 4.7 kohms sticks in my mind. All devices on the bus are open collector. It should be pretty robust. You can use a smaller value pull up resistor to get a bit more noise robustness. Just check all the data sheets to make sure they can pull the lower value resistor to ground. -- Rick C