Electrical – SPI device act as a Master and as a slave


We developing embedded device that contains 2 MCU(A and B), both of them can act as master or slave.

The device can run in 3 cases:

1- A + B + eeprom, A master B slave eeprom slave, no problem with that.

2- A + eeprom, A as master eeprom slave, B removed from the circuit, no problem with that.

3- B + eeprom, B as master eeprom slave, here is the problem, B act as slave becouse A control B(in case 1), but now we need that A act as control to control the eeprom, did it's possible to combine this kind of think?


SPI diagram

Best Answer

Not with what you show there, no. SPI is composed of 4 unidirectional signals and has no protocol to deal with them being bidirectional.

Some suggestions for achieving your goal...

You add two control lines, an AtoB line and a BtoA line, between A and B to indicate who is the bus master. There are several road-tested schemes for handling this based upon whether one master always decides, if both can request mastership but one always has priority, time-based fairness and more. (Don't know your situation so will leave that there.)

You could switch to I2C which is bidirectional and can do what you need with appropriate software to meet your priority scheme. But it runs a lot slower than SPI, which may or may not be a problem.