Bosch Sensortec Community

    Showing results for 
    Search instead for 
    Did you mean: 

    BMA456 - Trouble with timing and crashing

    BMA456 - Trouble with timing and crashing


    Hi there,

    I'm currently developing a data logging system and I'm using a bma456 connected to a SparkFun Pro nRF52840 Mini ( communicating over i2c. I'm working in the Arduino IDE and am having two main issues: 

    1) At a configuration of 1600Hz, and set up as continuous performance and averaging 4 samples at one time I have issues with the values spiking to -0.06 and crashing (not every time) system. I also note a change in the configuration values that shouldn't be possible as seen in the image. 

    2) I'm using micros() to stamp a timestamp each serial readout of data from the accelerometer and I note a variance between each value. For example, it will be 977 microseconds between two sets, and then at a seemingly random interval, there will be a difference of 1953 microseconds, but that is the only variance. I would have assumed each accelerometer value to be read at the same delta time moment. Any ideas?

    I'm also looking for some advice with fixing the offset in the accelerometer in addition to the advice in attempting to fix these bugs.

    Thank you for your time.

    Kind Regards,

    3 REPLIES 3

    Hi Sam,

    1) The sensor's raw output is in LSB. I suspect that -0.06 must be rounding error when converting an invalid value to floating point. I highly doubt that this is coming from the sensor, but the only way to be sure, would be to log the actual state of the bus using a logic analyzer, and compare it with a log of the raw data to make sure that the protocol decoding is working and that there are no communication errors.

    2) At 1.6kHz, the sensor should output data every 625us, not 977us. Could it be that:
    a) your timestamp resolution is not that small ? or
    b) Your MCU is not processing interrupts fast enough to measure all samples ?

    Regarding the variance, I quickly glanced at your code. Are you logging data over a wireless link ? If so, I would first investigate the chances of a simple packet drop. 1953/977 = 1.999, which highly suggests that there was simply a sample that was lost in transmission.


    Hi o_o,

    Thanks for your response. I actually was working on this over the weekend and concluded that:

    1) Is a power/grounding issue on my breadboard. I note that if I hold down my power cables and ground cables the device does not crash.

    2) I was using wired i2c when I timestamped data. I am transmitting the code over BlueTooth link but that is post-XYZ-capture. I've switched to SPI over the weekend and I think it might have something to do with micros(). I note the BMA456 does have a Sensor Time (counter that increments at 39.0625 us) that I may investigate. 
    It does seem weird that the timing is not 625us, I've been following through the code to see if there is any delay in the XYZ capture but there appears to be nothing. 
    The nrf52840 clk speed is 64Mhz (and I didn't modify the i2c speed so I assume it to be 100 kbit/s) so I don't think its because of the MCU unless there is something fishy going on.

    I'll keep you posted. Thanks for your help 🙂


    Edit 2:

    The timing issues are because Serial was slowing it down. Placing it in a buffer and reading through and serial outputting it fixes the timing inconsistency.

    My only thing now is I'm trying to get it to synchronise the data correctly. I think my next strategy is to use an interrupt on the accelerometer to alert when data is ready to be captured and then read the data rather than a delay.