Krolyxon
Commit 3120783

Branches

Tags

Refs →

orion-rf.piolibdepsesp32-s3-n16r8Adafruit BusIOexamplesspi_readwritespi_readwrite.ino

43 lines · 963 B

1#include <Adafruit_SPIDevice.h>
2
3#define SPIDEVICE_CS 10
4Adafruit_SPIDevice spi_dev = Adafruit_SPIDevice(SPIDEVICE_CS);
5
6void setup() {
7 while (!Serial) {
8 delay(10);
9 }
10 Serial.begin(115200);
11 Serial.println("SPI device read and write test");
12
13 if (!spi_dev.begin()) {
14 Serial.println("Could not initialize SPI device");
15 while (1)
16 ;
17 }
18
19 uint8_t buffer[32];
20
21 // Try to read 32 bytes
22 spi_dev.read(buffer, 32);
23 Serial.print("Read: ");
24 for (uint8_t i = 0; i < 32; i++) {
25 Serial.print("0x");
26 Serial.print(buffer[i], HEX);
27 Serial.print(", ");
28 }
29 Serial.println();
30
31 // read a register by writing first, then reading
32 buffer[0] = 0x8F; // we'll reuse the same buffer
33 spi_dev.write_then_read(buffer, 1, buffer, 2, false);
34 Serial.print("Write then Read: ");
35 for (uint8_t i = 0; i < 2; i++) {
36 Serial.print("0x");
37 Serial.print(buffer[i], HEX);
38 Serial.print(", ");
39 }
40 Serial.println();
41}
42
43void loop() {}