Hello paraas,
Unfortuantely, we don't have example code for Teensy 3.2 MCU.
However, here is the my i2c example for arduino.
bmi2xy_hal_i2c_bus_read and bmi2xy_hal_i2c_bus_write are put to bmi2 function pointers as below.
Thanks,
bmi2.read = bmi2xy_hal_i2c_bus_read; bmi2.write = bmi2xy_hal_i2c_bus_write;
/*! This API is used to perform I2C read operation with sensor */ int8_t bmi2xy_hal_i2c_bus_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, void *intf_ptr) { int8_t rslt = 0; //uint8_t dev_id = 0x68; uint8_t* dev_id = (uint8_t *)intf_ptr;
rslt = BMI270_read_i2c(*dev_id, reg_addr, reg_data, length);
return rslt; }
/*! This API is used to perform I2C write operations with sensor */ int8_t bmi2xy_hal_i2c_bus_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr) { int8_t rslt = 0; // uint8_t dev_id = 0x68;
uint8_t* dev_id = (uint8_t *)intf_ptr; rslt = BMI270_write_i2c(*dev_id, reg_addr, (uint8_t *)reg_data, length);
return rslt; }
int8_t BMI270_read_i2c(uint8_t dev_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t count) { /* dev_addr: I2C device address. reg_addr: Starting address for writing the data. reg_data: Data to be written. count: Number of bytes to write */ // Begin I2C communication with provided I2C address Wire.beginTransmission(dev_addr); Wire.write(reg_addr); // Done writting, end the transmission int8_t returned = Wire.endTransmission();
if (returned) { return returned; }
// Requests the required number of bytes from the sensor Wire.requestFrom((int)dev_addr, (int)count);
uint16_t i; // Reads the requested number of bytes into the provided array for (i = 0; (i < count) && Wire.available(); i++) { reg_data[i] = Wire.read(); // This is for the modern Wire library }
// This must return 0 on success, any other value will be interpreted as a communication failure. return 0; }
int8_t BMI270_write_i2c(uint8_t dev_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t count) { /* dev_addr: I2C device address. reg_addr: Starting address for reading the data. reg_data: Buffer to take up the read data. count: Number of bytes to read. */ // Begin I2C communication with provided I2C address Wire.beginTransmission(dev_addr); Wire.write(reg_addr);
uint16_t i; // Writes the requested number of bytes from the provided array for (i = 0; i < count; i++) { Wire.write(reg_data[i]); // This is for the modern Wire library } // Done writting, end the transmission int8_t returned = Wire.endTransmission(); return returned; }
... View more