0

I am trying to write to a charging IC (BQ24193) and I am trying to figure out how to use I2C to write to a specific register so I can set up the charging IC properly. I have watched a few videos on the communication protocol, but I don't understand how to write to a register directly. Your help would be appreciated. Thanks.

Datasheet: http://www.ti.com/lit/ds/symlink/bq24193.pdf

2
  • 1
    use Wire library
    – Juraj
    Sep 6, 2019 at 5:18
  • figure 18 in the datasheet
    – jsotola
    Sep 6, 2019 at 5:31

1 Answer 1

0

The Arduino uses the Wire.h library to communicate on an I2C bus.

Writing to a register in I2C is usually done by sending two bytes to the correct I2C address. The first byte is usually the register address, and the second is the value to place into the register:

#define CHIP_ADDRESS     0x6B
#define REGISTER_ADDRESS 0x12

Wire.beginTransmission(CHIP_ADDRESS);
Wire.write(REGISTER_ADDRESS);
Wire.write(0x18);
Wire.endTransmission();

Reading from a register is slightly more tricky, in that first you need to write to the chip to set the register address, then as a separate operation you need to read from that address:

Wire.beginTransmission(CHIP_ADDRESS);
Wire.write(REGISTER_ADDRESS);
Wire.endTransmission();
Wire.requestFrom(CHIP_ADDRESS, 1); // We want one byte
uint8_t val = Wire.read();
2
  • So with my IC, how do I find the address for each register? I checked the datasheet, and it only included the slave address.
    – Jay
    Sep 6, 2019 at 11:12
  • @Jay page 26: "8.5 Register Map"
    – Sim Son
    Sep 6, 2019 at 17:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.