Interfacing MPU9250 with BMD300.

I have designed a custom board and it has following components:
BMD300 (Module based on nRF52832 IC)
MPU9250
GPS (L80-R QUECTEL)
There are some other components as well but for now I just want to interface MPU9250 with BMD300. For that I am using the sample provided in the nRF Connect SDK (V 2.6.0) in VS Code. 
Pin Connection:
MPU9250       :   BMD300
SDA                :   9
SCL                :   8
Int                   :   22

I have pulled up the SDA and SCL lines with 4.7k resistors. AD0 pin of MPU9250 pulled down with 10k resistor so the address would be 0x68 according to the data sheet. 

Prj.conf:

CONFIG_I2C=y
CONFIG_SENSOR=y
CONFIG_MPU6050_TRIGGER_NONE=y
CONFIG_CBPRINTF_FP_SUPPORT=y

CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y
CONFIG_CLOCK_CONTROL_NRF_K32SRC_XTAL=n
CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC_CALIBRATION=y
CONFIG_NEWLIB_LIBC=y

CONFIG_LOG=y
CONFIG_RTT_CONSOLE=y

overlay file:
&i2c0 {
    mpu6050@68 {
        compatible = "invensense,mpu6050";
        reg = <0x68>;
        status = "okay";
        int-gpios = <&gpio0 22 GPIO_ACTIVE_HIGH>;
    };
};


Code builds without any errors. I am using J-Link (Segger) to program the BMD300. After uploading the code I get this:

Device mpu6050@68 is not ready
[00:00:00.500,152] <err> MPU6050: Failed to read chip ID.
*** Booting Zephyr OS build v3.5.99-ncs1 ***

BMD300 is getting the required power (3.2V) and so does the MPU9250. There are I2C header pins on my board so when I connect these pin with esp32. After uploading the code to the esp32 using Arduino IDE I am able to get the values.
Parents
  • Hi

    You can view the required properties here. It should be defined in the overlay for the device  

    &i2c0 {
        mpu6050@68 {
            compatible = "invensense,mpu9250"; //updated due to copy past error
            reg = <0x68>;
            status = "okay";
            int-gpios = <&gpio0 22 GPIO_ACTIVE_HIGH>;
            	gyro-sr-div = <10>;
        	gyro-dlpf = <5>;  //input fitting value
        	gyro-fs = <250>; //input fitting value
        	accel-fs = <2>;  //input fitting value
        	accel-dlpf="5.05"; //input fitting value
        };
    };

    I would expect it to look something like this

    Regards

    Runar

  • E:/SmartShoeFirmware/mpu6050_2/src/main.c: In function 'main':
    C:/ncs/v2.6.0/zephyr/include/zephyr/sys/util.h:94:55: error: size of unnamed array is negative
    94 | #define ZERO_OR_COMPILE_ERROR(cond) ((int) sizeof(char[1 - 2 * !(cond)]) - 1)
    | ^
    C:/ncs/v2.6.0/zephyr/include/zephyr/sys/util_internal.h:72:26: note: in definition of macro '__DEBRACKET'
    72 | #define __DEBRACKET(...) __VA_ARGS__
    | ^~~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/sys/util_internal.h:64:9: note: in expansion of macro '__GET_ARG2_DEBRACKET'
    64 | __GET_ARG2_DEBRACKET(one_or_two_args _if_code, _else_code)
    | ^~~~~~~~~~~~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/sys/util_internal.h:59:9: note: in expansion of macro '__COND_CODE'
    59 | __COND_CODE(_XXXX##_flag, _if_1_code, _else_code)
    | ^~~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/sys/util_macro.h:180:9: note: in expansion of macro 'Z_COND_CODE_1'
    180 | Z_COND_CODE_1(_flag, _if_1_code, _else_code)
    | ^~~~~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/device.h:284:9: note: in expansion of macro 'COND_CODE_1'
    284 | COND_CODE_1(DT_HAS_COMPAT_STATUS_OKAY(compat), \
    | ^~~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/device.h:286:22: note: in expansion of macro 'ZERO_OR_COMPILE_ERROR'
    286 | (ZERO_OR_COMPILE_ERROR(0)))
    | ^~~~~~~~~~~~~~~~~~~~~
    E:/SmartShoeFirmware/mpu6050_2/src/main.c:89:46: note: in expansion of macro 'DEVICE_DT_GET_ONE'
    89 | const struct device *const mpu6050 = DEVICE_DT_GET_ONE(invensense_mpu6050);
    | ^~~~~~~~~~~~~~~~~
    [6/63] Building C object zephyr/drivers/sensor/mpu9250/CMakeFiles/drivers__sensor__mpu9250.dir/mpu9250.c.obj
    FAILED: zephyr/drivers/sensor/mpu9250/CMakeFiles/drivers__sensor__mpu9250.dir/mpu9250.c.obj
    C:\ncs\toolchains\cf2149caf2\opt\zephyr-sdk\arm-zephyr-eabi\bin\arm-zephyr-eabi-gcc.exe -DKERNEL -DNRF52832_XXAA -D_ANSI_SOURCE -D_FORTIFY_SOURCE=1 -D__LINUX_ERRNO_EXTENSIONS__ -D__PROGRAM_START -D__ZEPHYR_SUPERVISOR__ -D__ZEPHYR__=1 -IC:/ncs/v2.6.0/zephyr/include -IE:/SmartShoeFirmware/mpu6050_2/build/zephyr/include/generated -IC:/ncs/v2.6.0/zephyr/soc/arm/nordic_nrf/nrf52 -IC:/ncs/v2.6.0/zephyr/lib/libc/newlib/include -IC:/ncs/v2.6.0/zephyr/soc/common/nordic_nrf/. -IC:/ncs/v2.6.0/zephyr/soc/arm/nordic_nrf/common/. -IC:/ncs/v2.6.0/modules/hal/cmsis/CMSIS/Core/Include -IC:/ncs/v2.6.0/zephyr/modules/cmsis/. -IC:/ncs/v2.6.0/modules/hal/nordic/nrfx -IC:/ncs/v2.6.0/modules/hal/nordic/nrfx/drivers/include -IC:/ncs/v2.6.0/modules/hal/nordic/nrfx/mdk -IC:/ncs/v2.6.0/zephyr/modules/hal_nordic/nrfx/. -IC:/ncs/v2.6.0/modules/debug/segger/SEGGER -IC:/ncs/v2.6.0/modules/debug/segger/Config -isystem C:/ncs/v2.6.0/zephyr/lib/libc/common/include -Wshadow -fno-strict-aliasing -Os -imacros E:/SmartShoeFirmware/mpu6050_2/build/zephyr/include/generated/autoconf.h -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m4 -mthumb -mabi=aapcs -mfp16-format=ieee --sysroot=C:/ncs/toolchains/cf2149caf2/opt/zephyr-sdk/arm-zephyr-eabi/arm-zephyr-eabi -imacros C:/ncs/v2.6.0/zephyr/include/zephyr/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -Werror=implicit-int -fno-pic -fno-pie -fno-asynchronous-unwind-tables -fno-reorder-functions --param=min-pagesize=0 -fno-defer-pop -fmacro-prefix-map=E:/SmartShoeFirmware/mpu6050_2=CMAKE_SOURCE_DIR -fmacro-prefix-map=C:/ncs/v2.6.0/zephyr=ZEPHYR_BASE -fmacro-prefix-map=C:/ncs/v2.6.0=WEST_TOPDIR -ffunction-sections -fdata-sections -std=c99 -MD -MT zephyr/drivers/sensor/mpu9250/CMakeFiles/drivers__sensor__mpu9250.dir/mpu9250.c.obj -MF zephyr\drivers\sensor\mpu9250\CMakeFiles\drivers__sensor__mpu9250.dir\mpu9250.c.obj.d -o zephyr/drivers/sensor/mpu9250/CMakeFiles/drivers__sensor__mpu9250.dir/mpu9250.c.obj -c C:/ncs/v2.6.0/zephyr/drivers/sensor/mpu9250/mpu9250.c
    In file included from C:/ncs/v2.6.0/zephyr/include/zephyr/sys/util_macro.h:34,
    from C:/ncs/v2.6.0/zephyr/include/zephyr/sys/util.h:17,
    from C:/ncs/v2.6.0/zephyr/include/zephyr/sys/cbprintf_internal.h:15,
    from C:/ncs/v2.6.0/zephyr/include/zephyr/sys/cbprintf.h:124,
    from C:/ncs/v2.6.0/zephyr/include/zephyr/logging/log_msg.h:11,
    from C:/ncs/v2.6.0/zephyr/include/zephyr/logging/log_core.h:9,
    from C:/ncs/v2.6.0/zephyr/include/zephyr/logging/log.h:11,
    from C:/ncs/v2.6.0/zephyr/drivers/sensor/mpu9250/mpu9250.c:10:
    C:/ncs/v2.6.0/zephyr/include/zephyr/device.h:89:41: error: '__device_dts_ord_DT_N_S_soc_S_i2c_40003000_S_mpu9250_68_P_irq_gpios_IDX_0_PH_ORD' undeclared here (not in a function)
    89 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
    | ^~~~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/sys/util_internal.h:72:26: note: in definition of macro '__DEBRACKET'
    72 | #define __DEBRACKET(...) __VA_ARGS__
    | ^~~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/sys/util_internal.h:64:9: note: in expansion of macro '__GET_ARG2_DEBRACKET'
    64 | __GET_ARG2_DEBRACKET(one_or_two_args _if_code, _else_code)
    | ^~~~~~~~~~~~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/sys/util_internal.h:59:9: note: in expansion of macro '__COND_CODE'
    59 | __COND_CODE(_XXXX##_flag, _if_1_code, _else_code)
    | ^~~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/sys/util_macro.h:180:9: note: in expansion of macro 'Z_COND_CODE_1'
    180 | Z_COND_CODE_1(_flag, _if_1_code, _else_code)
    | ^~~~~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/devicetree.h:4151:9: note: in expansion of macro 'COND_CODE_1'
    4151 | COND_CODE_1(DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT), \
    | ^~~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/sys/util_internal.h:69:53: note: in expansion of macro '__DEBRACKET'
    69 | #define __GET_ARG2_DEBRACKET(ignore_this, val, ...) __DEBRACKET val
    | ^~~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/sys/util_internal.h:64:9: note: in expansion of macro '__GET_ARG2_DEBRACKET'
    64 | __GET_ARG2_DEBRACKET(one_or_two_args _if_code, _else_code)
    | ^~~~~~~~~~~~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/sys/util_internal.h:59:9: note: in expansion of macro '__COND_CODE'
    59 | __COND_CODE(_XXXX##_flag, _if_1_code, _else_code)
    | ^~~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/sys/util_macro.h:180:9: note: in expansion of macro 'Z_COND_CODE_1'
    180 | Z_COND_CODE_1(_flag, _if_1_code, _else_code)
    | ^~~~~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/sys/util_macro.h:224:9: note: in expansion of macro 'COND_CODE_1'
    224 | COND_CODE_1(_flag, _code, ())
    | ^~~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/drivers/sensor/mpu9250/mpu9250.c:357:9: note: in expansion of macro 'IF_ENABLED'
    357 | IF_ENABLED(CONFIG_MPU9250_TRIGGER, \
    | ^~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/toolchain/common.h:138:23: note: in expansion of macro '_DO_CONCAT'
    138 | #define _CONCAT(x, y) _DO_CONCAT(x, y)
    | ^~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/device.h:89:33: note: in expansion of macro '_CONCAT'
    89 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
    | ^~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/device.h:216:37: note: in expansion of macro 'DEVICE_NAME_GET'
    216 | #define DEVICE_DT_NAME_GET(node_id) DEVICE_NAME_GET(Z_DEVICE_DT_DEV_ID(node_id))
    | ^~~~~~~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/device.h:233:34: note: in expansion of macro 'DEVICE_DT_NAME_GET'
    233 | #define DEVICE_DT_GET(node_id) (&DEVICE_DT_NAME_GET(node_id))
    | ^~~~~~~~~~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/drivers/gpio.h:331:25: note: in expansion of macro 'DEVICE_DT_GET'
    331 | .port = DEVICE_DT_GET(DT_GPIO_CTLR_BY_IDX(node_id, prop, idx)),\
    | ^~~~~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/drivers/gpio.h:393:9: note: in expansion of macro 'GPIO_DT_SPEC_GET_BY_IDX'
    393 | GPIO_DT_SPEC_GET_BY_IDX(DT_DRV_INST(inst), prop, idx)
    | ^~~~~~~~~~~~~~~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/drivers/gpio.h:420:9: note: in expansion of macro 'GPIO_DT_SPEC_INST_GET_BY_IDX'
    420 | GPIO_DT_SPEC_INST_GET_BY_IDX(inst, prop, 0)
    | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/drivers/sensor/mpu9250/mpu9250.c:358:31: note: in expansion of macro 'GPIO_DT_SPEC_INST_GET'
    358 | (.int_pin = GPIO_DT_SPEC_INST_GET(inst, irq_gpios))) \
    | ^~~~~~~~~~~~~~~~~~~~~
    E:/SmartShoeFirmware/mpu6050_2/build/zephyr/include/generated/devicetree_generated.h:11655:53: note: in expansion of macro 'INIT_MPU9250_INST'
    11655 | #define DT_FOREACH_OKAY_INST_invensense_mpu9250(fn) fn(0)
    | ^~
    C:/ncs/v2.6.0/zephyr/include/zephyr/sys/util_internal.h:105:36: note: in expansion of macro 'DT_FOREACH_OKAY_INST_invensense_mpu9250'
    105 | #define UTIL_PRIMITIVE_CAT(a, ...) a##__VA_ARGS__
    | ^
    C:/ncs/v2.6.0/zephyr/drivers/sensor/mpu9250/mpu9250.c:366:1: note: in expansion of macro 'DT_INST_FOREACH_STATUS_OKAY'
    366 | DT_INST_FOREACH_STATUS_OKAY(INIT_MPU9250_INST)
    | ^~~~~~~~~~~~~~~~~~~~~~~~~~~
    E:/SmartShoeFirmware/mpu6050_2/build/zephyr/include/generated/devicetree_generated.h:11026:40: error: 'DT_N_S_soc_S_i2c_40003000_S_mpu9250_68_P_irq_gpios_IDX_0_VAL_pin' undeclared here (not in a function); did you mean 'DT_N_S_soc_S_i2c_40003000_S_mpu9250_68_P_reg_IDX_0_EXISTS'?
    11026 | #define DT_N_INST_0_invensense_mpu9250 DT_N_S_soc_S_i2c_40003000_S_mpu9250_68
    | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/sys/util_internal.h:72:26: note: in definition of macro '__DEBRACKET'
    72 | #define __DEBRACKET(...) __VA_ARGS__
    | ^~~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/sys/util_internal.h:64:9: note: in expansion of macro '__GET_ARG2_DEBRACKET'
    64 | __GET_ARG2_DEBRACKET(one_or_two_args _if_code, _else_code)
    | ^~~~~~~~~~~~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/sys/util_internal.h:59:9: note: in expansion of macro '__COND_CODE'
    59 | __COND_CODE(_XXXX##_flag, _if_1_code, _else_code)
    | ^~~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/sys/util_macro.h:180:9: note: in expansion of macro 'Z_COND_CODE_1'
    180 | Z_COND_CODE_1(_flag, _if_1_code, _else_code)
    | ^~~~~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/devicetree.h:4151:9: note: in expansion of macro 'COND_CODE_1'
    4151 | COND_CODE_1(DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT), \
    | ^~~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/sys/util_internal.h:69:53: note: in expansion of macro '__DEBRACKET'
    69 | #define __GET_ARG2_DEBRACKET(ignore_this, val, ...) __DEBRACKET val
    | ^~~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/sys/util_internal.h:64:9: note: in expansion of macro '__GET_ARG2_DEBRACKET'
    64 | __GET_ARG2_DEBRACKET(one_or_two_args _if_code, _else_code)
    | ^~~~~~~~~~~~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/sys/util_internal.h:59:9: note: in expansion of macro '__COND_CODE'
    59 | __COND_CODE(_XXXX##_flag, _if_1_code, _else_code)
    | ^~~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/sys/util_macro.h:180:9: note: in expansion of macro 'Z_COND_CODE_1'
    180 | Z_COND_CODE_1(_flag, _if_1_code, _else_code)
    | ^~~~~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/sys/util_macro.h:224:9: note: in expansion of macro 'COND_CODE_1'
    224 | COND_CODE_1(_flag, _code, ())
    | ^~~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/drivers/sensor/mpu9250/mpu9250.c:357:9: note: in expansion of macro 'IF_ENABLED'
    357 | IF_ENABLED(CONFIG_MPU9250_TRIGGER, \
    | ^~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/devicetree.h:1371:9: note: in expansion of macro 'DT_CAT7'
    1371 | DT_CAT7(node_id, _P_, pha, _IDX_, idx, _VAL_, cell)
    | ^~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/devicetree/gpio.h:164:9: note: in expansion of macro 'DT_PHA_BY_IDX'
    164 | DT_PHA_BY_IDX(node_id, gpio_pha, idx, pin)
    | ^~~~~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/drivers/gpio.h:332:24: note: in expansion of macro 'DT_GPIO_PIN_BY_IDX'
    332 | .pin = DT_GPIO_PIN_BY_IDX(node_id, prop, idx), \
    | ^~~~~~~~~~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/drivers/gpio.h:393:9: note: in expansion of macro 'GPIO_DT_SPEC_GET_BY_IDX'
    393 | GPIO_DT_SPEC_GET_BY_IDX(DT_DRV_INST(inst), prop, idx)
    | ^~~~~~~~~~~~~~~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/sys/util_internal.h:105:36: note: in expansion of macro 'DT_N_INST_0_invensense_mpu9250'
    105 | #define UTIL_PRIMITIVE_CAT(a, ...) a##__VA_ARGS__
    | ^
    C:/ncs/v2.6.0/zephyr/include/zephyr/sys/util_internal.h:104:26: note: in expansion of macro 'UTIL_PRIMITIVE_CAT'
    104 | #define UTIL_CAT(a, ...) UTIL_PRIMITIVE_CAT(a, __VA_ARGS__)
    | ^~~~~~~~~~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/devicetree.h:334:31: note: in expansion of macro 'UTIL_CAT'
    334 | #define DT_INST(inst, compat) UTIL_CAT(DT_N_INST, DT_DASH(inst, compat))
    | ^~~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/devicetree.h:3319:27: note: in expansion of macro 'DT_INST'
    3319 | #define DT_DRV_INST(inst) DT_INST(inst, DT_DRV_COMPAT)
    | ^~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/drivers/gpio.h:393:33: note: in expansion of macro 'DT_DRV_INST'
    393 | GPIO_DT_SPEC_GET_BY_IDX(DT_DRV_INST(inst), prop, idx)
    | ^~~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/include/zephyr/drivers/gpio.h:420:9: note: in expansion of macro 'GPIO_DT_SPEC_INST_GET_BY_IDX'
    420 | GPIO_DT_SPEC_INST_GET_BY_IDX(inst, prop, 0)
    | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
    C:/ncs/v2.6.0/zephyr/drivers/sensor/mpu9250/mpu9250.c:358:31: note: in expansion of macro 'GPIO_DT_SPEC_INST_GET'
    358 | (.int_pin = GPIO_DT_SPEC_INST_GET(inst, irq_gpios))) \
    | ^~~~~~~~~~~~~~~~~~~~~
    E:/SmartShoeFirmware/mpu6050_2/build/zephyr/include/generated/devicetree_generated.h:11655:53: note: in expansion of macro 'INIT_MPU9250_INST'
    11655 | #define DT_FOREACH_OKAY_INST_invensense_mpu9250(fn) fn(0)
    | ^~
    C:/ncs/v2.6.0/zephyr/include/zephyr/sys/util_internal.h:105:36: note: in expansion of macro 'DT_FOREACH_OKAY_INST_invensense_mpu9250'
    105 | #define UTIL_PRIMITIVE_CAT(a, ...) a##__VA_ARGS__
    | ^
    C:/ncs/v2.6.0/zephyr/drivers/sensor/mpu9250/mpu9250.c:366:1: note: in expansion of macro 'DT_INST_FOREACH_STATUS_OKAY'
    366 | DT_INST_FOREACH_STATUS_OKAY(INIT_MPU9250_INST)

  •  &i2c0 {
        mpu6050@68 {
            compatible = "invensense,mpu9250"; //updated due to copy past error
            reg = <0x68>;
            status = "okay";
            gyro-sr-div = <10>;
            gyro-dlpf = <5>;  //input fitting value
            gyro-fs = <250>; //input fitting value
            accel-fs = <2>;  //input fitting value
            accel-dlpf="5.05"; //input fitting value
        };
    };


    #include <zephyr/kernel.h>
    #include <zephyr/device.h>
    #include <zephyr/drivers/sensor.h>
    #include <stdio.h>

    static int process_mpu6050(const struct device *dev)
    {
        struct sensor_value temperature;
        struct sensor_value accel[3];
        struct sensor_value gyro[3];
        int rc = sensor_sample_fetch(dev);

        if (rc == 0) {
            rc = sensor_channel_get(dev, SENSOR_CHAN_ACCEL_XYZ,
                        accel);
        }
        if (rc == 0) {
            rc = sensor_channel_get(dev, SENSOR_CHAN_GYRO_XYZ,
                        gyro);
        }
        if (rc == 0) {
            rc = sensor_channel_get(dev, SENSOR_CHAN_DIE_TEMP,
                        &temperature);
        }
        if (rc == 0) {
            printf("[%s]:%g Cel\n"
                   "  accel %f %f %f m/s/s\n"
                   "  gyro  %f %f %f rad/s\n",
                   now_str(),
                   sensor_value_to_double(&temperature),
                   sensor_value_to_double(&accel[0]),
                   sensor_value_to_double(&accel[1]),
                   sensor_value_to_double(&accel[2]),
                   sensor_value_to_double(&gyro[0]),
                   sensor_value_to_double(&gyro[1]),
                   sensor_value_to_double(&gyro[2]));
        } else {
            printf("sample fetch/get failed: %d\n", rc);
        }

        return rc;
    }

    #ifdef CONFIG_MPU6050_TRIGGER
    static struct sensor_trigger trigger;

    static void handle_mpu6050_drdy(const struct device *dev,
                    const struct sensor_trigger *trig)
    {
        int rc = process_mpu6050(dev);

        if (rc != 0) {
            printf("cancelling trigger due to failure: %d\n", rc);
            (void)sensor_trigger_set(dev, trig, NULL);
            return;
        }
    }
    #endif /* CONFIG_MPU6050_TRIGGER */

    int main(void)
    {
        const struct device *const mpu6050 = DEVICE_DT_GET_ONE(invensense_mpu6050);
        // const struct device *const mpu6050 = DEVICE_DT_NAME(mpu6050);

        if (!device_is_ready(mpu6050)) {
            printf("Device %s is not ready\n", mpu6050->name);
            return 0;
        }

    #ifdef CONFIG_MPU6050_TRIGGER
        trigger = (struct sensor_trigger) {
            .type = SENSOR_TRIG_DATA_READY,
            .chan = SENSOR_CHAN_ALL,
        };
        if (sensor_trigger_set(mpu6050, &trigger,
                       handle_mpu6050_drdy) < 0) {
            printf("Cannot configure trigger\n");
            return 0;
        }
        printk("Configured for triggered sampling.\n");
    #endif

        while (!IS_ENABLED(CONFIG_MPU6050_TRIGGER)) {
            int rc = process_mpu6050(mpu6050);

            if (rc != 0) {
                break;
            }
            k_sleep(K_SECONDS(2));
        }

        /* triggered runs with its own thread after exit */
        return 0;
    }
  • One thing I removed the int-gpios property as it was giving error that this property is not mentioned in invensense,mpu9250

  • Hi, the following setup compiles for me. You need to include the irq-gpios

    //overlay
    &i2c1 {
        status="okay";
        compatible = "nordic,nrf-twim";
    
    
        mpu9250@68 {
            compatible = "invensense,mpu9250"; //updated due to copy past error
            reg = <0x68>;
            status = "okay";
            gyro-sr-div = <10>;
        	gyro-dlpf = <5>;  //input fitting value
        	gyro-fs = <250>; //input fitting value
        	accel-fs = <2>;  //input fitting value
        	accel-dlpf="5.05"; //input fitting value
            irq-gpios = <&gpio0 0 0 >;
    
        };
    };
    // prj.conf
    CONFIG_I2C=y
    CONFIG_SENSOR=y
    CONFIG_MPU9250=y
    
    //main
    #include <zephyr/kernel.h>
    #include <stdio.h>
    #include <zephyr/drivers/sensor.h>
    #include <zephyr/devicetree.h>
    #include <zephyr/device.h>
    #include <zephyr/drivers/gpio.h>
    #include <zephyr/drivers/i2c.h>
    
    
    int main(void)
    {
    	static const struct device *sensor = DEVICE_DT_GET_ANY(mpu9250);
    
        if (sensor == NULL || !device_is_ready(sensor))
        {
            printf("Could not get accel0 device\n");
            
        }
    
    	printf("Hello World! %s\n", CONFIG_BOARD);
    	return 0;
    }
    

    Regards

    Runar

  • Hi Runar,
    Thanks. Let me check and I will let you know if any error occurs.

  • One more question Runar. Should I change pins in overlay file or in dts? B/C I am using pin 8 and 9 as mentioned at the top.

Reply Children
Related