01-05-2021 05:54 AM
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)
;
#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
01-08-2021 07:43 AM
Hi BSTRobin, I will try it and update it here today evening. Thanks for the reply
01-20-2021 07:29 AM
Hello nafihahmd,
By the way, did it work normally?
01-21-2021 08:52 AM
No it didn't
05-08-2021 05:02 AM
Hello nafihahmd,
We know a little about Arduino platform. Could you capture I2C waveform with a logic analyzer?