Bosch Sensortec Community

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

    BHy MACU driver Porting guide

    BHy MACU driver Porting guide

    belaya
    Established Member

    Hello,

    started a new Projekt which contains the Sensordata from the BHI160b. I am using the BHI160 Shuttle Board.  My Microcontroller is an STM32L053R8 which i will use to read out the sensordata. I started to follow the driver Porting guide to adapt the Functions to my Platform. At first i created a New Projekt with my STM32 init code and also included the BHy MCU driver. At the beginning i removed the lines in the file bhy_support.c

    #include "FreeRTOS.h"
    #include "task.h"
    extern int8_t sensor_i2c_write(uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t size);
    extern int8_t sensor_i2c_read(uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t size);
    extern void trace_log(const char *fmt, ...);

    After that i tried build the target Files in i have an error:

    ..\Drivers\BHI160b_driver\inc\BHy_support.h(59): error: #5: cannot open source input file "twi.h": No such file or directory

    Because the twi.h is a platform specific library for Atmel i also removed this line from file bhy_support.h.

    After this change i tried to rebuild again and now i have a lot of undefined identifiers :

    ..\Drivers\BHI160b_driver\inc\bhy_uc_driver_types.h(252): error: #20: identifier "uint8_t" is undefined           uint8_t sensor_id;

    Even the Porting guide says that in this case, the bhy.h should be modified to define the following fixed-width types:

    s8, s16, s32, u8, u16, u32

    I looked in this file and i am not sure how to exactly implement these types. Does anyone have an example for that?

    Also i should implement specific  sensor_i2c_write()  sensor_i2c_read() functions. This 2 functions have to be in bhy_support.c?

    Because there are no existing i2c functions just the declaration like this:

    extern int8_t sensor_i2c_write(uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t size);
    extern int8_t sensor_i2c_read(uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t size);

    Are there any example codes that has an HAL i2c connection to this sensor?

    Thx for helping!

    8 REPLIES 8

    BSTRobin
    Community Moderator
    Community Moderator

    Hello Belaya,

    This is sensor initialization code on STM32, please refer it.

    /*!
    * @brief Initializes BHY smart sensor and its required connections
    *
    */
    int8_t bhy_initialize_support(void)
    {
    uint8_t tmp_retry = RETRY_NUM;

    bhy.bus_write = &I2Cx_Write;
    bhy.bus_read = &I2Cx_Read;
    bhy.delay_msec = &bhy_delay_msec;
    bhy.device_addr = BHY_I2C_SLAVE_ADDRESS<<1;

    bhy_init(&bhy);

    bhy_set_reset_request(BHY_RESET_ENABLE);;

    while(tmp_retry--)
    {
    bhy_get_product_id(&bhy.product_id);

    if(PRODUCT_ID_7183 == bhy.product_id)
    {
    return BHY_SUCCESS;
    }

    bhy_delay_msec(BHY_PARAMETER_ACK_DELAY);
    }

    return BHY_PRODUCT_ID_ERROR;
    }
    /*!
    * @brief Initiates a delay of the length of the argument in milliseconds
    *
    * @param[in] msec Delay length in terms of milliseconds
    *
    */
    void bhy_delay_msec(uint32_t msec)
    {
    HAL_Delay(msec);
    }

    belaya
    Established Member

    Thx, i have the same init code in the driver. Do you have any main.c code that shows how to use this driver? After i initialized all functions of the MCU is called the bhy_initialize_support(); function and it gets successfull the Sensor id. But whats next? the example code in the driver just shows 2 functions, the sensor callback and the demo_sensor. But don't know how to implement these into my main to geht continous readings

    BSTRobin
    Community Moderator
    Community Moderator

    Hello Bellaya,

    There was a porting guide under package folder, you also could refer it.

    Which example code you refer it? For reading data, you could refer FIFO reading example.

    belaya
    Established Member

    Actually i want to read out rotation data as quaternions. So i decided to take the rotation_vector_example.c. I reffered to the documentation for the porting guide. But i dont know how to implement it into my main function to get continous readings. I guess this two functions in the example are reading rotation but i dont know how to use them.....

    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