我遇到I2C
通信速度问题。我将BNO055 Sensor
设置为ACCONLY Mode
并设置为2g /带宽1000 Hz,但是无法足够快地获得此信息。
我发现数据传输的正常结束与接收到的数据之间的差距超出了正常数据(您可以在下面的图片中看到它)。我得到的字节比预期多了1个字节,总是0xff + NACK
。
这里是我的代码,用于从BNO055
获取数据:
void i2c_get_Data(uint8_t address,volatile u8 *uartTx_buffer, u8 Buffersize)
{
I2C_GenerateSTART(I2Cx, ENABLE);
i2c_address_direction(address <<1, I2C_Direction_Receiver);
for (int i = 0; i < Buffersize-1; i++)
{
uartTx_buffer[i] = i2c_receive_ack();
}
uartTx_buffer[Buffersize-1] = i2c_receive_nack();
i2c_stop();
}
uint8_t i2c_receive_nack()
{
// Disable ACK of received data
I2C_AcknowledgeConfig(I2Cx, DISABLE);
// Wait for I2C EV7
// It means that the data has been received in I2C data register
while (!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_RECEIVED));
// Read and return data byte from I2C data register
return I2C_ReceiveData(I2Cx);
}
uint8_t i2c_receive_ack()
{
// Enable ACK of received data
I2C_AcknowledgeConfig(I2Cx, ENABLE);
// Wait for I2C EV7
// It means that the data has been received in I2C data register
while (!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_RECEIVED));
// Read and return data byte from I2C data register
return I2C_ReceiveData(I2Cx);
}