Reputation: 317
I have this following question. What is the difference between the read/write operations when using SPI and I2C protocols. For example I have 2 different sensors one interfaced through SPI and another interfaced through I2C.
So I2C read is as follows:
For SPI read:
Set the Chip select pin to enable the slave.
Send the read command to the slave to say that it is read operation.
Then how do we read the contents? Store it in a variable by using '=' operator in C?
Am I right with the sequence? Or Am I missing something? Please clarify. Thanks
Upvotes: 0
Views: 489
Reputation: 13
I2C is half duplex. Meaning, master needs to provide 8 clocks after register address is sent and listen to data line. This can be done by three ways
SPI works in full duplex mode. but still slave cant respond immediately after recieving the address. Typically it requires 8 cycles again to respond. Above said 3 modes exists for SPI as well.
Whether you can read the values using = operator ? It depends on driver implementation. But most probably not. Typically input arguments like RX buffer and Transfer size are passed. If its synchronous/Blocking call, you should be able to read the content of the same buffer after the read/transfer call. Otherwise you have to read it in ISR or after some delay
Upvotes: 0