Other Parts Discussed in Thread: BQSTUDIO
int I2C_ReadReg(uint8_t reg_addr, uint8_t *reg_data, uint8_t count)
{
unsigned int RX_CRC_Fail = 0; // reset to 0. If in CRC Mode and CRC fails, this will be incremented.
uint8_t RX_Buffer [MAX_BUFFER_SIZE] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
#if CRC_Mode
{
uint8_t crc_count = 0;
uint8_t ReceiveBuffer [10] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
crc_count = count * 2;
unsigned int j;
unsigned int i;
unsigned char CRCc = 0;
uint8_t temp_crc_buffer [3];
HAL_I2C_Mem_Read(&hi2c1, DEV_ADDR, reg_addr, 1, ReceiveBuffer, crc_count, 1000);
uint8_t crc1stByteBuffer [4] = {0x10, reg_addr, 0x11, ReceiveBuffer[0]};
CRCc = CRC8(crc1stByteBuffer,4);
if (CRCc != ReceiveBuffer[1])
{
RX_CRC_Fail += 1;
}
RX_Buffer[0] = ReceiveBuffer[0];
j = 2;
for (i=1; i<count; i++)
{
RX_Buffer[i] = ReceiveBuffer[j];
temp_crc_buffer[0] = ReceiveBuffer[j];
j = j + 1;
CRCc = CRC8(temp_crc_buffer,1);
if (CRCc != ReceiveBuffer[j])
RX_CRC_Fail += 1;
j = j + 1;
}
CopyArray(RX_Buffer, reg_data, crc_count);
}
#else
HAL_I2C_Mem_Read(&hi2c1, DEV_ADDR, reg_addr, 1, reg_data, count, 1000);
#endif
return 0;
}
中ReceiveBuffer大小只有10, 而crc_count = count * 2; 则count 就会限制到最大为5对吗?
而 Subcommands函数中I2C_ReadReg(0x40, RX_32Byte, 32); 为32, 是不是上面的ReadReg函数有问题?