Hi all,
I'm working on getting magnetometer data with a M5StickC Plus and ENV II Hat.
I found that I2C communication between M5StickC Plus and BMM150 is not working as expected, and am wondering if you can provide some guidance to make it work.
I'm using a sample code at
https://github.com/m5stack/M5StickC-Plus/tree/master/examples/Hat/ENVII_SHT30_BMP280
I tried it as is. It did not work (the code stopped running somewhere)
I added Wire.begin(0, 26) in the setup function since the hat is connected to G0 and G26. This got the same result.
Then, I dug into where the code stopped.
It stopped at BMM150::initialize > set_op_mode > suspend_to_sleep_mode > set_power_control_bit > i2c_read
In i2c_read, when the code called Wire.requestFrom(BMM150_I2C_Address, 1), it did not return.
How can I fix the issue?
Here is a minimal code to reproduce the issue.
#include <M5StickCPlus.h>
#define BMM150_I2C_Address 0x10 // These are copied from bmm150_defs.h
#define BMM150_POWER_CONTROL_ADDR 0x4B
void setup() {
M5.begin();
Wire.begin(0, 26);
delay(3000); // Make sure to avoid any race conditions
Serial.println("Start setup");
uint8_t reg_data = i2c_read(BMM150_POWER_CONTROL_ADDR);
}
void loop() {
delay(1000);
Serial.println("loop");
}
uint8_t i2c_read(short address)
{
uint8_t byte;
int result;
Wire.beginTransmission(BMM150_I2C_Address);
result = Wire.endTransmission();
Serial.printf("%d\n", result); // This sometimes gets 2: NACK, which is a bit strange
Wire.beginTransmission(BMM150_I2C_Address);
result = Wire.endTransmission();
Serial.printf("%d\n", result); // This gets 0: Success
Wire.beginTransmission(BMM150_I2C_Address);
Wire.write(address);
result = Wire.endTransmission();
Serial.printf("%d\n", result); // This gets 0: Success
Wire.beginTransmission(BMM150_I2C_Address);
Serial.println("call Wire.requestFrom");
Wire.requestFrom(BMM150_I2C_Address, 1, 0);
Serial.println("call returned"); // This is never called
byte = Wire.read();
Wire.endTransmission();
return byte;
}