The BQ76942 device
includes support for direct commands and subcommands.
- The
direct commands are accessed using a 7-bit command
address that is sent from a host through the device
serial communications interface and either triggers
an action, provides a data value to be written to
the device, or instructs the device to report data
back to the host.
- Subcommands are additional commands that are
accessed indirectly using the 7-bit command address
space and provide the capability for block data
transfers. When a subcommand is initiated, a 16-bit
subcommand address is first written to the 7-bit
command addresses 0x3E (lower byte) and 0x3F (upper
byte).
The device initially assumes a readback of data may be needed,
and auto-populates existing data into the 32-byte transfer buffer
(which uses 7-bit command addresses 0x40‒0x5F), and writes the
checksum for this data into address 0x60. If the host instead
intends to write data into the device, the host will overwrite the
new data into the transfer buffer, a checksum for the data into
address 0x60, and the data length into address 0x61. As soon as
address 0x61 is written, the device checks the checksum written into
0x60 with the data written into 0x40–0x5F, and if this is correct,
it proceeds to transfer the data from the transfer buffer into the
device's memory. The checksum is the 8-bit sum of the subcommand
bytes (0x3E and 0x3F) plus the number of bytes used in the transfer
buffer, then the result is bitwise inverted. The verification cannot
take place until the data length is written, so the device realizes
how many bytes in the transfer buffer are included. The checksum and
data length must be written together as a word in order to be valid.
The data length includes the two bytes in 0x3E and 0x3F, the two
bytes in 0x60 and 0x61, and the length of the transfer buffer;
therefore, if the entire 32-byte transfer buffer is used, the data
length will be 0x24.
Some subcommands are only
used to initiate an action and do not involve sending or receiving
data. In these cases, the host can simply write the subcommand into
0x3E and 0x3F, it is not necessary to write the length and checksum
or any further data.
The commands supported in
the device are described in
Commands
and Subcommands. Single-byte commands are direct
commands, while two-byte commands are subcommands. Data formats are
described in Data Formats.
The most efficient
approach to read the data from a subcommand (to minimize bus
traffic) is shown below:
- Write lower byte of subcommand to
0x3E.
- Write upper byte of subcommand to
0x3F.
- Read 0x3E and 0x3F. If this returns
0xFF, this indicates the subcommand has not
completed operation yet. When the subcommand has
completed, the readback returns what was originally
written. Continue reading 0x3E and 0x3F until it
returns what was written originally. Note: This
response only applies to subcommands that return
data to be read back.
- Read the length of response from
0x61.
- Read buffer starting at 0x40 for the
expected length.
- Read the checksum at 0x60 and verify it
matches the data read.
An easier approach that is
less efficient on bus traffic is:
- Write the lower byte of the subcommand to
0x3E.
- Write the upper byte of the subcommand to
0x3F.
- Read 0x3E and 0x3F. If this returns 0xFF, this
indicates that the subcommand has not completed the
operation yet. When the subcommand has completed, the
readback returns what was originally written. Continue
reading 0x3E and 0x3F until it returns what was written
originally. Note: This response only applies to subcommands
that return data to be read back.
- Read 0x40 to 0x61 in a block. Ensure that the
checksum at 0x60 is correct over the length designated by
0x61. This means sometimes more bytes are read than
necessary, but it also makes it possible to use a standard
function that can be called for all subcommands.
Note: 0x61 provides the
length of the buffer data plus 4 (that is, length of the buffer data
plus the length of 0x3E and 0x3F plus the length of 0x60 and
0x61).
The checksum is calculated
over 0x3E, 0x3F, and the buffer data. It does not include the
checksum or length in 0x60 and 0x61.
If the checksum and length
are read together, this can trigger an auto-increment in some cases.
In which case, the buffer is populated with another block's data.
Generally, the checksum and length should not be read together
unless the buffer has already been read or if auto-incrementing is
intended.
Command or subcommand bits
that are denoted RSVD_0 should only be written as a "0", while bits
denoted RSVD_1 should only be written as a "1".