本文整理汇总了C++中TwoWire::receive方法的典型用法代码示例。如果您正苦于以下问题:C++ TwoWire::receive方法的具体用法?C++ TwoWire::receive怎么用?C++ TwoWire::receive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TwoWire
的用法示例。
在下文中一共展示了TwoWire::receive方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
static void read16(byte reg, uint16_t *value)
{
Wire1.beginTransmission((uint8_t)BMP085_ADDRESS);
#if ARDUINO >= 100
Wire1.write((uint8_t)reg);
#else
Wire1.send(reg);
#endif
Wire1.endTransmission();
Wire1.requestFrom((uint8_t)BMP085_ADDRESS, (byte)2);
#if ARDUINO >= 100
*value = (Wire1.read() << 8) | Wire1.read();
#else
*value = (Wire1.receive() << 8) | Wire1.receive();
#endif
Wire1.endTransmission();
}
示例2: millis
/** Read multiple bytes from an 8-bit device register.
* @param useSPI true : use SPI
* @param devAddr I2C slave device address
* @param regAddr First register regAddr to read from
* @param length Number of bytes to read
* @param data Buffer to store read data in
* @param timeout Optional read timeout in milliseconds (0 to disable, leave off to use default class value in I2Cdev::readTimeout)
* @return Number of bytes read (0 indicates failure)
*/
int8_t I2Cdev::readBytes(bool useSPI, uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data, uint16_t timeout) {
#ifdef I2CDEV_SERIAL_DEBUG
Serial.print(useSPI ? "SPI (0x" : "I2C 0x");
Serial.print(devAddr, HEX);
Serial.print(") reading ");
Serial.print(length, DEC);
Serial.print(" bytes from 0x");
Serial.print(regAddr, HEX);
Serial.print("...");
#endif
int8_t count = 0;
// I2C
if (!useSPI) {
Wire.beginTransmission(devAddr);
#if ((I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE && ARDUINO < 100) || I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_NBWIRE)
Wire.send(regAddr);
#elif (I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE && ARDUINO >= 100)
Wire.write(regAddr);
#endif
Wire.endTransmission();
Wire.beginTransmission(devAddr);
Wire.requestFrom(devAddr, length);
uint32_t t1 = millis();
for (; Wire.available() && (timeout == 0 || millis() - t1 < timeout); count++) {
#if ((I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE && ARDUINO < 100) || I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_NBWIRE)
data[count] = Wire.receive();
#elif (I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE && ARDUINO >= 100)
data[count] = Wire.read();
#endif
#ifdef I2CDEV_SERIAL_DEBUG
Serial.print(data[count], HEX);
if (count + 1 < length) Serial.print(" ");
#endif
}
if (timeout > 0 && millis() - t1 >= timeout && count < length) count = -1; // timeout
Wire.endTransmission();
} else {
digitalWrite(devAddr, LOW);
byte Addr = regAddr | 0x80;
SPI.transfer(Addr);
for (uint8_t cnt=0; cnt < length; cnt++) {
data[cnt] = SPI.transfer(0);
count++;
}
digitalWrite(devAddr, HIGH);
}
#ifdef I2CDEV_SERIAL_DEBUG
Serial.print(". Done (");
Serial.print(count, DEC);
Serial.println(" read).");
#endif
return count;
}
示例3: millis
/** Read multiple bytes from an 8-bit device register.
* @param devAddr I2C slave device address
* @param regAddr First register regAddr to read from
* @param length Number of bytes to read
* @param data Buffer to store read data in
* @param timeout Optional read timeout in milliseconds (0 to disable, leave off to use default class value in I2Cdev::readTimeout)
* @return Number of bytes read (0 indicates failure)
*/
int8_t I2Cdev::readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data, uint16_t timeout) {
#ifdef I2CDEV_SERIAL_DEBUG
Serial.print("I2C (0x");
Serial.print(devAddr, HEX);
Serial.print(") reading ");
Serial.print(length, DEC);
Serial.print(" bytes from 0x");
Serial.print(regAddr, HEX);
Serial.print("...");
#endif
int8_t count = 0;
Wire.beginTransmission(devAddr);
#if ((I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE && ARDUINO < 100) || I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_NBWIRE)
Wire.send(regAddr);
#elif (I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE && ARDUINO >= 100)
Wire.write(regAddr);
#endif
Wire.endTransmission();
Wire.beginTransmission(devAddr);
Wire.requestFrom(devAddr, length);
uint32_t t1 = millis();
for (; Wire.available() && (timeout == 0 || millis() - t1 < timeout); count++) {
#if ((I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE && ARDUINO < 100) || I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_NBWIRE)
data[count] = Wire.receive();
#elif (I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE && ARDUINO >= 100)
data[count] = Wire.read();
#endif
#ifdef I2CDEV_SERIAL_DEBUG
Serial.print(data[count], HEX);
if (count + 1 < length) Serial.print(" ");
#endif
}
if (timeout > 0 && millis() - t1 >= timeout && count < length) count = -1; // timeout
Wire.endTransmission();
#ifdef I2CDEV_SERIAL_DEBUG
Serial.print(". Done (");
Serial.print(count, DEC);
Serial.println(" read).");
#endif
return count;
}
示例4:
uint8_t MCP23018_READ(uint8_t device, uint8_t reg)
{
uint8_t addr;
uint8_t result;
if(DEV_MISC == device){ addr = MISC_ADDR; }
else{ addr = VEH_IO_ADDR; }
i2c.beginTransmission(addr);
i2c.write(reg); // IODIRA.BANK1 Address
i2c.endTransmission();
i2c.requestFrom(addr,(uint8_t)1u);
while (i2c.available() < 1u);
result = i2c.receive();
return result;
}