Bosch Sensortec Community

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

    Unable to read acceleration of BMA456

    Unable to read acceleration of BMA456

    sat3_3
    Member

    Hi,

    I want to read only the raw sensor values, but it doesn't work. I'm using an 8-bit MCU, so I'd like to read data with the minimum configuration. It seems possible according to the topics below, but could you please tell me what I am missing?

    https://community.bosch-sensortec.com/t5/MEMS-sensors-forum/BMA456-without-configuration-file/td-p/5...

    chip_ID is being read correctly.

     

    #define BMA4_ACC_X_LOW                            UINT8_C(0x12)
    #define BMA4_ACC_X_HIGH                           UINT8_C(0x13)
    
    uint8_t data, status = 0;
    
    i2c_single_byte_write(BMA4_I2C_ADDR_PRIMARY, BMA4_POWER_CONF_ADDR, 0x00);
    delay_ms(1);
    
    i2c_single_byte_write(BMA4_I2C_ADDR_PRIMARY, BMA4_POWER_CTRL_ADDR, 0x04);
    delay_ms(500);
    
    status = i2c_single_byte_read(BMA4_I2C_ADDR_PRIMARY, BMA4_STATUS_ADDR); // read status = 0x90
    data = i2c_single_byte_read(BMA4_I2C_ADDR_PRIMARY, BMA4_ACC_X_LOW); // read data = 0x00

     

    3 REPLIES 3

    BSTRobin
    Community Moderator
    Community Moderator

    Hi sat3_3,

    Thanks for your inquiry.
    We conducted tests, BMA456 can read data from registers without loading configuration file.
    I have attached an example on STM32 32-bit MCU for your reference.

    void run_without_config_file(void)
    {
    int8_t rslt;
    uint8_t reg_data, command_reg, status;
    uint8_t data[BMA4_ACCEL_DATA_LENGTH] = { 0 };
    uint16_t lsb = 0, msb = 0;
    int16_t x, y, z;
    uint8_t bma456_i2c_addr;

    bma456_i2c_addr = BMA4_I2C_ADDR_SECONDARY;
    SensorAPI_I2Cx_Read(BMA4_CHIP_ID_ADDR, &reg_data, 1, &bma456_i2c_addr);
    PDEBUG("Chip ID:0x%02x\r\n", reg_data);

    command_reg = 0xB6;
    SensorAPI_I2Cx_Write(BMA4_CMD_ADDR, &command_reg, 1, &bma456_i2c_addr);
    HAL_Delay(100);

    bma456_i2c_addr = BMA4_I2C_ADDR_SECONDARY;
    SensorAPI_I2Cx_Read(BMA4_CHIP_ID_ADDR, &reg_data, 1, &bma456_i2c_addr);
    PDEBUG("Chip ID:0x%02x\r\n", reg_data);

    reg_data = 0;
    SensorAPI_I2Cx_Write(BMA4_POWER_CONF_ADDR, &reg_data, 1, &bma456_i2c_addr);
    bst_delay_us(450,NULL);

    reg_data = 0x04;
    SensorAPI_I2Cx_Write(BMA4_POWER_CTRL_ADDR, &reg_data, 1, &bma456_i2c_addr);
    bst_delay_us(2,NULL);

    SensorAPI_I2Cx_Read(BMA4_STATUS_ADDR, &reg_data, 1, &bma456_i2c_addr);
    PDEBUG("Status:0x%02x\r\n", reg_data);

    for(int i=0;i<100;i++)
    {
    SensorAPI_I2Cx_Read(BMA4_DATA_8_ADDR, data, BMA4_ACCEL_DATA_LENGTH, &bma456_i2c_addr);
    msb = data[1];
    lsb = data[0];

    /* Accel data x axis */
    x = (int16_t)((msb << 😎 | lsb);
    msb = data[3];
    lsb = data[2];

    /* Accel data y axis */
    y = (int16_t)((msb << 😎 | lsb);
    msb = data[5];
    lsb = data[4];

    /* Accel data z axis */
    z = (int16_t)((msb << 😎 | lsb);

    PDEBUG("data X: %d, Y: %d, Z: %d\r\n", x, y, z);
    HAL_Delay(500);
    }
    }

    test log.png

     

     

    Hi BSTRobin,

    Thank you for your support.

    I tried implementing it based on the sample code you provided, but it didn't work. The sample code uses BMA4_I2C_ADDR_SECONDARY, but will it work with PRIMARY as well? I would like to receive any other advice.

    I suspected a malfunction and tried other chips, but the result was the same. I have attached the circuit diagram. Could you also check the problem with the circuit?

     

        uint8_t reg_data, command_reg, status;
        uint8_t data[BMA4_ACCEL_DATA_LENGTH] = { 0 };
        uint16_t lsb = 0, msb = 0;
        int16_t x, y, z;
        int8_t addr = BMA4_I2C_ADDR_PRIMARY;
    
        reg_data = i2c_single_byte_read(addr, BMA4_CHIP_ID_ADDR);
        DebugPrint("CHIP ID: %x\r\n", reg_data);
    
        i2c_single_byte_write(addr , BMA4_CMD_ADDR, 0xB6);
        delay_ms(100);
    
        reg_data = i2c_single_byte_read(addr, BMA4_CHIP_ID_ADDR);
        DebugPrint("CHIP ID: %x\r\n", reg_data);
    
        i2c_single_byte_write(addr , BMA4_POWER_CONF_ADDR, 0x00);
        delay_us(450);
        i2c_single_byte_write(addr , BMA4_POWER_CTRL_ADDR, 0x04);
        delay_us(2);
    
        reg_data = i2c_single_byte_read(addr, BMA4_STATUS_ADDR);
        DebugPrint("STATUS: %x\r\n", reg_data);
        delay_ms(500);
    
        while(1){
            data[0] = i2c_single_byte_read(addr, BMA4_ACC_X_LOW);
            data[1] = i2c_single_byte_read(addr, BMA4_ACC_X_HIGH);
            data[2] = i2c_single_byte_read(addr, BMA4_ACC_Y_LOW);
            data[3] = i2c_single_byte_read(addr, BMA4_ACC_Y_HIGH);
            data[4] = i2c_single_byte_read(addr, BMA4_ACC_Z_LOW);
            data[5] = i2c_single_byte_read(addr, BMA4_ACC_Z_HIGH);
    
            msb = data[1];
    	lsb = data[0];
    
    	/* Accel data x axis */
    	x = (int16_t)((msb <<  | lsb);
    	msb = data[3];
    	lsb = data[2];
         
            /* Accel data y axis */
    	y = (int16_t)((msb <<  | lsb);
    	msb = data[5];
    	lsb = data[4];
    
    	/* Accel data z axis */
    	z = (int16_t)((msb <<  | lsb);
    
    	DebugPrint("data X: %d, Y: %d, Z: %d\r\n", x, y, z);
    	delay_ms(500);
        }

     

     

     

    image.pngschematicschematic

    There was a problem with the I2C library we were using. We fixed it and confirmed that BMA456 works properly.

    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