Read slave I2C in ISR

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

cross mob
yaga_3967241
Level 3
Level 3
50 sign-ins 25 sign-ins 10 replies posted

Hi,

I need to read an I2C slave device in a pin ISR in order to avoid a polling in main(). I can read the I2C slave from main() without any issue, but when I run exactly the same code in pin ISR to read the I2C slave device, the read function never returns.

What would be wrong? Is it because I2C reading also generate an interrupt that is blocked by current pin ISR?

Thanks,

Winston

0 Likes
1 Solution
Hari
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hi @yaga_3967241,

 

Are you using the pin interrupt only for checking activity on the bus? You can do so by enabling the callback function in the cyapicallback.h file. There is an exit callback present in the I2C code, please see I2C_INT.c file for more details. The I2C_1_ISR_ExitCallback(); function is called by the component if I2C_1_ISR_EXIT_CALLBACK is defined in cyapicallback.h. 

 

If you still wish to do so with the pin, the issue might be with the interrupt priority and on how it is handled. Please make sure that you clear the pin interrupt and disable the interrupt as soon as there is any activity so that it does not trigger again during a read cycle. You can also change the interrupt priority by going to the interrupts tab in design wide resources to make sure that I2C interrupts have a higher priority than Pin interrupt.

 

Best regards, 
Hari

View solution in original post

0 Likes
2 Replies
Hari
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hi @yaga_3967241,

 

Are you using the pin interrupt only for checking activity on the bus? You can do so by enabling the callback function in the cyapicallback.h file. There is an exit callback present in the I2C code, please see I2C_INT.c file for more details. The I2C_1_ISR_ExitCallback(); function is called by the component if I2C_1_ISR_EXIT_CALLBACK is defined in cyapicallback.h. 

 

If you still wish to do so with the pin, the issue might be with the interrupt priority and on how it is handled. Please make sure that you clear the pin interrupt and disable the interrupt as soon as there is any activity so that it does not trigger again during a read cycle. You can also change the interrupt priority by going to the interrupts tab in design wide resources to make sure that I2C interrupts have a higher priority than Pin interrupt.

 

Best regards, 
Hari

0 Likes
yaga_3967241
Level 3
Level 3
50 sign-ins 25 sign-ins 10 replies posted

Hi Hari,

I am not using the pin interrupt for checking the activity on the I2C bus. It is the reverse: when a pin interrupt happens, I need to read I2C register.  The pin has no relation to I2C directly, it just indicates some work needs to be done, and one of the work is to read an I2C device. In this case, is there any good solution to do it?

I will try the approach in your second paragraph.

Thanks,

Yan

0 Likes