DFRobot / DFRobot_BMI160

MIT License
25 stars 22 forks source link

Having Wire.begin() in the constructor causes some platforms (adafruit feather m0 logger) to freeze #7

Open GoonieG opened 1 year ago

GoonieG commented 1 year ago

I was having an issue with the example code (accelGyro) not running, and freezing com ports, etc. I traced the issue to having Wire.begin() in the class constructor: DFRobot_BMI160::DFRobot_BMI160() The feather m0 seems to lock up, especially when instantiating the: DFRobot_BMI160 bmi160;

As a global object, before the void setup() function.

The solution was to move Wire.begin() to the beginning of: int8_t DFRobot_BMI160::I2cInit(int8_t i2c_addr)

My Code changes were as follows (in DFRobot_BMI160.cpp) DFRobot_BMI160::DFRobot_BMI160() { // Wire.begin();

Obmi160=(struct bmi160Dev *)malloc(sizeof(struct bmi160Dev)); //Obmi160->id = BMI160_I2C_ADDR; //Obmi160->interface = BMI160_I2C_INTF; Oaccel= (struct bmi160SensorData*)malloc(sizeof(struct bmi160SensorData)); Ogyro = (struct bmi160SensorData*)malloc(sizeof(struct bmi160SensorData)); }

int8_t DFRobot_BMI160::I2cInit(int8_t i2c_addr) { Wire.begin();

Obmi160->id = i2c_addr; Obmi160->interface = BMI160_I2C_INTF; return DFRobot_BMI160::I2cInit(Obmi160); }

krisstakos commented 1 year ago

Thanks, that also fixes the i2c init failure for bluepill(stm32)