# Is it possible to communicate single SPI slave with Two SPI masters

I am using two STM8 micro-controllers as SPI masters. Master-1 is configured in full duplex mode. And the Master-2 is configured in Receive-only mode. The CS, MISO, MOSI and SCLK lines of Master-1 are connected to the Slave. The CS, MISO and SCLK lines of Master-2 are connected to the Slave. When Master-1 requests data from the slave. Master-1 and Master-2 should receive the data from slave at the same time. And the data should be same. I configured two masters with same baudrate,CPOL and CPHA.

When I am communicating with single master, I could receive the data correctly from the slave. But When I involve the second master in the communication the received data of both master is corrupted. And in the oscilloscope, I could see the SCLK variations on the slave.

What are the things I need to consider while communicating a slave with two masters at the same time.

• The SPI master is the device that drives the SCLK line. You can't have two devices driving the same SCLK line at the same time. As simple as that. I think you have to take a step back and rethink your architecture. Or tell us the bigger picture of what you're trying to do, so we can give advice on that too. – dim Dec 7 '16 at 11:16
• I am trying to get the data from the slave to two masters at the same time, but only one master should request the slave. When Slave responds to the request two masters should be able to read the data. – Abdul Gafoor Dec 7 '16 at 11:21
• Then, Master-2 shouldn't be a master. It's not initiating the communication, and it shouldn't drive SCLK. It could simply be another slave on the same bus (maybe with a few tricks if it needs to spy both MISO and MOSI). – dim Dec 7 '16 at 11:34
• Why can't you just configure the 2nd master as a slave thus there will be no clock fights. – Andy aka Dec 7 '16 at 11:35
• @AbdulGafoor If your system needs flow control to limit data rate slave-2 may be trying to control flow rate but not be able. What happens if you slow data rate for test purposes? Does error rate drop as data rate drops? Is there a rate at which you get no errors? What % of time is the SPI interface handling data actively. eg if << 50% of the time you could use two sessions. Either M->Sa, M-> S2 , or M->S1, S2 as M to S2. – Russell McMahon Jan 23 '17 at 10:45