fix wrong exmaple
This commit is contained in:
parent
ef1a09d38f
commit
85577e9f2e
|
|
@ -1,25 +1,23 @@
|
||||||
#include <Adafruit_I2CDevice.h>
|
#include <Adafruit_SPIDevice.h>
|
||||||
|
|
||||||
#define I2C_ADDRESS 0x60
|
#define SPIDEVICE_CS 10
|
||||||
Adafruit_I2CDevice i2c_dev = Adafruit_I2CDevice(I2C_ADDRESS);
|
Adafruit_SPIDevice spi_dev = Adafruit_SPIDevice(SPIDEVICE_CS);
|
||||||
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
while (!Serial) { delay(10); }
|
while (!Serial) { delay(10); }
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.println("I2C device read and write test");
|
Serial.println("SPI device read and write test");
|
||||||
|
|
||||||
if (!i2c_dev.begin()) {
|
if (!spi_dev.begin()) {
|
||||||
Serial.print("Did not find device at 0x");
|
Serial.println("Could not initialize SPI device");
|
||||||
Serial.println(i2c_dev.address(), HEX);
|
|
||||||
while (1);
|
while (1);
|
||||||
}
|
}
|
||||||
Serial.print("Device found on address 0x");
|
|
||||||
Serial.println(i2c_dev.address(), HEX);
|
|
||||||
|
|
||||||
uint8_t buffer[32];
|
uint8_t buffer[32];
|
||||||
|
|
||||||
// Try to read 32 bytes
|
// Try to read 32 bytes
|
||||||
i2c_dev.read(buffer, 32);
|
spi_dev.read(buffer, 32);
|
||||||
Serial.print("Read: ");
|
Serial.print("Read: ");
|
||||||
for (uint8_t i=0; i<32; i++) {
|
for (uint8_t i=0; i<32; i++) {
|
||||||
Serial.print("0x"); Serial.print(buffer[i], HEX); Serial.print(", ");
|
Serial.print("0x"); Serial.print(buffer[i], HEX); Serial.print(", ");
|
||||||
|
|
@ -27,8 +25,8 @@ void setup() {
|
||||||
Serial.println();
|
Serial.println();
|
||||||
|
|
||||||
// read a register by writing first, then reading
|
// read a register by writing first, then reading
|
||||||
buffer[0] = 0x0C; // we'll reuse the same buffer
|
buffer[0] = 0x8F; // we'll reuse the same buffer
|
||||||
i2c_dev.write_then_read(buffer, 1, buffer, 2, false);
|
spi_dev.write_then_read(buffer, 1, buffer, 2, false);
|
||||||
Serial.print("Write then Read: ");
|
Serial.print("Write then Read: ");
|
||||||
for (uint8_t i=0; i<2; i++) {
|
for (uint8_t i=0; i<2; i++) {
|
||||||
Serial.print("0x"); Serial.print(buffer[i], HEX); Serial.print(", ");
|
Serial.print("0x"); Serial.print(buffer[i], HEX); Serial.print(", ");
|
||||||
Loading…
Reference in New Issue