spi_registers.ino 991 B

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