SPI bus (arduino)

Why use SPI?

I2C lets you connect many devices to a single bus (two wires, plus ground) so it would be the preferred choice if you needed to interrogate a substantial number of devices, perhaps fairly infrequently. However the speed of SPI could be more relevant for situations where you need to output rapidly (eg. a LED strip) or input rapidly (eg. an ADC converter). - Nick Gammon

SPI debugging

The code below demonstrates how you can achieve this by sending debugging “prints” out from the device you are testing, via SPI, to a second processor. The second processor simply sits there awaiting incoming bytes, and then dumps them out its serial port. Thus you effectively get a second serial port, via SPI.

This is suitable for debugging inside an interrupt service routine (ISR) because doing the SPI.transfer does not use interrupts.

caption

Written on August 10, 2019, Last update on August 10, 2019
SPI arduino bus