Hello Andy_253,
It is impossible to get average data -4147 of x axis, because of default sensor range is 4G, typical maxmum LSB data is 8192.
Please refer the code and compare it with yours. Ensure your board is positive placement and keep horizontal.
main()
{
...
/* Function to select interface between SPI and I2C, according to that the device structure gets updated */ rslt = bma4_interface_selection(&dev); bma4_error_codes_print_result("bma4_interface_selection status", rslt);
/* Initialize BMA456 */ rslt = bma456_init(&dev); bma4_error_codes_print_result("bma456_init status", rslt);
#if defined(FOC) BMA456_Do_FOC(&dev); #endif
...
}
int8_t BMA456_Do_FOC(struct bma4_dev *dev) { struct bma4_accel_foc_g_value accel_g_value = {0, 0, 1, 0}; /*Do FOC for X,Y,Z axis*/ PDEBUG("Start to do FOC...\r\n"); if(bma4_perform_accel_foc(&accel_g_value, dev) == BMA4_OK) { PDEBUG("Do FOC success\r\n"); } else { PDEBUG("Do FOC failed\r\n"); } PDEBUG("End to do FOC\r\n"); }
And you could print offset value before writing to offset register.
static int8_t perform_accel_foc(const struct bma4_accel_foc_g_value *accel_g_value, const struct bma4_accel_config *acc_cfg, struct bma4_dev *dev)
{
...
PDEBUG("offset x=%d, y= %d, z=%d\r\n", offset.x, offset.y, offset.z);
/* Write offset data in the offset compensation register */ rslt = write_bma4_accel_offset(&offset, dev);
...
}
... View more