I am currently working on a project that wants to get data from this sensor: http://wiki.seeedstudio.com/wiki/Grove_-_Dust_Sensor. In order to do this I need a timer that will elapses at 2 seconds and also works on DEEP SLEEP state and a GPIO interrupt set for Output pin of the sensor.
Therefore I did the following:
I took pin P1.6 and set it as High Impedance Digital(initial state 0) state Digital input and under the Input tab I set Interrupt to be Both Edges and dedicated interrupt was attach, configured and started with _StartEX(Handle) call.
For the Timer I chose WDT_Timer_0 since I need it to work also in deep sleep. I did not configure the timer inside creator but I used this code:
<code>/* Setup WDT Counter 0 to generate interrupt on match */
/* Write match count */
/* Enable clear of counter on match */
/* Enable WDT counter 0 */
/* associate a callback to wdt interrupt */
Some notes: It does not matter if I use this code or configure the timer inside creator, the interrupt gets fired every 2 seconds as intended!
I also use WDT_TIMER_2 for RTC and it is configured at 4 seconds(it works).Therefore I used the CySysWdtSetInterruptCallback call since in creator I need the auto generate mode for RTC. This is not the problem because the interrupt is fired and the callback attached is called.
The problem that I have is that when start the Interrupt on GPIO or set the Callback for WDT the entire code sometimes if I am not connected at BLE and always!! when connected to BLE, does not even reach the MAIN FOR loop. It will print the fact that it goes to GPIO interrupt and WDT 0 interrupt callbacks but it goes out of main code. The CySmart app disconnects the device and it needs a reset or else it will always commute in GPIO interrupt when the sensor pin goes 0 or 1, and in timer interrupt once at every 2 sec.
The code is complicated and uses many other sensors without a problem but when added this 2 callbacks it is dead.
My assumptions are: I did not set the GPIO state correctly(high impedance), using 2 WDT creates some confusion. Morover even if I set one of the 2 callbacks the code is broken.
If anyone has any idea it would be great. Thank you!