I am having some trouble running a interrupt to control reading data from a pressure sensor.
When the interrupt rises it means new data is available and when I do an i2c read the line will fall and when data is available again the interrupt rises.
My problem is the time between the previous new data and the next can vary slightly. it can vary between 1.38ms to 2ms. It is very important that I have a set and known time between each new data as I need it for plotting data.
I am thinking of using an increment timer to calculate how long its talking between each read? Could someone help me with setting up an increment timer?
Or does anyone have any idea on how to solve this?
Which sensor are you using?
Usually the sensors will have capabilities where you can set the output data rate.
You can set the rate on your sensor and put less load on the BLE chip, which will optimize the system power consumption.
Also, some sensors have FIFO available. So you can store a lot of data to the sensor's FIFO, before you pull the data.
The sensor datasheet should help.
This approach is probably the best because there are some limitations to the timers on the BLE chip. (app timer : 1 sec; fine timer: minimum 12.5ms)
But there's another timer that you can use at a resolution of 1.25ms.
This post will help with setting up the timer if you want to use timer.