Krolyxon
Commit 1d55752

Branches

Tags

Refs →

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

40 lines · 991 B

1#include <Adafruit_BusIO_Register.h>
2#include <Adafruit_SPIDevice.h>
3
4#define SPIDEVICE_CS 10
5Adafruit_SPIDevice spi_dev = Adafruit_SPIDevice(SPIDEVICE_CS);
6
7void setup() {
8 while (!Serial) {
9 delay(10);
10 }
11 Serial.begin(115200);
12 Serial.println("SPI device register test");
13
14 if (!spi_dev.begin()) {
15 Serial.println("Could not initialize SPI device");
16 while (1)
17 ;
18 }
19
20 Adafruit_BusIO_Register id_reg =
21 Adafruit_BusIO_Register(&spi_dev, 0x0F, ADDRBIT8_HIGH_TOREAD);
22 uint8_t id = 0;
23 id_reg.read(&id);
24 Serial.print("ID register = 0x");
25 Serial.println(id, HEX);
26
27 Adafruit_BusIO_Register thresh_reg = Adafruit_BusIO_Register(
28 &spi_dev, 0x0C, ADDRBIT8_HIGH_TOREAD, 2, LSBFIRST);
29 uint16_t thresh = 0;
30 thresh_reg.read(&thresh);
31 Serial.print("Initial threshold register = 0x");
32 Serial.println(thresh, HEX);
33
34 thresh_reg.write(~thresh);
35
36 Serial.print("Post threshold register = 0x");
37 Serial.println(thresh_reg.read(), HEX);
38}
39
40void loop() {}