Exchange bytes with SPI peripherals and radio modules.
Open in compiler →/*
Roboda verified Arduino sample 0585
Feature: SPI Transfer
Generated for online build, classroom practice, and hardware upload testing.
*/
#include <SPI.h>
const byte chipSelect = 10;
byte value = 23;
void setup() {
pinMode(chipSelect, OUTPUT);
digitalWrite(chipSelect, HIGH);
SPI.begin();
Serial.begin(9600);
}
void loop() {
digitalWrite(chipSelect, LOW);
byte reply = SPI.transfer(value++);
digitalWrite(chipSelect, HIGH);
Serial.println(reply);
delay(465);
}
How it works
Send and receive one byte over SPI.
- Wire MOSI/MISO/SCK using the board-specific SPI pins.
- Wire chipSelect to the listed CS pin.
- Pull CS LOW for the transfer.
- Return CS HIGH after the byte exchange.
Connections
| Pin | Connect to | Note |
|---|---|---|
| D10 | SPI peripheral CS/SS | SPI MOSI/MISO/SCK move to board-specific SPI pins. |