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