Bosch Sensortec Community

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

    BMA456 Simple read of Acceleration Values

    BMA456 Simple read of Acceleration Values

    HBUDE
    Member

    Hello,

    we are using BMA456, connected to a uC via SPI Interface.

    In first step, I simply want to read the acceleration data registers, and I wrote a small program according to the steps described in "Example 2" of the data sheet.

    But the readout of the registers is always Zero.

    What am I doing wrong, resp. what do I have to do to make it work ? Is there any further initialisation/configuration necessary ? If so, does anybody have a code example for this ?

    I downloaded the driver API, but there is a lot of code inside which I do not (yet) understand.

    I searched the net carefully, but could not find any help or information....

    Thanks in advance, bye

    Harald

    8 REPLIES 8

    Hello again,

    I migrated the acceleration example project to my hardware, but unfortunately it does not work correctly...

    I can see that in lines 921+922 of module bma4.c:

     rslt = bma4_read_regs(BMA4_INTERNAL_STAT, &config_stream_status, 1, dev);
    config_stream_status = config_stream_status & BMA4_CONFIG_STREAM_MESSAGE_MSK;

    the content of variable config_stream_status is 0 after execution of function bma4_read_regs(...). This seems to signal an error.

    Sorry, but I do not exactly understand what this function does, but I believe it could be a problem of my implementation of functions user_spi_read(...) and

    user_spi_write(...).

    I implemented the following code by use of HAL SPI functions. Could you please check if there is something wrong ?

    I assume the code in user_spi_write() is possibly not correct. On call of the function I first transmit one byte of adress data, after the register data with given length. Is that okay ?!

    /*!
    * @brief Function for writing the sensor's registers through SPI bus.
    */
    int8_t user_spi_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr)
    {

    /* Implement the SPI write routine according to the target machine. */

    HAL_GPIO_WritePin(SPI2_ACC_NSS_GPIO_Port,SPI2_ACC_NSS_Pin,GPIO_PIN_RESET); // NSS Pin = Low

    HAL_SPI_Transmit(&hspi2,&reg_addr,1,100); // Transmit Register Adress
    HAL_SPI_Transmit(&hspi2,(uint8_t *)reg_data,length,100); // Transmit Data

    HAL_GPIO_WritePin(SPI2_ACC_NSS_GPIO_Port,SPI2_ACC_NSS_Pin,GPIO_PIN_SET); // NSS Pin = High

    return 0;
    }

    /*!
    * @brief Function for reading the sensor's registers through SPI bus.
    */

    int8_t user_spi_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, void *intf_ptr)
    {

    /* Implement the SPI read routine according to the target machine. */

    HAL_GPIO_WritePin(SPI2_ACC_NSS_GPIO_Port,SPI2_ACC_NSS_Pin,GPIO_PIN_RESET); // NSS Pin = Low

    HAL_SPI_TransmitReceive(&hspi2,&reg_addr,reg_data,length,100);

    HAL_GPIO_WritePin(SPI2_ACC_NSS_GPIO_Port,SPI2_ACC_NSS_Pin,GPIO_PIN_SET); // NSS Pin = High

    return 0;
    }

     

    Thank you in advance, kind regards

    Harald


     

    Hello again,

    it's okay now, I found the problem. The use of HAL_SPI_TransmitReceive in function user_spi_read() was wrong. I replaced it by

    HAL_SPI_Transmit(&hspi2,&reg_addr,1,100); // Transmit Register Adress
    HAL_SPI_Receive(&hspi2,reg_data,length,100); // Receive Register Data

    and now it works....it seems, the second dummy write byte of adress transfer is included in the receive data length, or not ?

    However, now it works and that's great 🙂

    Thanks a lot for your assistance

    Harald

     

    BSTRobin
    Community Moderator
    Community Moderator

    Hello HBUDE,

    HAL_SPI_TransmitReceive() also could work. You could refer example code I uploaded in another ticket: https://community.bosch-sensortec.com/t5/MEMS-sensors-forum/BMA456-Init-fail/m-p/47081#M8520

    Hello BSTRobin,

    thanks for information. I know it's working, I simply used the wrong data length in this function.

    Thanks again, bye

    Harald

    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