This application report provides examples that illustrate the bit-transaction details of I2C commands used with TI's bq34xxx series and bq35xxx series battery fuel gauges. The first two examples provide detailed explanations of using I2C commands to read standard parameters and Control Subcommand parameters. The first example shows how to implement a standard fuel gauge command that interrogates the gauge for reading cell voltage. The second example shows the added bit transitions required to access a Control Subcommand, specifically requesting firmware version information. Other I2C commands can be executed in the same manner, using the methodology of these two examples. The final sections provide step-by-step examples using the bqStudio I2C Master Control Panel to read and write parameters from these gauges.
All trademarks are the property of their respective owners.
I2C commands are always initiated by the host with a START (S) bit sequence, immediately followed by a 7-bit I2C address with the most-significant bit (MSB) sent first. An eighth bit of 0 is sent by the host, indicating that the next byte to be sent will be a write to the gauge. For the bq34xxx series and bq35xxx series of parts, these 8 bits form the byte 0xAA. Once the start bit and address byte have been successfully received by the gauge, the gauge responds with an ACKNOWLEDGE (A) bit sequence. The gauge is now ready for the subsequent command directive from the host. Further descriptions of the control bit sequences are presented in the Glossary: Control-Bit-Sequence Definitions.
After the successful transmission of the I2C address and read or write bit, the gauge command code can be sent by the host, in this case 0x08 for the Voltage( ) command. The command code is actually a base address location within the gauge and must not be confused with the I2C address for the gauge. Once this location is sent by the host, the gauge responds by sending an ACKNOWLEDGE bit sequence and then executing the corresponding command subroutine. Even though two-byte locations are used for many gauge commands, writing to only the single byte is required to start gauge command processing. In this case, only 0x08 was written to the gauge, even though the command consists of the two consecutive command bytes 0x08 and 0x09. Most commands consist of two bytes, because the data is returned to these command locations and are also two bytes – the least-significant byte (LSB) is stored in the lower address (0x08), whereas the MSB is stored in the higher address (0x09). Like the I2C address data, the gauge command is sent MSB-first.
The host initiates the reading of the command data by sending a REPEAT START (Sr) bit sequence. This is immediately followed by the 7-bit I2C address of the gauge plus the read-bit directive (1), which together create the byte 0xAB. The gauge responds with an ACKNOWLEDGE bit sequence, then takes control of the data bus. The first data byte (LSB) is stored at the 0x08 location in the gauge and is strobed out by the gauge MSB-first. If the host responds with an ACKNOWLEDGE bit sequence, the gauge automatically increments the command location to 0x09, then strobes out the MSB stored there. If the host responds with a NO ACKNOWLEDGE (P or NACK) bit transmission, no further data is spooled to the host. The host terminates the present command packet by sending a STOP bit.
Reading the firmware version is an example of using the bq34z100-G1 subcommands. Subcommands are unique, as they represent another level of depth into the gauge command structure. All subcommands are accessed through the paired command locations at 0x00 and 0x01 in the gauge. The subcommands are written LSB-first. Hence, to send the FW_VERSION subcommand (0x0002), the host writes 0x02 to command location 0x00 and 0x00 to 0x01. Again, I2C always writes the MSB first. The format for address/command/data exchange between host and gauge is similar to the previous example and is shown in Figure 2. As in Example 1, the host initiates transmission with a START bit, followed by the gauge I2C address and a WRITE bit of 0 (0xAA). The gauge responds with an ACKNOWLEDGE, then the host specifies the command address of 0x00. Again, the gauge responds with an ACKNOWLEDGE. At this stage, the host must make additional writes to the gauge to set the subcommand code of 0x0002. Hence, the host sends the low byte of the subcommand (0x02). The gauge acknowledges. Then the host sends the high byte of the subcommand (0x00). The gauge issues an ACKNOWLEDGE. The host completes the writing process by issuing the STOP bit sequence. Now the gauge is prepared to return firmware information to the host.
To start the reading process, the host proceeds in a manner similar to Example 1, by issuing a START (S) bit sequence, immediately followed by the 7-bit I2C address of the gauge and the eighth bit of 0 (altogether, 0xAA for the bq34z100-G1 device). The gauge responds with an ACKNOWLEDGE bit sequence. The host sends the Control( ) command of 0x00, and the gauge acknowledges. The gauge address location has now been set. To retrieve the data at 0x00 and 0x01, the host proceeds as before. It initiates the reading of the command data by sending a REPEATED START bit sequence. This is immediately followed by the 7-bit I2C address of the gauge plus the read-bit directive (1), which together create the byte 0xAB. The gauge responds with an ACKNOWLEDGE bit sequence, then takes control of the data bus. The first data byte (LSB) is stored at the 0x00 location in the gauge and is strobed out by the gauge MSB-first. If the host responds with an ACKNOWLEDGE bit sequence, the gauge automatically increments the command location to 0x01, then strobes out the MSB stored there. The host terminates the entire command process by sending a STOP bit.
We will use the Voltage as an example. Its command code is 08/09. Use the I2C Master Control Panel section to read the flash.
ENTER: Start Register 08, Number of Bytes to Read 2 and PRESS the Read button.
Byte swap the data and convert it to decimal. 3C8C is 15500 mV.