Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    BMA456 Fails after initialization

    BMA456 Fails after initialization

    nafihahmd
    Member

    Hi, First of all let me admit that I am a newbie in embedded firmware. I am trying to write a code for BMA456 using ESP32 and Arduino platform(PlatformIO). I am using latest version of BMA456 Sensor API from the official repo. I am able to read the chip ID (0x16) correctly. But when I try to execute the further steps it's failing. The BMA456 seems to get hang at 

     

     

     while (Wire.available() < len) 
        ;

     

     
    Also I tried to read the status register at 0x2A  and got a value 0b11111 which is not even defined in the datasheet.
    I will attach my code below.
     
    P.S: I also tried arduino portred library from Seed studio. The link is here. I tried their step counter example and the steps never incremented. 
     
     Main.cpp

     

     

    #include <Arduino.h>
    #include "bma456.h"
    #include "bma4_common.h"
    
    
    //  Function Declaration
    uint16_t init_BMA();
    uint16_t config_acc();
    
    // Global Variables
    struct bma4_dev bma_global; // Declare an instance of the BMA456 device
    uint16_t rslt = BMA4_OK;
    uint8_t init_seq_status;
    uint16_t int_status;         // Variable to store accel data ready interrupt status
    struct bma4_accel_config accel_conf = {0};
    
    void setup()
    {
      Serial.begin(115200);
      Serial.println("\n BMA456");
      
      init_BMA();
      //config_acc();
    
      delay(150);
    }
    
    void loop()
    {
      // read_acc();
    }
    
    uint16_t init_BMA()
    {
      Wire.begin();
    
      // Modify Params
      // bma.dev_addr = BMA4_I2C_ADDR_PRIMARY;
      struct bma4_dev bma; // Declare an instance of the BMA456 device
      bma.intf = BMA4_I2C_INTF;
      bma.bus_read = usr_i2c_r;
      bma.bus_write = usr_i2c_w;
      bma.delay_us = usr_delay;
      bma.read_write_len = 8;
      bma.resolution = 12;
      bma.feature_len = BMA456_FEATURE_SIZE;
    
      /* a. Reading the chip id. */
      uint16_t rslt = BMA4_OK;
      rslt |= bma456_init(&bma);
      Serial.println("tst_pnt1");
      Serial.println(rslt, HEX);
      bma4_error_codes_print_result("bma456_init status", rslt);
      bma4_set_command_register(0xB6, &bma); // reset device  
      Serial.println("tst_pnt2");
      delay(500);
    
      /* b. Performing initialization sequence. 
           c. Checking the correct status of the initialization sequence.
        */
    
      rslt |= bma456_write_config_file(&bma);
      Serial.println(rslt);
      bma4_error_codes_print_result("bma456_write_config status", rslt);
      Serial.println("tst_pnt3");
    
      bma_global = bma;
      return rslt;
    }
    
    uint16_t config_acc()
    {
      struct bma4_dev bma; // Declare an instance of the BMA456 device
      bma = bma_global;
      bma4_set_accel_enable(BMA4_ENABLE, &bma);
      bma4_error_codes_print_result("bma4_set_accel_enable status", rslt);
    
      /* Assign the desired settings */
      accel_conf.odr = BMA4_OUTPUT_DATA_RATE_100HZ;
      accel_conf.range = BMA4_ACCEL_RANGE_2G;
      accel_conf.bandwidth = BMA4_ACCEL_NORMAL_AVG4;
    
      /* Set the configuration */
      rslt |= bma4_set_accel_config(&accel_conf, &bma);
      bma_global = bma;
      return rslt;
    }

     

     

     

    i2c_read functipon

     

     

    int8_t usr_i2c_r(uint8_t reg_addr, uint8_t *read_data, uint32_t len, void *intf_ptr)
    {
      Wire.beginTransmission(dev_addr);
      Wire.write(reg_addr);
      Wire.endTransmission(false);
    
      Wire.requestFrom(dev_addr, len);
      Serial.println("i2cR/tst_pnt1");
      while (Wire.available() < len) 
        ;
      Serial.println("i2cR/tst_pnt2");
      for (int i = 0; i < len; i++)
      {
        read_data[i++] = Wire.read();
      }
    
      Wire.endTransmission();
      Serial.println("i2cR/tst_pnt3");
    
      return 0;
    }

     

     

     

    P.S 2: I am using the Serial.print() for debugging

    8 REPLIES 8

    Hi BSTRobin, I will try it and update it here today evening. Thanks for the reply

     

    BSTRobin
    Community Moderator
    Community Moderator

    Hello nafihahmd,

    By the way, did it work normally?

    No it didn't

    BSTRobin
    Community Moderator
    Community Moderator

    Hello nafihahmd,

    We know a little about Arduino platform. Could you capture I2C waveform with a logic analyzer?

    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