Hi Forum,
Just wondering if anyone could suggest a proper way to read the I2C / SPI in precision interval with ESP32?
Currently, I'm trying to build a gimble with DC motor(w/encoder). I use a LS7366R (external encoder counter with SPI) to count AB encoder and MPU6050 IMU to get the angle. Since I need to calculate the speed of the motor and do PID calculations, I need precise 20ms time interval. So my plan is put PID code and I2C / SPI reading in timer interrupt.
I used to put I2C / SPI read in a timer interrupt with Arduino Nano with Interrupt(); & noInterrupt(), and it works fine. However, when I start use ESP32, this code doesn't work as it does in Arduino. The ESP32 only runs main loop with taking care of interrupt. So is it possible to turn on the interrupt...when it is already in an interrupt?
I did A LOT search about this topic and the most common suggestion is set a flag in interrupt, and do the I2C and SPI read in main loop. However, based on my knowledge, (please correct me if I got anything wrong) by doing this, I would lose the time stamp so the interval between each reading is different, which causes unstable speed calculation and jump of Kd tern.
So is there any suggestion about how to read I2C/SPI in the timer interrupt? or how should I develop my algorithm?
Any help is appreciated!! Thanks a lot,
Bests
G
ESP32_Read I2C/SPI in precision time interval
Who is online
Users browsing this forum: No registered users and 83 guests