05-21-2024 12:19 PM - edited 05-22-2024 06:58 AM
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?
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
Solved! Go to Solution.
05-23-2024 11:32 AM - edited 05-23-2024 11:45 AM
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, ®_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, ®_data, 1, &bma456_i2c_addr);
PDEBUG("Chip ID:0x%02x\r\n", reg_data);
reg_data = 0;
SensorAPI_I2Cx_Write(BMA4_POWER_CONF_ADDR, ®_data, 1, &bma456_i2c_addr);
bst_delay_us(450,NULL);
reg_data = 0x04;
SensorAPI_I2Cx_Write(BMA4_POWER_CTRL_ADDR, ®_data, 1, &bma456_i2c_addr);
bst_delay_us(2,NULL);
SensorAPI_I2Cx_Read(BMA4_STATUS_ADDR, ®_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);
}
}
05-24-2024 03:22 AM - edited 05-24-2024 03:51 AM
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);
}
schematic
06-17-2024 08:10 AM
There was a problem with the I2C library we were using. We fixed it and confirmed that BMA456 works properly.