Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
GoonieG opened this issue Feb 11, 2023 · 1 comment · May be fixed by #9

Comments

@GoonieG
Copy link

GoonieG commented Feb 11, 2023

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
Copy link

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

@krisstakos krisstakos linked a pull request Aug 19, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants