本帖最后由 xieyongbin 于 2020-9-29 17:05 编辑
单片机是STM8L151
读1个字节正常, 连续读多字节,第一个也正常,但后面是0xFF
程序是否有错误?
while(NumByte)
{
if (NumByte==1)
{
I2C_AcknowledgeConfig(I2C1, DISABLE);
I2C_GenerateSTOP(I2C1, ENABLE);
while ( I2C_GetFlagStatus(I2C1, I2C_FLAG_RXNE) == RESET )
pBuffer[Rx_Idx++] = I2C_ReceiveData(I2C1);
NumByte--;
}
if (I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_RECEIVED))
{
I2C_AcknowledgeConfig(I2C1,ENABLE);
pBuffer[Rx_Idx++] = I2C_ReceiveData(I2C1);
NumByte--;
}
} |