Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    BHI160B initialization issue BHY_META_EVENT_TYPE_ERROR()

    BHI160B initialization issue BHY_META_EVENT_TYPE_ERROR()

    robinpipers
    Member

    Hi,
    So I am trying to get my bhi160b to work and stream accelerometer data connected to a stm32f7 via i2c.

    Here I have used some of the example code:

    Together with the following firmware: Bosch_PCB_7183_di03_BMI160-7183_di03.2.1.11696_170103.h

    void demo_sensor(void)
    {
        int8_t ret;
    
        /* BHY Variable*/
        uint8_t                    *fifoptr           = NULL;
        uint8_t                    bytes_left_in_fifo = 0;
        uint16_t                   bytes_remaining    = 0;
        uint16_t                   bytes_read         = 0;
        bhy_data_generic_t         fifo_packet;
        bhy_data_type_t            packet_type;
        BHY_RETURN_FUNCTION_TYPE   result;
    
        /* To get the customized version number in firmware, it is necessary to read Parameter Page 2, index 125 */
        /* to get this information. This feature is only supported for customized firmware. To get this customized */
        /* firmware, you need to contact your local FAE of Bosch Sensortec. */
        //struct cus_version_t      bhy_cus_version;
    
        BHY_RETURN_FUNCTION_TYPE com_rslt = BHY_COMM_RES;
        uint8_t data[1] = {1};
        com_rslt = bhy_write_reg(BHY_I2C_REG_RESET_REQUEST_ADDR, data, sizeof(data));
        while (!bhi160b_get_int_status());
        osDelay(5000);
        
        // bhy_install_meta_event_callback(BHY_META_EVENT_TYPE_ERROR, meta_event_callback);
        // bhy_install_meta_event_callback(BHY_META_EVENT_TYPE_SENSOR_ERROR, meta_event_callback);
        bhy_install_meta_event_callback(BHY_META_EVENT_TYPE_INITIALIZED, meta_event_callback);
        bhy_install_meta_event_callback(BHY_META_EVENT_TYPE_SELF_TEST_RESULTS, meta_event_callback);
        bhy_install_sensor_callback(VS_ID_CUS1, VS_WAKEUP, sensors_callback);
        // PDEBUG("version=%s, %s, %s\n", bhy_get_version(), __DATE__, __TIME__);
        // PDEBUG("start example\n");
    
        /* init the bhy chip */
        if(bhy_driver_init(bhy1_fw))
        {
            PDEBUG("Fail to init bhy\n");
        }
    
        /* wait for the bhy trigger the interrupt pin go down and up again */
        while(bhi160b_get_int_status());
        while(!bhi160b_get_int_status());
    
        /* To get the customized version number in firmware, it is necessary to read Parameter Page 2, index 125 */
        /* to get this information. This feature is only supported for customized firmware. To get this customized */
        /* firmware, you need to contact your local FAE of Bosch Sensortec. */
        //bhy_read_parameter_page(BHY_PAGE_2, PAGE2_CUS_FIRMWARE_VERSION, (uint8_t*)&bhy_cus_version, sizeof(struct cus_version_t));
        //PDEBUG("cus version base:%d major:%d minor:%d\n", bhy_cus_version.base, bhy_cus_version.major, bhy_cus_version.minor);
    
        struct accel_physical_status_t phy_acc;
        struct gyro_physical_status_t phy_gyro;
        struct mag_physical_status_t phy_mag;
        uint8_t physical_sensor_present_bitmap[8];
        uint32_t                   i                  = 0;
        struct sensor_information_non_wakeup_t sensor_info_non_wakeup;
        struct sensor_information_wakeup_t sensor_info_wakeup;
      
        /* get physical sensor present from sensor hub */
        bhy_read_parameter_page(BHY_PAGE_1, BHY_PARAM_SYSTEM_PHYSICAL_SENSOR_PRESENT, &physical_sensor_present_bitmap[0], 8);
        PDEBUG("Physical Sensor Present:\n");
        for(i = 0; i < 8; i++)
        {
          PDEBUG("bitmap[%d] = 0x%x\n", i, physical_sensor_present_bitmap[i]);
          PDEBUG("");
        }
    
        /* get physical sensor status from sensor hub */
        bhy_get_physical_sensor_status(&phy_acc, &phy_gyro, &phy_mag);
    
          /*	Physical Sensor Status:
        Flags[bit 0]:  interrupt enable
        Flags[bits 5-7]: Sensor Power Mode values:
        0: Sensor Not Present
        1: Power Down
        2: Suspend
        3: Self-Test
        4: Interrupt Motion
        5: One Shot
        6: Low Power Active
        7: Active
        */
        PDEBUG("Physical Sensor Status:\n");
        PDEBUG("Acc : sample rate %d, range %d, int %d pwr %d\n",\
        phy_acc.accel_sample_rate, phy_acc.accel_dynamic_range, phy_acc.accel_flag & 0x01, (phy_acc.accel_flag & 0xE0) >> 5);
        PDEBUG("Gyro: sample rate %d, range %d, int %d pwr %d\n", \
        phy_gyro.gyro_sample_rate, phy_gyro.gyro_dynamic_range, phy_gyro.gyro_flag & 0x01, (phy_gyro.gyro_flag & 0xE0) >> 5);
        PDEBUG("Mag : sample rate %d, range %d, int %d pwr %d\n", \
        phy_mag.mag_sample_rate, phy_mag.mag_dynamic_range, phy_mag.mag_flag & 0x01, (phy_mag.mag_flag & 0xE0) >> 5);
        PDEBUG("");
    
        /* read custom sensor event size from hub for later fifo parse */
        bhy_sync_cus_evt_size();
    
        PDEBUG("cus evt size = %d %d %d %d %d\n", bhy_get_cus_evt_size(VS_ID_CUS1), bhy_get_cus_evt_size(VS_ID_CUS2), \
        bhy_get_cus_evt_size(VS_ID_CUS3), bhy_get_cus_evt_size(VS_ID_CUS4), \
        bhy_get_cus_evt_size(VS_ID_CUS5));
    
    
        /* get virtual sensor information from sensor hub */
        PDEBUG("Supported Virtual Sensor Information:\n");
        for(i = 1; i < 32; i++)
        {
          bhy_get_wakeup_sensor_information(i, &sensor_info_wakeup);
    
          if(sensor_info_wakeup.wakeup_sensor_type == i)
          PDEBUG("id=%2d\n", i);
        }
    
        for(i = 33; i < 64; i++)
        {
          bhy_get_non_wakeup_sensor_information(i, &sensor_info_non_wakeup);
    
          if(sensor_info_non_wakeup.non_wakeup_sensor_type == i)
          PDEBUG("id=%2d\n", i);
        }
        PDEBUG("");
    
        
        bool shouldSelftest = false;
        if (shouldSelftest) {
          bhy_set_chip_control(0);
          bhy_set_host_interface_control(BHY_HOST_SELFTEST, ENABLE);
          osDelay(100);
          
          bhy_set_chip_control(1);
          osDelay(100);
        } else {
          bhy_enable_virtual_sensor(VS_ID_CUS1, VS_WAKEUP, 5, 0, VS_FLUSH_NONE, 0, 0);
        }
    	
        while(1)
        {
            osDelay(1);
            /* wait until the interrupt fires */
            /* unless we already know there are bytes remaining in the fifo */
            while (!bhi160b_get_int_status() && !bytes_remaining);
    
            bhy_read_fifo(fifo + bytes_left_in_fifo, FIFO_SIZE - bytes_left_in_fifo, &bytes_read, &bytes_remaining);
            bytes_read           += bytes_left_in_fifo;
            fifoptr              = fifo;
            packet_type          = BHY_DATA_TYPE_PADDING;
    
            do
            {
                /* this function will call callbacks that are registered */
                result = bhy_parse_next_fifo_packet(&fifoptr, &bytes_read, &fifo_packet, &packet_type);
    
                /* prints all the debug packets */
                if (packet_type == BHY_DATA_TYPE_PADDING)
                {
                  /* padding data only added at the end of each FIFO dump, discard it. */
                  PDEBUG(">Padding\n");
                }
                else if (packet_type == BHY_DATA_TYPE_DEBUG)
                {
                  PDEBUG(">DebugString       :");
                  bhy_print_debug_packet(&fifo_packet.data_debug, bhy_printf);
                  PDEBUG("\n");
                }
                
                /* the logic here is that if doing a partial parsing of the fifo, then we should not parse  */
                /* the last 18 bytes (max length of a packet) so that we don't try to parse an incomplete   */
                /* packet */
            } 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++);
                }
            }
        }
    }

     
    Callback:

    static void meta_event_callback(bhy_data_meta_event_t *event_data, bhy_meta_event_type_t event_type)
    {
    
        PDEBUG(">Meta event type %d,  \n", event_type);
    
        switch(event_type)
        {
            case BHY_META_EVENT_TYPE_INITIALIZED:
                PDEBUG("initialize success!\n");
                break;
            case BHY_META_EVENT_TYPE_SELF_TEST_RESULTS:
                if(event_data->event_specific == BHY_SUCCESS)
                {
                    PDEBUG("self test result success!  sensor_type=%d \n", event_data->sensor_type);
                }
                else
                {
                    PDEBUG("self test result fail!  sensor_type=%d  \n", event_data->sensor_type);
                }
                break;
            case BHY_META_EVENT_TYPE_ERROR:
            {
              PDEBUG("error meta event\n");
            }
            break;
            default:
                PDEBUG("unknown meta event\n");
                break;
        }
    }

    However this causes BHY_META_EVENT_TYPE_ERROR once entering the meta_callback after first time processing fifo.
    There are no more events following that event. neither sensor or meta callback.

    And the code snippet bellow shows that the flags for phy_acc is 0x20. which means suspended mode, is there any way to take it out of suspended?

        /* get physical sensor status from sensor hub */
        bhy_get_physical_sensor_status(&phy_acc, &phy_gyro, &phy_mag);


    Attached my hw schematics.

    robinpipers_0-1648405880869.png

     

     

    10 REPLIES 10

    BSTRobin
    Community Moderator
    Community Moderator

    Hi robinpipers,

    Did your sensor initialize successfully?

    I Tried adding your code to the previous example I showed as well. Driver Init if case is successful but no streaming seems to start. Or events generated.

    Is it good to run a reset before the init? Any special order? Waiting etc? My board has fixed 3.3v to imu.

    I think I am using the GitHub bhy1 example with the bmi150 as stated above.

    BSTRobin
    Community Moderator
    Community Moderator

    Hi robinpipers,

    Previous code works well on my side, this is the log:

    acc log.png

    I upload all the code, please run it.

    robinpipers_0-1648844906123.png

    Getting init fail sometimes.. pulled and plugged power again and restarted debug session. and it stops after id 63.

    BHI160B library files?

    also tried starting with 2x2 cus fw

    result

    robinpipers_0-1648847411780.png

     

    Found the issue.

    Thanks for all the help BST Robin.

    The issue is that I have forgotten the pull ups on the ASDK, ASDA pins. Did not read the datasheets carefull enough. I stumbled uppon this yesterday evening when browsing the forums.

    Here is the current output. after doing a patch job to the pcb where I have solder wires to the ASDA and ASDK pins(yes this is possible with microscope and some patience. I melted away a little hole on the side to the pad and then used a road runner and carefully connected the legs. Then routed them to their respective 4.7kohm resistor connected to 3.3v)

    robinpipers_0-1648971244718.png

    New schematics:

    robinpipers_1-1648971321542.png


    Datasheet

    robinpipers_2-1648971351132.png

     

    Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist