Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

Thingy52: MPU9250 i2c_nrfx_twim: Error 0x0BAE0001 occurred for message 0

Hi,

I'm trying to test the MPU9250 included on the Thingy52

My Overlay file:

&i2c0 {
mpu9250: mpu9250@68 {
compatible = "invensense,mpu9250";
reg = <0x68>;
status = "okay";
friendly-name = "MPU9250";
irq-gpios = <&gpio0 06 GPIO_ACTIVE_HIGH>;
accel-fs = < 2 >;
accel-dlpf = "218.1";
gyro-fs = < 250 >;
gyro-dlpf = < 250 >;
gyro-sr-div = < 1 >;
vin-supply = <&mpu_pwr>;
};
};
&mpu_pwr {
status = "okay";
regulator-always-on;
}
;
My prj.conf
CONFIG_STDOUT_CONSOLE=y
CONFIG_PRINTK=y
CONFIG_LOG=y
CONFIG_LOG_PRINTK=y
CONFIG_LOG_MODE_IMMEDIATE=y
CONFIG_I2C=y
CONFIG_I2C_LOG_LEVEL_DBG=y
CONFIG_SENSOR=y
CONFIG_MPU9250=y
CONFIG_MPU9250_TRIGGER_GLOBAL_THREAD=y
CONFIG_CBPRINTF_FP_SUPPORT=y
Logging messages:
[00:00:00.342,468] <err> regulator_fixed: GPIO port: sx1509b@3e not ready
[00:00:00.350,250] <err> regulator_fixed: GPIO port: sx1509b@3e not ready
[00:00:00.363,006] <inf> sx1509b: sx1509b@3e init ok
[00:00:00.399,597] <inf> CCS811: App FW 1100
[00:00:00.410,949] <inf> lis2dh: fs=2, odr=0x4 lp_en=0x0 scale=9576
[00:00:00.419,006] <err> i2c_nrfx_twim: Error 0x0BAE0001 occurred for message 0
[00:00:00.427,368] <err> MPU9250: Failed to read chip ID.
*** Booting Zephyr OS build v3.3.99-ncs1 ***
Did I missed something?
Suggestions?
Thanks and Best Regards,
JP
  • Hi Jose,

    Thank you for contacting DevZone at NordicSemi.

    Which SDK you are using and what sample your application is based on?
    I can see that there is a Zephyr sample using MPU6050

    You can check .config to be sure that your configurations are taking place.

    Also, it is good to check compiled DTS to be sure that the overlay settings are taking place.

    There is also a ticket on the GitHub with the same error 

    Regards,
    Naeem

  • Hi Naeem,

    I'm using SDK v2.4.0 clean installation.

    Where is the .config file/directory? I can't find it.

    How do I check the compile DTS?

    Best Regards,

    JP

  • Hello Jose,

    You can check .config file in the /build/zephyr/ folder as shown below:

    You can also check the compiled DTS from the NRF Connect Extension on the left (bottom) in VS Code

    compiled DTS is also present in the /build/zephyr/ folder with name zephyr.dts

    Regards,

    Naeem

  • I check the hardware were ok testing it with a default firmware for Thingy52.

    The MPU9250 works with that firmware.

    I couldn't found any missing configuration anywhere on the build

    Is there a way I can test the MPU has power in the first place?
    Does the mpu_pwr has to active in High?

    If this is ok:

    mpu_pwr: mpu-pwr-ctrl {
      compatible = "regulator-fixed";
      regulator-name = "mpu-pwr-ctrl";
      enable-gpios = <&sx1509b 8 GPIO_ACTIVE_HIGH>;
      status = "okay";
      regulator-boot-on;
    };
    Then I don't know what else to look for.
    The MPU6050 example doesn't work either 
  • Hi Naeem,

    I figure it out.

    I Added this on the KConfig file of the project:

    config BOARD_MPU_VDD_PWR_CTRL_INIT_PRIORITY
      int "MPU_VDD power rail init priority"
      default 85
      depends on GPIO_SX1509B
      help
        Initialization priority for the MPU_VDD power rail. This powers the
        MPU9250 gas sensor. The value has to be greater than
        BOARD_VDD_PWR_CTRL_INIT_PRIORITY, but smaller than SENSOR_INIT_PRIORITY.
    Then I added on the main.c file:

    static const struct gpio_dt_spec mpu_gpio =
        GPIO_DT_SPEC_GET(DT_NODELABEL(mpu_pwr), enable_gpios);
    static int mpu_pwr_ctrl_init(void)
    {
      int ret;

      if (!device_is_ready(mpu_gpio.port)) {
        return -ENODEV;
      }
      ret = gpio_pin_configure_dt(&mpu_gpio, GPIO_OUTPUT_HIGH);
      if (ret < 0) {
        return ret;
      }

      k_sleep(K_MSEC(1)); /* Wait for the rail to come up and stabilize */
      return 0;
    }


    #if CONFIG_SENSOR_INIT_PRIORITY <= CONFIG_BOARD_MPU_VDD_PWR_CTRL_INIT_PRIORITY
    #error BOARD_CCS_VDD_MPU_PWR_CTRL_INIT_PRIORITY must be lower than SENSOR_INIT_PRIORITY
    #endif

    SYS_INIT(mpu_pwr_ctrl_init, POST_KERNEL,
         CONFIG_BOARD_MPU_VDD_PWR_CTRL_INIT_PRIORITY);
    After that I got it working:

    -Link OB-nRF5340-NordicSemi compiled Nov 7 2022 16:22:01 V1.0, SN=1050054727
    Process: JLinkExe
    [00:00:00.346,191] <err> regulator_fixed: GPIO port: sx1509b@3e not ready
    [00:00:00.358,947] <inf> sx1509b: sx1509b@3e init ok
    [00:00:00.397,491] <inf> CCS811: App FW 1100
    [00:00:00.408,874] <inf> lis2dh: fs=2, odr=0x4 lp_en=0x0 scale=9576
    *** Booting Zephyr OS build v3.3.99-ncs1 ***
    MPU9250: Main()
    MPU9250: device *const mpu9250
    Device mpu9250@68 is ready
    I still needs to figure it out how to pull sensor data from the MPU9250 or to execute a callback every time there is a IRQ-GPIO from the MPU9250.
    This ticket can be label as resolved.

Related