|
本帖最后由 zhao5352 于 2023-3-7 15:18 编辑
1、速率不同,将IIC的速率降至BQ40Z50要求的速率
2、"Clock stretching"问题,SMBUS下,从机可以拉住SCL信号,让其保持低电平,原IIC协议不处理这问题,就会导致通信失败,
IIC协议里面需在主机将SCL电平拉高后,再判断是否拉高:
#define I2Cx_SCL_H do {\
HAL_GPIO_WritePin(I2Cx_PORT, I2Cx_SCL_PIN, GPIO_PIN_SET); \
/*use for smbus, wait until the slave to release iic bus*/ \
uint32_t timeout = 1000; \
while(timeout && (HAL_GPIO_ReadPin(I2Cx_PORT, I2Cx_SCL_PIN) != GPIO_PIN_SET)) timeout--; } while(0)
"Clock stretching"问题详见下图:
3、可选的PEC校验
/******************************************************************************
* Name: CRC-8/SMBUS
* Poly: 0x07
* Init: 0x00
* Refin: False
* Refout: False
* Xorout: 0x00
* Note: x8+x2+x+1
*****************************************************************************/
static uint8_t CRC8_Accumulate(uint8_t *buf, uint32_t len)
{
uint8_t crc8 =0;
uint8_t i;
while(len--)
{
crc8 ^= *buf++;
for (i=0; i<8; i++)
{
if (crc8 & 0x80)
crc8 = (crc8 << 1) ^ 0x07;
else
crc8 <<= 1;
}
}
return crc8;
}
|
评分
-
查看全部评分
|