Timeline for How to read data using Arduino SPI
Current License: CC BY-SA 3.0
7 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jun 23, 2020 at 22:31 | comment | added | SoreDakeNoKoto |
It wouldn't be totally incorrect to say you can't truly read without writing on an SPI bus and vice versa as well. So it makes sense to simply design a peripheral that takes a byte in one register and, 8 cycles later, returns a byte in another (or even the same) register, just to generalize usecases. Then it's up to the user's application to decide if they're only interested in the byte that was written out in the first place (TX) or the one that was read back (RX) or both (TX and RX). Also, hence the ambiguous name transfer() since it serves both reading and writing roles.
|
|
| Jun 23, 2020 at 22:22 | comment | added | SoreDakeNoKoto |
@S.Imp They're dummy bytes. You can send whatever you want to send, the device at the other end will still discard them, if it even pays the data any mind. SPI.transfer() is always used partly because of the intrinsic full-duplex nature of SPI and (as a result of the first factor) then partly because of the way most MCUs implement their SPI peripherals. Once the clock starts running, there is always "data" on the MOSI and MISO lines, it's just up to each participant on the bus to read it or not, deciding based on whatever predefined higher-layer protocol if the "data" is meaningful or not.
|
|
| Jun 20, 2020 at 20:30 | comment | added | S. Imp | All the examples I've seen use SPI,transfer(0) to read data rather than SPI.transfer(0xff). They also use SPI.transfer for writing data, too. I still haven't figured out what SPI does with the 0 or 0xff when you are actually reading data. Is this sent to the slave? | |
| Apr 27, 2016 at 15:17 | history | edited | SoreDakeNoKoto | CC BY-SA 3.0 |
added 212 characters in body; added 16 characters in body
|
| Apr 27, 2016 at 14:59 | comment | added | SoreDakeNoKoto | @st2000 The OP saw fit to not give enough details; nothing but assumptions can be made till that changes. | |
| Apr 27, 2016 at 14:13 | comment | added | st2000 | Not sure this will work. We really need to know how the SPI slave works before we can assume how it will react. Also, if the Chip Select line is asserted and de-asserted with each 8 bit SPI transaction, how well is the SPI slave designed? That is, such a SPI slave could easily get out of sync with the SPI master. Specifically, how are you assured which 8 bit byte you are actually reading? | |
| Apr 27, 2016 at 13:07 | history | answered | SoreDakeNoKoto | CC BY-SA 3.0 |