SPI or I2C board to board communication

Thread Starter

adrenalina

Joined Jan 4, 2011
78
Hello everybody. I was wondering if you could help me with the following problem I'm having. I'm working on a project that communicates a master device to multiple slaves, 12 to be exact, on different boards. The connection would be using ribbon cable. My question is what would be the most reliable to use, SPI or I2C, using a clock speed of 100 kHz? The cable length would be 40 cm. I attach an image to better explain the idea.

I know RS-485 or CAN would be more reliable protocols, but because of cost, SPI or I2C would be better.
 

Attachments

MrChips

Joined Oct 2, 2009
34,807
Are the slaves programmable devices, i.e. are they implemented using microcontrollers?

If so I can think of 1-wire or 2-wire solutions without the need for separate SLAVE SELECT signals.

You have to create a network protocol where the slave address is embedded in the message.

Can you use standard UART 2-wire TTL signals?
 

shteii01

Joined Feb 19, 2010
4,644
Also, in i2c all the devices share the two lines. Your block diagram shows the data flow. It does not show the actual physical layout. How are you going to connect the devices to the ribbon cable?
 

Thread Starter

adrenalina

Joined Jan 4, 2011
78
Are the slaves programmable devices, i.e. are they implemented using microcontrollers?

If so I can think of 1-wire or 2-wire solutions without the need for separate SLAVE SELECT signals.

You have to create a network protocol where the slave address is embedded in the message.

Can you use standard UART 2-wire TTL signals?
The slaves would be microcontrollers and ICs, for example a led driver IC that uses I2C or SPI.


Also, in i2c all the devices share the two lines. Your block diagram shows the data flow. It does not show the actual physical layout. How are you going to connect the devices to the ribbon cable?
I would be using headers and an IDC connector. the 2 lines would be connected to each header on the main board plus a ground and supply.
 

Papabravo

Joined Feb 24, 2006
22,082
You could do SPI at higher speed than 100 kbits/sec by using a shift register chain made of individual flip-flops, one for each device, for the chip selects. Preset them all to 1 and then shift a single 0 through all devices and feed the output of the last flip-flop back to the master.

So the interface lines on the master would be
Rich (BB code):
SPI_DATAOUT     OUTPUT
SPI_DATAIN      INPUT
SPI_DATA_CLOCK  OUTPUT
SELECT _RESET   OUTPUT
SELECT_DATA     OUTPUT
SELECTINPUT     INPUT
Although bi-directional buffers are available for SDA under I2C I've never really trusted them. Nothing beats a buffer chip powered from 3.3V that is 5V tolerant with TTL thresholds.
 

Thread Starter

adrenalina

Joined Jan 4, 2011
78
More info on the project. We have another pin on the header which is simply a digital IO and analog from the microcontroller on the master board. This is used for devices that don't require a communication protocol, for example and analog sensor or to read a button. Different devices that do various things can be connected.

The idea is that any device can be connected to any header and you don't need a device address. On the programming side you would simply say the type of device that is connected on the header. So for I2C which requires an address we came up with the idea in the image. A mosfet is between the clock line that is controlled by the extra IO pin. The clock signal on the slave won't change and stay high unless the mosfet is turned on.

The other 2 mosfets on the image are there to simulate the open collector of I2C.

In a way this is kind of like SPI, using a "slave select", but the difference would be that the drivers are open collector and not push pull.

Hopefully I'm clear enough.
 

Attachments

Thread Starter

adrenalina

Joined Jan 4, 2011
78
How would the implementation be using 1 or 2 wires if the devices cannot have a pre programmed address and not all of the devices are microcontrollers.
 
Last edited:

ErnieM

Joined Apr 24, 2011
8,415
If each and every I2C device can be assigned it's own address then it would need fewer lines to drive them all. If that is not possible (today and in all future systems) then SPI has the advantage of the existing chip select line.

One could make a chip select for I2C, as there exists chips for this exact purpose. I believe NXP for one makes them. I would not recommend making your own device for this, as the slave may also use the clock line (it's how it requests extra time to process an inputed byte).

Without explicit I2C addresses or for SPI you need X signal lines for X devices all running down your cable.

Hopefully X is finite and fixed now and forever. Add a few extrans in anyway just in any case.
 

NorthGuy

Joined Jun 28, 2014
611
There are few things that are unclear in your design.

1. If devices do various, possibly unknown, things, what good does it make to connect them if MCU doesn't know what the device does?

2. If you insert a new device, you need to re-program the MCU. Why does it make any difference if you reprogram is with device address (for I2C) or slot position (for SPI)?

3. Are these devices removable? That is do you need a mechanism to figure out if device was disconnected or connected to your network?
 

ErnieM

Joined Apr 24, 2011
8,415
My choice would be to redesign the system so that every device uses a microcontroller.
One huge benefit of this system is each micro can be used as an I2C slave device with a unique address set by either jumper or electronically thru internal EEPROM.
 

Thread Starter

adrenalina

Joined Jan 4, 2011
78
When the program for the master is written it is told the type of device in each slot. There can be multiple devices of the same type and it would not be possible to change the address of a device.

If it's not possible to change the system to only use microcontrollers and considering that the devices would not be able to have addresses would SPI be the best choice?
 
Last edited:

NorthGuy

Joined Jun 28, 2014
611
When the program for the master is written it is told the type of device in each slot. There can be multiple devices of the same type and it would not be possible to change the address of a device.
If you cannot use addresses, it's better to go with SPI, or even UART.

BTW: In the schematics that your posted, when master's side goes low, the slave's side will follow regardless of the state of the FET in the middle. This is because when source voltage is above drain voltage in N-FET, it simply works as a diode.
 

ErnieM

Joined Apr 24, 2011
8,415
If it's not possible to change the system to only use microcontrollers and considering that the devices would not be able to have addresses would SPI be the best choice?
As I have stated "Without explicit I2C addresses or for SPI you need X signal lines for X devices all running down your cable. Hopefully X is finite and fixed now and forever."

As long as you don't mind adding all these signal lines the either I2C or SPI are equivalent methods, keeping in mind I2C with like addresses will need the bus drivers I mentioned (NOT fets).
 
Top