2 weeks ago
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!
a week ago
Hi Bullseye,
I uploaed BMA456 example code on STM32F401 for your reference. Sensor API, you could use the version on github https://github.com/boschsensortec/BMA456-Sensor-API
a week ago - last edited a week ago
Hello!
Thanks a lot for the quick response. I will try this out and get back to you with the results.
Have a great day ahead.
Edit: Having quickly looked at the files that you have provided, and considering that I am still somewhat a beginner in what regarding working with the BMA sensor. Could you help me understand how does your code work? There are a lot of definitions and functions especially in the bma456h_task files.
Thanks again!