Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 
    SOLVED

    BHI160b Shuttle Board with STM32

    Vincent
    Community Moderator

    Re: BHI160b Shuttle Board with STM32

    You are currently use HAL_I2C_Master_Transmit + HAL_I2C_Master_Receive to implement  I2C read.

    Can you try to use the following function?

    • HAL_I2C_Mem_Write
    • HAL_I2C_Mem_Read
    belaya
    Established Member

    Re: BHI160b Shuttle Board with STM32

    I debugged  the program and found some issues i want to share, hopefully they help us to find a solution. It still seems like that the bhy_driver_init(&bhy1_fw) is working fine. After that i have this code where i can also find an error return from the Sensor.

    	    bhy_mapping_matrix_set(PHYSICAL_SENSOR_INDEX_ACC, bhy_mapping_matrix_config);
    	    bhy_mapping_matrix_set(PHYSICAL_SENSOR_INDEX_MAG, mag_mapping_matrix_config);
    	    bhy_mapping_matrix_set(PHYSICAL_SENSOR_INDEX_GYRO, bhy_mapping_matrix_config);

    After the Matrix was set up, it tries to write the parameter page to the Sensor with the function bhy_write_parameter_page(). Within this function it selects the parameter and reads the acknowledgments.

    BHY_RETURN_FUNCTION_TYPE bhy_write_parameter_page(uint8_t page, uint8_t parameter, uint8_t *data, uint8_t length)
    {
        /* variable used for return the status of communication result */
        BHY_RETURN_FUNCTION_TYPE com_rslt = BHY_COMM_RES;
    
        uint8_t v_parameter_ack = BHY_INIT_VALUE;
        uint8_t v_parameter_ack_check = BHY_INIT_VALUE;
    
        /* write values to the load address*/
        if (length > MAX_WRITE_BYTES)
        {
            length = MAX_WRITE_BYTES;
        }
        else if (length == 0)
        {
            return BHY_SUCCESS;
        }
    
        com_rslt = bhy_write_reg(BHY_I2C_REG_PARAMETER_WRITE_BUFFER_ZERO, data, length);
    
        /* select the page*/
        if (page > MAX_PAGE_NUM)
        {
            page = MAX_PAGE_NUM;
        }
        else if (page == 0)
        {
            return BHY_SUCCESS;
        }
    
        page = ((length & 0x07) << 4) | page;
        com_rslt += bhy_write_reg(BHY_I2C_REG_PARAMETER_PAGE_SELECT__REG, &page, 1);
    
        /* select the parameter*/
        parameter |= 0x80;
        com_rslt += bhy_set_parameter_request(parameter);
        for (v_parameter_ack_check = BHY_INIT_VALUE;
            v_parameter_ack_check < BHY_PARAMETER_ACK_LENGTH;
            v_parameter_ack_check++)
        {
            /* read the acknowledgment*/
            com_rslt += bhy_get_parameter_acknowledge(&v_parameter_ack);
            if (v_parameter_ack == parameter)
            {
                com_rslt += BHY_SUCCESS;
                break;
            }
            else if (v_parameter_ack == BHY_PARAMETER_ACK_CHECK)
            {
                bhy_delay_msec(BHY_PARAMETER_ACK_DELAY);
                com_rslt += BHY_ERROR;
            }
            else
            {
                /* device not ready yet */
                bhy_delay_msec(1);
            }
        }
        return com_rslt;
    }

    But when it reads the acknowledgments it alwas ends up in an error executing this line com_rslt += BHY_ERROR; . This is the same for all three matrix mapping functions.

    I am facing the same problem with the function bhy_enable_virtual_sensor().  It uses the function bhy_write_parameter_bytes();  which trys to write the parameter bytes to the sensor and check the acknowledgments afterwards. So this Function causes the error which returns -18 for the function bhy_enable_virtual_sensor().

    I guess my write/read operation is still not working properly. i tried to implement the read function with the function HAL_I2C_Mem_Read() like this.

    int8_t sensor_i2c_read(uint8_t slave_address7, uint8_t subaddress, uint8_t *pBuffer, uint16_t ReadNumbr)
    {
    uint16_t DevAddress = slave_address7 << 1;
    HAL_StatusTypeDef status = HAL_OK;
    
    status = HAL_I2C_Mem_Read(&hi2c1, DevAddress, (uint16_t)subaddress, I2C_MEMADD_SIZE_8BIT, pBuffer, ReadNumbr, HAL_MAX_DELAY);
    if(status != HAL_OK)
    {
    	HAL_Delay(1);
    }
    return 0;
    }

    With my logic analyzer i created a capture file of my i2c transactions, hopefully you can see anything in there.

    CarlyAzuma
    Occasional Visitor

    Re: BHI160b Shuttle Board with STM32

    Hello...Which microcontroller you should buy very much depends on what you are trying to do with it.Do you actually need a 180MHz M4 with LCD and SDRAM controller?If you don't need a lot of processing power your may also want to consider the less complex Cortex M0+ products. (eg. STM32L0, ATSAMD21, LPC8xx etc)

    ST, Atmel and NXP all have cheap and readily available eval boards and software tools available.

    Vincent
    Community Moderator

    Re: BHI160b Shuttle Board with STM32

    When reading your log,  i found one thing,  each write function,  you write one more byte as expect. 

    For example, for the bhy reset function,  we need to write 0x01 to register 0x9B.  But actually in your log,  you write 01, 00 to the sensor.  

    Here it will not impact the result since reset will take effect from the first byte written into sensor.

    But when we call write parameter page,  the parameter page only accept 8 bytes,  and you are trying to write 9 bytes.  

    Can you try to look into this first? 

    Vincent
    Community Moderator

    Re: BHI160b Shuttle Board with STM32

    Pls try this. It works well on my side.

    int8_t sensor_i2c_write(uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t size)
    {
    if(HAL_I2C_Mem_Write(&hi2c1,(uint16_t)addr*2,(uint16_t)reg, I2C_MEMADD_SIZE_8BIT, p_buf, size,50))
    return BHY_ERROR;
    else
    return BHY_SUCCESS;
    }

    int8_t sensor_i2c_read(uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t size)
    {
    if(HAL_I2C_Mem_Read(&hi2c1,(uint16_t)addr*2,(uint16_t)reg, I2C_MEMADD_SIZE_8BIT, p_buf, size,50))
    return BHY_ERROR;
    else
    return BHY_SUCCESS;
    }

    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