Can I get mems values (from IKS01A2) through a callback? It seems not

Hello experts ! Sorry to bother you but I’m suspecting we cannot catch mems values (acc and gyro) from an IKSO1A2 ST evaluation board using a callback routine? is it? Where am I doing wrong?
Let’s say… I know I can read values from accelerometer and gyro in main loop as written in “HelloWorld_IKS01A2” example…but it seems it doesn’t work if I do it in a callback function like this code:

// Main function
int main()

  • uint16_t status = imu.begin(); *
  • imu.calibrate(1);*
  • start.attach(&read_acc_gyro, 0.01); // <–here I’d like to read values from mems with loop frequency 100Hz*
  • while(1) { *
  •   pc.printf("%f\n\r",speed);   *
  • }*

where “start” is a Ticker object of course and “read_acc_gyro” is a routine with inside:

  • gyroscope->get_g_axes_raw(gyrL);*

Unlucky the code doesn’t work :frowning:

so what do you think? Can I catch values in this way ?!?!?:slight_smile:

Many thanks for your help and regards


please, use these symbols ``` before and after your code for good code formatting in your post.

Variables what are used outside and also inside an ISR is good to have as volatile, to prevent compiler optimization.
Alternatively you can try to use EventQueue - API references and tutorials | Mbed OS 6 Documentation

BR, Jan

1 Like

Many thanks Johnny for your help!!
(sorry for my late thanks :slight_smile: )