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

asked Sep 6, 2019 at 2:20
2
  • 1
    use Wire library Commented Sep 6, 2019 at 5:18
  • figure 18 in the datasheet Commented 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();
answered Sep 6, 2019 at 11:05
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. Commented Sep 6, 2019 at 11:12
  • @Jay page 26: "8.5 Register Map" Commented Sep 6, 2019 at 17:50

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.