BMA456 test communication error

Hello all!

I am working with the BMA456 sensor, connected to an STM32F411RE nucleo card.

I am still learning how to work with the sensor, therefore I decided to play by the book and follow the datasheet's instructions beginning with the test communication. (BMA PDF Datasheet – Page 11 – bma ds.png)

I am also using the STM32CubeIDE.

My code:

#include "stm32f4xx_hal.h"

#define BMA456_I2C_ADDRESS 0x19
#define BMA456_CHIP_ID_REG 0x00
#define BMA456_CHIP_ID_VAL 0x16

I2C_HandleTypeDef hi2c1; 

uint8_t BMA456_ReadChipID() {
uint8_t chip_id = 0;
HAL_StatusTypeDef status = HAL_I2C_Mem_Read(&hi2c1, BMA456_I2C_ADDRESS, BMA456_CHIP_ID_REG, I2C_MEMADD_SIZE_8BIT, &chip_id, 1, 1000);

if (status != HAL_OK) {
// Handle error here
return 0;
}
return chip_id;
}

int main() {
// ...

uint8_t chip_id = BMA456_ReadChipID();

if (chip_id == BMA456_CHIP_ID_VAL) {
// Communication is OK
} else {
// Communication is not OK
}

// ...
}

After debugging a little, I found that I am receiving the error code "4". The code that I provided is of course only the piece related to the bma456 sensor. If you need the rest of my main.c code, you can find it in the attachements.

I  would really appreciate the help, thanks a lot!

main.c
10KB
bma ds.png
49.39KB
3 replies