How to write interrupt for receiving and sending through UART0

-1

I am using my uC LPC2478. I am working on function UART0. But I need to make function UART0. I don't know about Interrupt, to how use!

i try to make to send a long string und it should be receive a Long string. but it doesn't work. But Does I need to write in function __irq void isr_UART0 (void)???

    >     void initUART0 (void)
    >     {
    >       PCONP   |= (1 << 3);                 /* Enable UART0 power                */
    >     
    >       PINSEL0 &= ~0x000000F0;
    >       PINSEL0 |= 0x00000050;
    >     
    >       U0FDR    = 0;                          /* Fractional divider not used       */
    >       U0LCR = 0x83;                       /* 8 bits, no Parity, 1 Stop bit       */
    >       U0DLL = 10;                          /* 115200 Baud Rate @ 12MHz PCLK Clock */
    >     
    >       U0DLM = 0;
    >       U0LCR = 0x03;                       /* DLAB = 0                            */
    >       
    >       U0IER = 0;
    >       
    >       VICVectAddr6 = (U32)isr_UART0;     /* Set Interrupt Vector                */
    >       VICVectCntl6 = 15;                   /* use it for UART1 Interrupt          */
    >       VICIntEnable  = (1  << 6);          /* Enable Interrupt                    */
    >       
    >       U0IER = 0x03;
    >     }
    > 
    >     void sendToUART0 (char *data, int len)
    >     {
    >       int i;
    >       
    >       while (!(U0LSR & (1 << 5)));
    >       for (i = 0; i < len; i++)
    >       {
    >           U0THR = *data;
    >           data++;
    >       }
    >     }
    > 
    >     void readDataAtUART0 (char *ch) { 
    >       //while (!(U0LSR & 0x01));  
    >        while (!(U0LSR & (1 << 0))); 
    >        *ch = U0RBR; 
    >     }
    > 
    >     /* UART1 receive ISR
    >     ******************************************************** */
    >     __irq void isr_UART0 (void) {     
    >       // readDataAtUART0();
    > 
    >               // read and assign the received data 
           VICVectAddr = 0;              /* Acknowledge Interrupt   */ 
    >      }
c
interrupt
lpc
asked on Stack Overflow Dec 12, 2014 by goethe • edited Dec 12, 2014 by goethe

1 Answer

0

'but it doesn't work' is a VERY POOR description of your problem so -1 anyway.

'readDataAtUART0();' does not match the signature of 'void readDataAtUART0 (char *ch)', so this code will not compile. Interrupt-handlers have no process or thread context, so you MUST resort to at least one global var to allow the handler to communicate - in your case, an array pointer.

TX interrupts are a bit more awkward, since the U0THR may need 'priming' with the first character to send. This can be awkward, requiring the tx interrupt to be disabled to check whether the U0THR has been emptied of the last char of the previous buffer content.

Just get the code to compile and then get rx handler working first.

answered on Stack Overflow Dec 12, 2014 by Martin James

User contributions licensed under CC BY-SA 3.0