SPI Loopback example sketch SPI loopback test: sends a counter with SPI.transfer() every 500 ms and prints the byte that comes back. With MOSI wired to MISO, every byte sent should come straight back.
Uses PhyduinoSPI::beginTransaction() with 1 MHz, MSBFIRST, SPI_MODE0.
- Wiring
- D11 (MOSI) to D12 (MISO).
- Output
- Serial Monitor at 115200 baud, for example: With D11 and D12 not connected, the received value is usually 0 or 255.
}
static uint8_t value = 0;
SPI.beginTransaction(SPISettings(1000000,
MSBFIRST, SPI_MODE0));
const uint8_t received =
SPI.transfer(value);
value++;
}
@ MSBFIRST
Definition Common.h:48
Arduino SPI on the header pins: SCK = D13, MOSI = D11, MISO = D12.
PhyduinoSPI SPI
SPI on the header: SCK D13, MOSI D11, MISO D12.
SerialUSBClass Serial
USB serial port, the one the Serial Monitor uses.
void loop(void)
Written by the sketch: runs over and over after setup(), on core 0.
void setup(void)
Written by the sketch: runs once after reset, on core 0.
void delay(unsigned long)
Waits a number of milliseconds.