I2C and Interupt Handler - blocking

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

cross mob
Anonymous
Not applicable

Hi. In my project I have one element which measure acceleration, and I get data using I2C interface.

   

In my program I want to get this data, and make some calculation every (for example) 100 ms. I use for this Timer with interrupt, but then the program stops working, and I can't get any data from this I2C.

   

I know, that there is a way to do it, but I don't know it ;(

0 Likes
4 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Just set a flag in your interrupt handler and check for it in your main-loop. Act upon accordingly.

   

When still stuck, post your complete project. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

You mean for example something Like this? If yes it didn't worked 😜

   

CY_ISR(Timer_Interrupt)
{
    timer_Flag = 1;
    //code
    timer_Flag = 0;
}

   

and in main:

   

if(timer_Flag == 0)

   

{

   

   readFromI2C();

   

}

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

Nearly.

   

volatile uint8 TimerFlag = 0;

   

CY_ISR(Timer_Interrupt)
{
    Timer_Flag = 1;
    //code to clear interrupt cause of timer goes here
}

   

and in main:

   

isr_StartEx(Timer_Interrupt);
.
.
.
if(Timer_Flag)

   

{

   

   readFromI2C();

   

   TimerFlag = 0;

   

}

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Thanks 😉

0 Likes