Chuck Swiger
/
FTHRChirpChangeAddr
Change i2c address in the Chirp! sensor
Diff: main.cpp
- Revision:
- 0:0b271f6ca9be
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Jul 31 18:17:05 2018 +0000 @@ -0,0 +1,32 @@ +#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]); + +} +