--- In l..., "praks_1510" wrote:
>
> How to write an ISR routine to recieve data through uart?
>
Here's another $0.01 contribution.
Take a look at the code below written for an LPC2103. It sets UART#1 and the
corresponding ISR. FIFOs are enabled for size 8 (my packets are 11 bytes long so
going for 14 wouldn't do any good), after which I collect the characters
one by one until an LF ('\n' or 0x0A) character is received. In the
ISR I set a flag to indicate when the full packet is received.
And, please, do not take the programming style in the code as an example. I was
in a hurry, and that's an ongoing work, so I'll have a chance to
improve it.
Cheers,
Julio de Melo
#define TAM_FIFO_RX 8 /* tamanho do buffer FIFO da UART1 */
#define RDA_IRQ 0x04 /* interrupo por RDA */
#define CTI_IRQ 0x0C /* interrupo por CTI */
unsigned char codigo[NUMCOD+1];
__irq void rda_int(void) {
static int i;
unsigned char ch;
if (!(U1IIR & 0x01)) /* testar se halguma interrupo pendente */
{
if ((U1IIR & 0x0E) == RDA_IRQ) /* por RDA? */
for (i = 0; i < TAM_FIFO_RX; i++)
{
if (U1LSR & 0x01)
{
ch = U1RBR;
codigo[i] = ch;
if (ch == '\n')
i = 0;
}
}
else if ((U1IIR & 0x0E) == CTI_IRQ) /* por CTI? */
{
ch = U1RBR;
codigo[i++] = ch;
if (ch == '\n')
i = 0;
}
}
if (i == 0) // ativar flag de bloco recebido
cod_OK = TRUE;
else
cod_OK = FALSE;
VICVectAddr = 0; // Acknowledge Interrupt
}
void init_serial ()
{
/* RXD1/TXD1 s usados para interface com o sensor/transdutor */
U1LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit
*/
U1DLL = 96; /* 9600 Baud Rate @ 15MHz VPB Clock
*/
U1LCR = 0x03; /* DLAB = 0
*/
U1FCR = 0x87;
U1IER = 0x01; /* habilitar interrupo por RDA */
VICVectAddr1 = (unsigned long) rda_int; // set interrupt vector in 1
VICVectCntl1 = 0x20 | 7; // use it for UART1 Interrupt
}