Is it possible to test a SPI connection by wiring the MISO directly to the MOSI pin? I'm working on a low-level SPI implementation, and I want to check that the library is basically working. It would be nice to be able to test the connection itself without additional hardware.
2 Answers
Yes, you can - and it's something I often do when doing low-level electrical testing an SPI interfacce. For every clock that you send out the data presented on MOSI will get reflected on MISO. So if you were to (using the Arduino SPI library) do:
uint8_t x = SPI.transfer(0x38);
then x should equal 0x38.
I find this especially useful on systems with remappable pins to confirm that the pins are configured correctly in the board configuration for proper SPI operation.
- 105,851
- 5
- 82
- 139
Usually the SPI Master clocks data out while the Slave clocks data back in. So if you were sending and receiving 8 bits per transaction you can clock out 8 bits and at the same time clock in 8 bits for a total of 8 clocks. This is described in this Wikipedia paragraph. That said, often the first 8 clocks are used to transmit a command and an additional 8 clocks are used to retrieve the result.
If you looped MOSI to MISO you would clock in what you clocked out. You would complete the entire transaction in 8 clocks. At a low level I'm thinking this does not matter. But at a higher level the software would have to be re-written to accommodate this weirdness.
- 7,513
- 2
- 13
- 19