This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

BQ76930 CRC校验问题

Other Parts Discussed in Thread: BQ40Z50, BQ76930

1.关于CRC的校验BQ76930手册是这样描述的

When enabled, the CRC is calculated as follows:
• In a single-byte write transaction, the CRC is calculated over the slave address, register address, and
data.
• In a block write transaction, the CRC for the first data byte is calculated over the slave address,
register address, and data. The CRC for subsequent data bytes is calculated over the data byte only.
The CRC polynomial is x8 + x2 + x + 1, and the initial value is 0.
When the slave detects a bad CRC, the I2C slave will NACK the CRC, which causes the I2C slave to go to
an idle state.

When enabled, the CRC for a read transaction is calculated as follows:
• In a single-byte read transaction, the CRC is calculated after the second start and uses the slave
address and data byte.
• In a block read transaction, the CRC for the first data byte is calculated after the second start and uses
the slave address and data byte. The CRC for subsequent data bytes is calculated over the data byte
only.
The CRC polynomial is x8 + x2 + x + 1, and the initial value is 0.
When the master detects a bad CRC, the I2C master will NACK the CRC, which causes the I2C slave to
go to an idle state.

是否理解为:writebolck:Start+slaveaddr+ACK+register+ACK+data1+ACK+CRC1(CRC1为slaveaddr+register+data1的校验)+ACK+data2+ACK+CRC2(CRC2为data2的校验)+ACK+data3+ACK+CRC3(CRC3为data3的校验)+ACK+....+Stop;

readblock:Start+slaveaddr+ACK+register+ACK+Stop+Start+(slaveaddr+1)+ACK+data1+ACK+CRC1(CRC1为(slaveaddr+1)+data1的校验)+ACK+data2+ACK+CRC2(CRC2为data2的校验)+ACK+data3+ACK+CRC3(CRC3为data3的校验)+...+NACK+Stop;

这样理解是否正确。

2.在BQ76930配置参数中

result = I2CWriteBlockWithCRC(BQMAXIMO, PROTECT1, &(Registers.Protect1.Protect1Byte), 5);

PROTECT1是要配置的寄存器首地址,&(Registers.Protect1.Protect1Byte)是参数的首地址。一次性连续写入5个寄存器,寄存器地址是每写入一个字节后自动+1的吗,因为,I2CWriteBlockWithCRC()函数并没有对寄存器地址偏移 操作,有点疑惑。

int I2CWriteBlockWithCRC(unsigned char I2CSlaveAddress, unsigned char StartAddress, unsigned char *Buffer, unsigned char Length)
{
unsigned char *BufferCRC, *Pointer;
int i;
unsigned int SentByte = 0;
int result;

BufferCRC = (unsigned char*)malloc(2*Length + 2); //申请 一个2*Length + 2大小的内存空间,并转换为指针类型
if (NULL == BufferCRC)
return -1;

Pointer = BufferCRC;
*Pointer = I2CSlaveAddress << 1;
Pointer++;
*Pointer = StartAddress;
Pointer++;
*Pointer = *Buffer;
Pointer++;
*Pointer = CRC8(BufferCRC, 3, CRC_KEY);

for(i = 1; i < Length; i++)
{
Pointer++;
Buffer++;
*Pointer = *Buffer;
*(Pointer + 1) = CRC8(Pointer, 1, CRC_KEY);
Pointer++;
}

result = I2CSendBytes(I2CSlaveAddress, BufferCRC + 1, 2*Length + 1, &SentByte);

free(BufferCRC);
BufferCRC = NULL;

return result;
}

3.请问BQ76930和BQ40Z50_R1的校验方式是否相同,之前用过BQ40Z50校验方式是:Start+slaveaddr+ACK+register+ACK+Stop+Start+(slaveaddr+1)+ACK+data1+ACK+data2+ACK+data3+ACK+CRC(CRC为slaveaddr+register+(slaveaddr+1)+data1+data2+data3的校验)+...+NACK+Stop;