WiringPi数据可用

时间:2015-01-02 17:07:53

标签: c++ raspberry-pi driver i2c

我正在尝试为Adafruit LSM303(https://www.adafruit.com/product/1120)编写一个自定义驱动程序,以便我可以使用这个分组板在raspberry pi上编写C ++代码。因为我一直在挖掘Arduino驱动程序的源代码(位于这里:https://github.com/adafruit/Adafruit_LSM303DLHC/blob/master/Adafruit_LSM303_U.cpp),我发现代码在读取之前等待数据准备就绪:(第87行)

以下代码适用于使用Wire.h标头进行I2C访问的Arduino。

void Adafruit_LSM303_Accel_Unified::read()
{
 ...
  while (Wire.available() < 6);

  #if ARDUINO >= 100
    uint8_t xlo = Wire.read();
    uint8_t xhi = Wire.read();
    uint8_t ylo = Wire.read();
    uint8_t yhi = Wire.read();
    uint8_t zlo = Wire.read();
    uint8_t zhi = Wire.read();
  #else
    uint8_t xlo = Wire.receive();
    uint8_t xhi = Wire.receive();
    uint8_t ylo = Wire.receive();
    uint8_t yhi = Wire.receive();
    uint8_t zlo = Wire.receive();
    uint8_t zhi = Wire.receive();
  #endif    

  ...
}

是否可以在wiringPi I2C库中等待首先准备好数据?在等待数据准备就绪时,然后读取数据。

作为一个注释,我正在移植Arduino代码,以便它可以在覆盆子pi上运行。

0 个答案:

没有答案