Recall interrupt

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hi all. I want to make a project with CY8CKIT-059. I want to receive sensor digital value from a photodiode using interrupt in digital pin. LCD will displays the value of sensor after interrupt works (interrupt will work when the light is OFF). After the counter value reaches 8, the processor will stop receiving data. Then, when I turn ON and OFF again the light, the processor will receive again the data until the counter value reaches 8. But, the reality is not like that. After the counter value is equal to 8, I try to turn light ON and OFF again, but the processor only receive 1 value from sensor and the counter doesn't work.

Here I also attached my project. 

Looking forward for your help. Thank you

Regards

Yakub

0 Likes
1 Reply
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

I did not check the logic of your project yet, but you are making two unforgivable errors.

   

Declaring intermediate variables that are used within an interrupt handler should be declared inside the handler when not accessed by another function. If accessed they must be declared as "volatile" or you'll run into deep troubles.

   

 

   

Never call delay-functions within an interrupt handler neither directly nor indirectly (LCD-functions delay!). Avoid loops. Do not wait for any event to happen.

   

 

   

Best (and safest) practice is

   

Declare a global volatile variable as an indicator (flag) for the interrupt. In interrupt handler set the flag, clear the interrupt and return.

   

In the main-loop: Check the flag. When set, act accordingly and reset the flag.

   

 

   

Happy coding

   

Bob

0 Likes