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.

BQ76952: AFE ACCESS CRC wrong

Part Number: BQ76952

Hello ,

    I  meet a  question.  Through   spi  we read  or  wite  afe, we  find  there   are many  crc  error.

SPI is ok.

  

fuction() to  write afe is as following:

static uint8_t SPI_WriteReg(uint8_t reg_addr, uint8_t *reg_data, uint8_t count)
{
uint8_t addr = 0U;
uint8_t TX_Buffer[MAX_BUFFER_SIZE] = {0x0U, 0x0U, 0x0U};
uint8_t i = 0U;
uint8_t match = 0U;
uint8_t retries = 5U;
uint8_t reg_value = 0U;
uint8_t result = SPI_ACCESS_OK;
uint8_t crc_ret = 0U;
uint8_t rxdata[3U] = {0x0U, 0x0U, 0x0U};
uint8_t TxRxResult = SPI_ACCESS_OK;

addr = (uint8_t)(0x80U | reg_addr);

for (i = 0U; i < count; i++)
{
retries = 5U;
match = SPI_ACCESS_FAIL;
TX_Buffer[0U] = addr;
TX_Buffer[1U] = *(reg_data + i);
TX_Buffer[2U] = CRC8(TX_Buffer, 2U);
/*确认发送成功,如果不成功,重发,重发10次不成功退出*/
while ((match == SPI_ACCESS_FAIL) && (retries > 0U))
{
TxRxResult = SPI_ACCESS_OK;
Delay_US(300U);
SPI_BQ76952_CS_LOW;
Delay_US(100U);
rxdata[0U] = SPIx_ReadWriteByte(TX_Buffer[0], &TxRxResult);
if (TxRxResult == SPI_ACCESS_OK)
{
rxdata[1U] = SPIx_ReadWriteByte(TX_Buffer[1], &TxRxResult);
}
if (TxRxResult == SPI_ACCESS_OK)
{
rxdata[2U] = SPIx_ReadWriteByte(TX_Buffer[2], &TxRxResult);
}
SPI_BQ76952_CS_HIGH;
reg_value = *(reg_data + i);

crc_ret = CRC8(rxdata, 2U);
if ((rxdata[0U] == addr) && (rxdata[1U] == reg_value) && (rxdata[2U] == crc_ret) && (TxRxResult == SPI_ACCESS_OK))
{
match = SPI_ACCESS_OK;
}
if(rxdata[2U] != crc_ret)
{
g_afe_crc_fail_times++;
}
if(TxRxResult != SPI_ACCESS_OK)
{
g_spi_fail_times++;

}

retries--;
}
if (match == SPI_ACCESS_FAIL)
{
result = SPI_ACCESS_FAIL;
break; /*写入失败提前直接退出*/
}
addr += 1U;
Delay_US(500U);
}

result = (TxRxResult != SPI_ACCESS_OK) ? TxRxResult : result; /*如果SPI读写错误就返回读写错误,如果没有就返回访问结果*/
return result;
}

thanks