Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    BMA456 test communication error

    BMA456 test communication error

    Bullseye
    New Poster

    Hello all!

    I am working with the BMA456 sensor, connected to an STM32F411RE nucleo card.

    I am still learning how to work with the sensor, therefore I decided to play by the book and follow the datasheet's instructions beginning with the test communication. (BMA PDF Datasheet – Page 11 – bma ds.png)

    I am also using the STM32CubeIDE.

    My code:

    #include "stm32f4xx_hal.h"

    #define BMA456_I2C_ADDRESS 0x19
    #define BMA456_CHIP_ID_REG 0x00
    #define BMA456_CHIP_ID_VAL 0x16

    I2C_HandleTypeDef hi2c1; 

    uint8_t BMA456_ReadChipID() {
    uint8_t chip_id = 0;
    HAL_StatusTypeDef status = HAL_I2C_Mem_Read(&hi2c1, BMA456_I2C_ADDRESS, BMA456_CHIP_ID_REG, I2C_MEMADD_SIZE_8BIT, &chip_id, 1, 1000);

    if (status != HAL_OK) {
    // Handle error here
    return 0;
    }
    return chip_id;
    }

    int main() {
    // ...

    uint8_t chip_id = BMA456_ReadChipID();

    if (chip_id == BMA456_CHIP_ID_VAL) {
    // Communication is OK
    } else {
    // Communication is not OK
    }

    // ...
    }

    After debugging a little, I found that I am receiving the error code "4". The code that I provided is of course only the piece related to the bma456 sensor. If you need the rest of my main.c code, you can find it in the attachements.

    I  would really appreciate the help, thanks a lot!

    3 REPLIES 3

    BSTRobin
    Community Moderator
    Community Moderator

    Hi Bullseye,

    I uploaed BMA456 example code on STM32F401 for your reference. Sensor API, you could use the version on github https://github.com/boschsensortec/BMA456-Sensor-API

    Hello!

    Thanks a lot for the quick response. I will try this out and get back to you with the results.

    Have a great day ahead.

    Edit: Having quickly looked at the files that you have provided, and considering that I am still somewhat a beginner in what regarding working with the BMA sensor. Could you help me understand how does your code work? There are a lot of definitions and functions especially in the bma456h_task files.

    Thanks again!

    BSTRobin
    Community Moderator
    Community Moderator

    Hi Bullseye,

    Welcome.
    The entry function is StartBMA456HTask() in bma456h_task.c file. The reference code run with STM32F401, you don't need to modify any code in bma456h_task.c as you used STM32F411RE which was also same STM32F4 series. You only need to ensure you configure currect I2C interface on STM32F411RE side.

    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