Chuck Swiger
/
FTHRChirpChangeAddr
Change i2c address in the Chirp! sensor
main.cpp
- Committer:
- cswiger
- Date:
- 2018-07-31
- Revision:
- 0:0b271f6ca9be
File content as of revision 0:0b271f6ca9be:
#include "mbed.h" // Change Chirp! Address - default starts with 0x20 I2C i2c(P3_4, P3_5); int addr = 0x20; int addr8 = addr << 1; int main() { char cmd[2]; wait(30.0); // give user time to connect to serial port cmd[0] = 0x01; // change address command cmd[1] = 0x21; // new address i2c.write(addr8, cmd, 2); // update address // The above does successfully change the address, but 0x21 won't read until the device is reset addr = 0x20; // try 0x20 here, the device is still 0x20 and should read 0x21 from eeprom addr8 = addr << 1; wait(2.0); cmd[0] = 0x02; // read address from eeprom i2c.write(addr8, cmd, 1); i2c.read(addr8, cmd, 1); printf("New address read: %d",cmd[0]); }