使用IIC读取再次数据,检验是否正常
int32_t GTP_I2C_Read_dbl_check(uint8_t client_addr, uint16_t addr, uint8_t *rxbuf, int len)
{
uint8_t buf[16] = {0};
uint8_t confirm_buf[16] = {0};
uint8_t retry = 0;
GTP_DEBUG_FUNC();
while (retry++ < 3)
{
memset(buf, 0xAA, 16);
buf[0] = (uint8_t)(addr >> 8);
buf[1] = (uint8_t)(addr & 0xFF);
GTP_I2C_Read(client_addr, buf, len + 2);
memset(confirm_buf, 0xAB, 16);
confirm_buf[0] = (uint8_t)(addr >> 8);
confirm_buf[1] = (uint8_t)(addr & 0xFF);
GTP_I2C_Read(client_addr, confirm_buf, len + 2);
if (!memcmp(buf, confirm_buf, len+2))
{
memcpy(rxbuf, confirm_buf+2, len);
return SUCCESS;
}
}
GTP_ERROR("I2C read 0x%04X, %d bytes, double check failed!", addr, len);
return FAIL;
}
|