UART and I2C with Interrupt

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

cross mob
ShVy_264716
Level 4
Level 4
50 replies posted 25 replies posted 10 replies posted

I can program the UART with Hardware Interrupt, because the Rx_Interrupt pin is available in the UART component. I need help in programming I2C with interrupt, because the component does not have any hardware Interrupt pin. Please find the piece of ISR that I have written to get a byte on UART of Master and send it to the Slave by I2C:

   

CY_ISR(ISR_Rx_UART_Interrupt)
{
  
    I2CM_I2CMasterSendStart(I2C_SLAVE_ADDR, 1u);
    I2CM_I2CMasterWriteByte(UART_GetChar());
   
}
 

   

At the end, I want to configure UART and I2C with Software Interrupt. Any reference to the explanation of Hardware and Software interrupt will be highly appreciated.

   

Thanks in Advance.

   

Shaunak

0 Likes
6 Replies
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

There is an AppNote regarding interrupts: www.cypress.com/

   

Also, have a look at the example projects: right click on the component in the component browser, 'find example projects'.

   

It would also help if you state what the problem is - are there compile errors, does the ISR not get triggered (or only once?), or are there other problems?

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

In the "System Reference Guide" (Creator -> Help -> System Reference) you'll find a lot about interrupts. Additional information you may get from ARM when looking into the "Cortex M0 Devices Reference Manual".

   

 

   

Keep in mind, that some components (as UART, I2C, ADC ...) alredy use interrupts for their internal usage.

   

 

   

A quite easier way to handle what you want to is to fetch all the incoming UART bytes and store them into a circular buffer, then empty the buffer and send the bytes via I2C. This could be done more effective than transferring single bytes from within an interrupt handler. Also, the I2C overhead is reduced because there is no start/stop condition requred between sending multiple bytes.

   

 

   

Bob

0 Likes
ShVy_264716
Level 4
Level 4
50 replies posted 25 replies posted 10 replies posted

hli and bob, thank you very much for your inputs. I am already done with the UART receive interrupt, I2C-Write-from-Master-to-Slave interrupt. Now I need help to generate an interrupt from master I2C to read a particular data from slave I2C. Please guide for that.

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

Can you tell us, why you want to do that interrupt-driven by a software-interrupt although this is the same as a simple function call?

   

 

   

Bob

0 Likes
ShVy_264716
Level 4
Level 4
50 replies posted 25 replies posted 10 replies posted

Bob. I would prefer interrupt programming to the procedural programming. So as a part of the experiment, I want to do that.

0 Likes
Anonymous
Not applicable

Hello Shaunak,

   

i would like to use Software interrupt also. Please do you know now how to use it? When yes please send me, when possible your example.

   

Thanks for replying.

   

Rosine

0 Likes