6 Replies Latest reply on Feb 17, 2015 7:11 AM by userc_41734

    UART and I2C with Interrupt

    ShVy_264716

      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

        • 1. Re: UART and I2C with Interrupt
          HeLi_263931

          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?

          • 2. Re: UART and I2C with Interrupt
            JoMe_264151

            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

            • 3. Re: UART and I2C with Interrupt
              ShVy_264716

              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.

              • 4. Re: UART and I2C with Interrupt
                JoMe_264151

                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

                • 5. Re: UART and I2C with Interrupt
                  ShVy_264716

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

                  • 6. Re: UART and I2C with Interrupt

                    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