A little curiosity. A whole lot of making.Robotics, CNC & connected ideas
robodatech.
Arduino sample library

SPI Transfer 27

Exchange bytes with SPI peripherals and radio modules.

Open in compiler →
/*
  Roboda verified Arduino sample 0660
  Feature: SPI Transfer
  Generated for online build, classroom practice, and hardware upload testing.
*/

#include <SPI.h>

const byte chipSelect = 10;
byte value = 26;

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(150);
}

How it works

Send and receive one byte over SPI.

  1. Wire MOSI/MISO/SCK using the board-specific SPI pins.
  2. Wire chipSelect to the listed CS pin.
  3. Pull CS LOW for the transfer.
  4. Return CS HIGH after the byte exchange.

Connections

PinConnect toNote
D10SPI peripheral CS/SSSPI MOSI/MISO/SCK move to board-specific SPI pins.

Good ideas start here.

Robotics lessons, build notes and useful updates. Subscribe by entering your email.