i2corspi_register.ino (1024B)
1 #include <Adafruit_BusIO_Register.h> 2 3 // Define which interface to use by setting the unused interface to NULL! 4 5 #define SPIDEVICE_CS 10 6 Adafruit_SPIDevice *spi_dev = NULL; // new Adafruit_SPIDevice(SPIDEVICE_CS); 7 8 #define I2C_ADDRESS 0x5D 9 Adafruit_I2CDevice *i2c_dev = new Adafruit_I2CDevice(I2C_ADDRESS); 10 11 void setup() { 12 while (!Serial) { delay(10); } 13 Serial.begin(115200); 14 Serial.println("I2C or SPI device register test"); 15 16 if (spi_dev && !spi_dev->begin()) { 17 Serial.println("Could not initialize SPI device"); 18 } 19 20 if (i2c_dev) { 21 if (i2c_dev->begin()) { 22 Serial.print("Device found on I2C address 0x"); 23 Serial.println(i2c_dev->address(), HEX); 24 } else { 25 Serial.print("Did not find I2C device at 0x"); 26 Serial.println(i2c_dev->address(), HEX); 27 } 28 } 29 30 Adafruit_BusIO_Register id_reg = Adafruit_BusIO_Register(i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, 0x0F); 31 uint8_t id; 32 id_reg.read(&id); 33 Serial.print("ID register = 0x"); Serial.println(id, HEX); 34 } 35 36 void loop() { 37 38 }