Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    BHI160 sends no data

    BHI160 sends no data

    lkamp
    Member

    Hello,

    I am trying to get a BHI160 working with a STM32 microcontroller. My code is based on the sample code in the GitHub repository. I have attached my code at the bottom of this post.

    Communicating with the chip seems to work fine. bhy_driver_init() returns 0. However, the INT pin never changes, so my code is stuck in the loops that wait for an edge on INT. If I remove the loops and start reading FIFO data right away, no data is received. I expect an initialization meta message and the sensor data from the accelerometer, but data_read is always 0.

     

    int ret;
    
    uint8_t fifo[100];
    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;
    
    if(bhy_driver_init(bhy1_fw)) {
        return EB_ERROR;
    }
    
    while(HAL_GPIO_ReadPin(INT_BHI_GPIO_Port, INT_BHI_Pin) == GPIO_PIN_SET) ;
    while(HAL_GPIO_ReadPin(INT_BHI_GPIO_Port, INT_BHI_Pin) == GPIO_PIN_RESET) ;
    
    ret = bhy_enable_virtual_sensor(VS_TYPE_ACCELEROMETER, VS_WAKEUP, 10, 0, VS_FLUSH_NONE, 0, 0);
    
    while(1) {
        ret = bhy_read_fifo(fifo + bytes_left_in_fifo, 100 - 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 */
            ret = bhy_parse_next_fifo_packet(&fifoptr, &bytes_read, &fifo_packet, &packet_type);
    
            /* 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 ((ret == BHY_SUCCESS) && (bytes_read > (bytes_remaining ? 18 : 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++);
            }
        }
    }
    8 REPLIES 8

    Again this enforces my initial hypothesis of an init failure. It may sound stupid, but did you forget the pull-up resistors on the auxiliary interface ? BHI160 uses I2C for internal communication, but lacks the built-in pull-ups. External pull-up resistors are mandatory.

    If you connect your oscilloscope to the secondary i2c bus, are you able to log the bus activity and post it here ?

    It indeed appears that the resistors on the auxiliary interface are missing. I will check with my colleague how this can be fixed and will report back if the problem is solved.

    Was the missing pull-ups the issue?  I'm facing similar symptoms and we also forgot to add them to our board.

    EDIT: Adding the pullups fixed our problem.

    belaya
    Established Member

    Did someone of you have an example code with a modified driver code including STM32 devices using HAL library?

    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