Unable to read the IMU, GPIO Expander data through I2C

Hi,

We are working with nRF52840 MCU with zephyr v2.9.2 SDK and Visual Studio IDE for debugging, Flashing, Generating zephyr.uf2 file. We took one example have configured the I2C driver (I2C pins 04,05 in .overlay file) for BHI160B IMU and GPIO expander data.

First we developed our application using nRF52840 DK board and it is working as expected after we generated zephyr.uf2 file by modifying the build configurations for Seeed Studio xiao_nrf52840 board and tested. We successfully completed the .uf2 file flash in Seeed Studio xiao_nrf52840. When we reset the board it only shows the device ID of BHI160B IMU as 0x83. But unable to write the Firmware to IMU & getting failed at initial stage only. 

Please go through the below information and suggest to get the data from the BHI160B IMU using Seeed Studio xiao_nrf52840. I would appreciate to the help provided for below

Thank you,


1. I have added below in the .overlay file 

&i2c0 {
    compatible = "nordic,nrf-twim";
    status = "okay";

    pinctrl-0 = <&i2c0_default>;
    pinctrl-1 = <&i2c0_sleep>;
    pinctrl-names = "default", "sleep";

    clock-frequency = <I2C_BITRATE_FAST>;

    bhi160b: bhi160b@29 {
        compatible = "bosch,bhi160b";
        reg = <0x29>;
        label = "BHI160B";
        int-gpios = <&gpio1 15 GPIO_ACTIVE_LOW>;
        status = "okay";
    };
};

&pinctrl {
    i2c0_default: i2c0_default {
        group1 {
            psels = <NRF_PSEL(TWIM_SDA, 0, 26)>,
                    <NRF_PSEL(TWIM_SCL, 0, 27)>;
        };
    };
    i2c0_sleep: i2c0_sleep {
        group1 {
            psels = <NRF_PSEL(TWIM_SDA, 0, 26)>,
                    <NRF_PSEL(TWIM_SCL, 0, 27)>;
            low-power-enable;
        };
    };
};


2. This is the main.c file having IMU initialization and Data reading in while code 
int main(void)
{
    int ret;
    uint16_t bytes_read, bytes_remaining;
    bhy_data_generic_t fifo_packet;
    bhy_data_type_t packet_type;
    BHY_RETURN_FUNCTION_TYPE result;
    //LOG_INF("Starting BHI160B I2C + GPIO interrupt test...");

    nrf_gpio_cfg_input(CUSTOM_BUTTON, NRF_GPIO_PIN_NOPULL);

    if (!p_bhy) {
    printk("p_bhy is NULL\n");
    return;
    }
    printf("Starting BHI160B I2C + GPIO interrupt test...\n");

    struct bhy_t *p_bhy;

    p_bhy = bhy_init();
    __ASSERT(p_bhy != NULL, "BHY init failed");

    printk("BHY initialized\n");
    delay_ms(500);
    /* ---- Perform I2C read test ---- */
    bhi160b_i2c_test();
    delay_ms(500);

    /* Initialize IMU Sensor */
	IMU_Initialization(&i2c_inst);
    
    delay_ms(10);
    /* ---- Main loop ---- */
    while (1) {
        int8_t result;
        //button_value = gpio_pin_get_dt(&bhi160b_int); //nrf_gpio_pin_read(CUSTOM_BUTTON);
	    while((!gpio_pin_get_dt(&bhi160b_int)==0) && !(bytes_remaining))
        {}

        IMU_read_fifo(&i2c_inst, fifo + bytes_left_in_fifo, FIFO_SIZE - bytes_left_in_fifo, &bytes_read, &bytes_remaining);
        bytes_read      += bytes_left_in_fifo;
        fifoptr         = fifo;
        bhi_packet_type = BHY_DATA_TYPE_VECTOR;// BHY_DATA_TYPE_PADDING;
        do
        {
            result = IMU_parse_next_fifo_packet(&fifoptr, &bytes_read, &fifo_packet, &bhi_packet_type);
        }
        while ((result == BHY_SUCCESS) && (bytes_read > (bytes_remaining ? MAX_PACKET_LENGTH : 0)));
        bytes_left_in_fifo = 0;
        if (bytes_remaining)
        {
            /* shifts the remaining bytes to the beginning of the buffer */
            while (bytes_left_in_fifo < bytes_read)
            {
                fifo[bytes_left_in_fifo++] = *(fifoptr++);
            }
        }
        }

        return 0;
}


3. please go through the attached output image of Sl#2 code.

4. I am using below print for data reading but in Sl#3 I did not observe as expected.

printk("Roll %2.2f, Pitch %2.2f, Yaw %2.2f\n", euler1[ROLL], euler1[PITCH], euler1[YAW]);
Parents Reply Children
No Data
Related