Hello,
I’m working with the Arduino Nano 33 BLE (nrf52840) inside Mbed Studio(flashing with J-Link).
The board features an LSM9DS1 IMU connected via I2C as seen in the schematics. The Arduino example with their own library works without problem but once outside arduino I tried some mbed friendly LSM9DS1 libraries which did not work.
After some debugging I realized the sensor is not even popping up on the I2C bus. I have tried several things like turning on the VDD_ENV pin but nothing works.
Here is the smallest possible code to reproduce the issue, in which I’ve also commented out a loop that looks for the device that doesn’t work either. I don’t know what I’m missing:
#include "USBSerial.h"
#include "mbed.h"
#define LSM9DS1_ADDRESS 0x6b
#define LSM9DS1_CTRL_REG8 0x22
#define LSM9DS1_WHO_AM_I 0x0f
DigitalOut acc_pwr(VDD_ENV);
USBSerial pc;
I2C i2c(I2C_SDA1, I2C_SCL1); // sda, scl
int main() {
i2c.frequency(100000);
i2c.start();
acc_pwr = 1; // Doesn't seem to improve anything
ThisThread::sleep_for(1s);
int nack = 0;
char cmd[2] = {0};
/*
// Try to write on every address but
// No succesful write on any address
cmd[0] = LSM9DS1_CTRL_REG8;
cmd[1] = 0x05;
for(int i = 0; i < 128; i++){
ack = i2c.write(i, cmd, 2);
pc.printf("ack is %d, i is %d \r\n", ack, i);
ThisThread::sleep_for(10ms);
}
*/
cmd[0] = LSM9DS1_CTRL_REG8;
cmd[1] = 0x05;
nack = i2c.write(LSM9DS1_ADDRESS, cmd, 2);
//Returns 0 on success (ack), nonzero on failure (nack)
pc.printf("nack is %d \r\n", nack); // Fails
ThisThread::sleep_for(10ms);
cmd[0] = LSM9DS1_WHO_AM_I;
i2c.write(LSM9DS1_ADDRESS, cmd, 1);
i2c.read(LSM9DS1_ADDRESS, cmd, 1);
pc.printf("cmd[0] is %d\r\n", cmd[0]);
while (1) ThisThread::sleep_for(1s);
}
Which prints:
nack is 1
cmd[0] is 15
I’m just doing the same thing as the Arduino library, but the important thing is that not even the write is successful, meaning the device is not detected.
Any ideas of what is going on? I ran out of things to try.