BNO055 Ack / Nack和速度MC stm32f103的I2C问题

时间:2019-05-29 08:31:00

标签: c i2c stm32f1

我遇到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);
}

我正在使用STM32F10x standard peripheral library

Abbildung I2C Timing diagramm with logic analyzer

0 个答案:

没有答案