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
... View more