Output boards, SPI vs I2C

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.......................... 
 Click to see the full signature
Reply to
David Lesher
Loading thread data ...

I2C across connectors isn't recommended. SPI is far more robust, though can be a bit more complicated in large systems.

Reply to
krw

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
Reply to
rickman

....

This would be driven by a 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 and but many other boards are not what they seem to be, or are from across the pond.

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.......................... 
 Click to see the full signature
Reply to
David Lesher

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.......................... 
 Click to see the full signature
Reply to
David Lesher

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.

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.

This board seems to be I2C only. That would require I2C support in your PLC. Does the PLC have that in the software?

Another I2C board.

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, ?SDA? TB20, ?SCL? TB18, ?GND? TB19, ?5V?

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
Reply to
rickman

Yes, I noticed that aspect.

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.....

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.

Do you echo krw's concerns on I2C cabling?

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.......................... 
 Click to see the full signature
Reply to
David Lesher

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?

See my comments above.

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?

--

Rick C
Reply to
rickman

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.

No, because I'm not the programmer at all; (To paraphrase Bob Pease) I just solder wires. Two people working with it suggested this platform for this project.

....

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.......................... 
 Click to see the full signature
Reply to
David Lesher

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.

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

formatting link
and VFX from MPE (Microprocessor Engineering)
formatting link

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.

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
Reply to
rickman

save some pins: use a 4017 for the enable.

--
This email has not been checked by half-arsed antivirus software
Reply to
Jasen Betts

The OPEN PLC device does not indicate if the I2C and SPI busses are brougth out to a connector. Thus you might be forced to bit bang the OC digital outputs.

Cheers

Reply to
Martin Riddle

74HC138 Mux, 3 to 8

Cheers

Reply to
Martin Riddle

They both do, but I'm not clear if the SPI has enough enable lines.

--
A host is a host from coast to coast.................wb8foz@nrk.com 
& no one will talk to a host that's close.......................... 
 Click to see the full signature
Reply to
David Lesher

The I2C port is a hardware interface on the MCU, so it will have a driver in software so that it will be easy to program. If you are happy with the I2C relay board, there is no reason to use the SPI port. You just need to set the address switches differently on each of the relay boards so that there are no address conflicts including the other I2C peripherals like the display.

--

Rick C
Reply to
rickman

We don't want ladder-logic. This box was suggested by folks using them & the programmer is happy so far.

Its advantages are it's already built, has most of the functionality we need in one box, and is inexpensive vs. the labor of building anything.

We will be using other aspects, such as the analog inputs, RTC, and the touch screen.

If you are aware of a different unit (....no matter if it's called a PLC or an X-15) that does what this one does, plus a wired Ethernet port, suggestions welcome.

--
A host is a host from coast to coast.................wb8foz@nrk.com 
& no one will talk to a host that's close.......................... 
 Click to see the full signature
Reply to
David Lesher

I'm not sure what "already built" means other than the obvious thing. But why wouldn't other boards be "already built"? Are you saying this comes in a box? Does that include the relay boards? If you need to put the relay boards in another box, why not put it all in one box?

Analog inputs are not uncommon on CPU boards along with RTC and touch screen. In fact, all this is extremely common.

You can get a Raspberry Pi for a number between $5 and $35 including a

40 pin header with serial, SPI and I2C ports along with 3.3 volt GP I/O. It is easy to find an analog input module to plug into the header and it is easy to find RTC and touch screen LCDs. I don't know just how the unit you are looking at is packaged. But if you are happy with it, go for it. I'm just saying that there is a lot on the PLC that you aren't using. In fact, all the stuff that you aren't using is what makes a typical PLC different from a CPU card. So it just seemed a bit out of line. But the price for this PLC is pretty good actually. My brother is using one that is a *lot* more money.
--

Rick C
Reply to
rickman

yeah, almost as good.

--
This email has not been checked by half-arsed antivirus software
Reply to
Jasen Betts

Using a 4017 is pretty gnarly--how do you avoid !CS glitches? If you had a '595 buffered SIPO register on there, every time you hit its chip select, its output register gets loaded with whatever garbage is in the shift reg at the time.

Since that would require that each shift register be loaded with the correct data at nearly all times, you might as well daisy chain them and use one chip select.

Cheers

Phil Hobbs

--
Dr Philip C D Hobbs 
Principal Consultant 
 Click to see the full signature
Reply to
Phil Hobbs

I thought the display was on the SPI bus. The choice is also a function of what relay boards of each ilk I find. I expected to find lots, and have not.

--
A host is a host from coast to coast.................wb8foz@nrk.com 
& no one will talk to a host that's close.......................... 
 Click to see the full signature
Reply to
David Lesher

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.