本文整理汇总了C++中TwoWire::beginTransmission方法的典型用法代码示例。如果您正苦于以下问题:C++ TwoWire::beginTransmission方法的具体用法?C++ TwoWire::beginTransmission怎么用?C++ TwoWire::beginTransmission使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TwoWire
的用法示例。
在下文中一共展示了TwoWire::beginTransmission方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Read_Gyro
// Read the ITG3200 Gyroscope
void Read_Gyro() {
// Point to the first data register
I2C->beginTransmission(GyroAddress);
I2C->write(0x1B); // point to the first data register
I2C->endTransmission();
// read 8 byte, from address 4 (Data Registers)
I2C->beginTransmission(GyroAddress);
I2C->requestFrom(GyroAddress, 8);
if (I2C->available() >= 8) {
//Just confirming that the data order is Temp, X, Y, Z
Gyro_T = (I2C->read() * 256) + I2C->read(); // Temp MSB * 256 + Temp LSB
Gyro_X = (I2C->read() * 256) + I2C->read(); // X axis MSB * 256 + X axis LSB
Gyro_Y = (I2C->read() * 256) + I2C->read(); // Y axis MSB * 256 + Y axis LSB
Gyro_Z = (I2C->read() * 256) + I2C->read(); // Z axis MSB * 256 + Z axis LSB
}
// Incorrent number of returned bytes
else {
Serial.println("Recieving incorrect amount of bytes from Gyroscope");
while(I2C->available()) {
Serial.print("data byte = ");
Serial.println(I2C->read(), DEC); //print the returned number as a decimal
}
}
I2C->endTransmission();
}
示例2: Init_Dev
// Initialise the device
void Init_Dev(TwoWire *I2C_Ptr) {
I2C = I2C_Ptr; // Pointer to the "Wire" I2C object
// Setup the ADXL345 Accelerometer
Serial.print("Setting up ADXL345 Accelerometer...");
//Put the sensor into measurement mode. The data sheet recommends that you first Reset, then Sleep mode then Measurement mode.
I2C->beginTransmission(AccelAddress);
I2C->write(0x2D); //Reset the POWER_CTL (0x2D) register.
I2C->write(0b00000000);
I2C->endTransmission();
I2C->beginTransmission(AccelAddress);
I2C->write(0x2D); //Put the ADXL345 into StandBy mode by writing 0x10 to the POWER_CTL (0x2D) register.
I2C->write(0b00010000);
I2C->endTransmission();
I2C->beginTransmission(AccelAddress);
I2C->write(0x2D); //Put the ADXL345 into Measurement Mode by writing 0x08 to the POWER_CTL (0x2D) register.
I2C->write(0b00001000);
I2C->endTransmission();
// force a calibration event
Accel_X_Center_Ave = 99;
//Set the G force range the sensor will work in
I2C->beginTransmission(AccelAddress);
I2C->write(0x31); //Put the ADXL345 into +/- 4G range by writing the value 0x01 to the DATA_FORMAT (0x31) register.
I2C->write(0b00000001); //(Default is +/-2G range
I2C->endTransmission();
Serial.println("Done");
delay(100);
}
示例3: prepare_pin
/* The "train" requested by servo motors is
the minimal of 20ms. Our PWM allow us to have
41.7Hz that means 23.98 ms.
However the cypress does not offer a good angle
resolution on this frequency and the user
has option to operates the servos in 188Hz */
void Servo::prepare_pin(uint8_t pin)
{
extern TwoWire Wire;
Wire.begin();
// let's use this function only to select the bit port
// the datasheet is a little confusing regading this set
analogWrite(pin, 1);
// Select programmable PWM CLK source to 367.7 Hz
Wire.beginTransmission(CYPRESS_I2C_ADDRESS);
Wire.write(0x29);
Wire.write(0x04);
Wire.endTransmission();
// Rising edge register
Wire.beginTransmission(CYPRESS_I2C_ADDRESS);
Wire.write(0x2a);
Wire.write(0xff);
Wire.endTransmission();
// Set divider to get 47.4Hz freq.
Wire.beginTransmission(CYPRESS_I2C_ADDRESS);
Wire.write(0x2C);
if (this->is188hz)
Wire.write(0x02);
else
Wire.write(0x09);
Wire.endTransmission();
}
示例4: 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;
}
示例5: 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;
}
示例6: MCP23018_Init_IOCON
void MCP23018_Init_IOCON(void)
{
delayMicroseconds(1000u);
i2c.beginTransmission((uint8_t)MISC_ADDR);
i2c.write(0x0Au); // select IOCON
i2c.write(0xA0u); // BANK=1, ADDR pointer NOT incremented
i2c.endTransmission();
delayMicroseconds(1000u);
i2c.beginTransmission((uint8_t)VEH_IO_ADDR);
i2c.write(0x0Au); // select IOCON
i2c.write(0xA0u); // BANK=1, ADDR pointer NOT incremented
i2c.endTransmission();
}
示例7: MCP23018_WRITE
void MCP23018_WRITE(uint8_t device, uint8_t reg, uint8_t data)
{
uint8_t addr;
if(DEV_MISC == device){ addr = MISC_ADDR; }
else{ addr = VEH_IO_ADDR; }
i2c.beginTransmission(addr);
i2c.write(reg);
i2c.write(data);
i2c.endTransmission();
}
示例8:
void PCF8574::i2cSend(){
PCFBUFFER = i2cRead(0x00);
for(int i=0;i<8;i++){
if(bitRead(PCFTRISA,i) == INPUT) bitWrite(PCFPORTA,i,bitRead(PCFBUFFER,i));
if(PCFPULL[i] == 1) bitWrite(PCFPORTA,i,1); // Required for unblock pull level
if(PCFPULL[i] == 2) bitWrite(PCFPORTA,i,0); // Required for unblock pull level
}
Wire1.beginTransmission(PCFaddress);
Wire1.write((uint8_t )PCFPORTA);
Wire1.endTransmission();
}
示例9: writeCommand
static void writeCommand(byte reg, byte value)
{
Wire1.beginTransmission((uint8_t)BMP085_ADDRESS);
#if ARDUINO >= 100
Wire1.write((uint8_t)reg);
Wire1.write((uint8_t)value);
#else
Wire1.send(reg);
Wire1.send(value);
#endif
Wire1.endTransmission();
}
示例10: NunchuckInitialize
static bool NunchuckInitialize(TwoWire& interface)
{
interface.begin(); // join i2c bus as master
interface.beginTransmission(0x52);// transmit to device 0x52
interface.write((uint8_t)0xF0);// sends a zero.
interface.write((uint8_t)0x55);// sends a zero.
interface.write((uint8_t)0xFB);// sends a zero.
interface.write((uint8_t)0x00);// sends a zero.
interface.endTransmission();// stop transmitting
return 1;
}
示例11: Read_Accel
// Read the ADXL345 Accelerometer
void Read_Accel() {
I2C->beginTransmission(AccelAddress); // start transmission to device
I2C->write(0x32); // point to the first data register DATAX0
I2C->endTransmission(); // end transmission
// read 6 byte, from address 32 (Data Registers)
I2C->beginTransmission(AccelAddress); // start transmission to device
I2C->requestFrom(AccelAddress, 6);
if (I2C->available() >= 6) {
Accel_X = I2C->read() + (I2C->read() * 256); // X axis LSB + X axis MSB * 256
Accel_Y = I2C->read() + (I2C->read() * 256); // Y axis LSB + Y axis MSB * 256
Accel_Z = I2C->read() + (I2C->read() * 256); // Z axis LSB + Z axis MSB * 256
}
// Incorrent number of returned bytes
else {
Serial.println("Recieving incorrect amount of bytes from Accelerometer");
while(I2C->available()) {
Serial.print("data byte = ");
Serial.println(I2C->read(), DEC); //print the returned number as a decimal
}
}
I2C->endTransmission();
}
示例12:
void MCP342X::selectChannel(byte channel, byte gain)
{
//configuration register, assuming 16 bit resolution
// Initiate one shot conversion
// 16 bits, 66.6 ms later the data should be available.
byte reg = 1 << BIT_RDY |
channel << BIT_C0 |
0 << BIT_OC |
1 << BIT_S1 |
gain;
Wire1.beginTransmission(I2C_ADDRESS);
Wire1.write(reg);
Wire1.endTransmission();
}
示例13:
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();
}
示例14:
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;
}
示例15: NunchuckReadData
static bool NunchuckReadData(TwoWire& interface, NunchuckData& data)
{
interface.requestFrom(0x52, 6);
data.jX = interface.read();
data.jY = interface.read();
data.accX = interface.read();
data.accY = interface.read();
data.accZ = interface.read();
data.buttons = interface.read();
data.accZ<<=2;
data.accZ|=data.buttons>>6;
data.accY<<=2;
data.accY|=(data.buttons>>4)&0x3;
data.accX<<=2;
data.accX|=(data.buttons>>2)&0x3;
data.buttons&=0x3;
SERIAL_PORT_MONITOR.print("Joy : ");
SERIAL_PORT_MONITOR.print(data.jX);
SERIAL_PORT_MONITOR.print(", ");
SERIAL_PORT_MONITOR.print(data.jY);
SERIAL_PORT_MONITOR.print("\tAcc : ");
SERIAL_PORT_MONITOR.print(data.accX);
SERIAL_PORT_MONITOR.print(", ");
SERIAL_PORT_MONITOR.print(data.accY);
SERIAL_PORT_MONITOR.print(", ");
SERIAL_PORT_MONITOR.print(data.accZ);
SERIAL_PORT_MONITOR.print("\tBtn : ");
SERIAL_PORT_MONITOR.print(" [");
SERIAL_PORT_MONITOR.print(data.buttons);
SERIAL_PORT_MONITOR.print("] ");
switch(data.buttons)
{
case 0x0ul:
SERIAL_PORT_MONITOR.println("C + Z");
break;
case 0x1ul:
SERIAL_PORT_MONITOR.println("C");
break;
case 0x2ul:
SERIAL_PORT_MONITOR.println("Z");
break;
case 0x3ul:
SERIAL_PORT_MONITOR.println("No key");
break;
default:
break;
}
interface.beginTransmission(0x52);// transmit to device 0x52
interface.write((uint8_t)0x00);// sends a zero.
interface.endTransmission();// stop transmitting
return 1;
}