Hi, everyone.
I am a newbie in LPC2000. Now I have a LPC2210 DVK. I want to use the uart0 to receive data in the interrupt way, not polling. But things do not work well. Now the LPC2210 CPU can receive some data, several bytes, after that, it does not work any more. Any one can help me? Thank you!
The startup part of the project is OK, and I can send data to the PC with the UART0 using the polling way. I run the program in the internal ram. And I use the super terminal on a PC to send some data to the UART0.
I use cygwin to compile my project.
Here’s the source code.
#define BUF_SIZE 2048
#define bps 19200
static char Buf[BUF_SIZE];
static uint32 Hard = 0;
static volatile uint32 End = 0;
#define IRQ_Enable() asm volatile(" mrs r0, cpsr\n"\
" bic r0, r0, #0x80\n"\
" msr cpsr_c, r0")
#define ISR_ENTRY() asm volatile(“sub lr, lr, #4\n”\
“stmfd sp!, {r0-r12, lr}\n”\
“mrs r1, spsr\n”\
“stmfd sp!, {r1}”)
#define ISR_EXIT() asm volatile(“ldmfd sp!, {r1}\n”\
“msr spsr_c, r1\n”\
“ldmfd sp!, {r0-r12, pc}^”)
//the exception handler
void UART0_Exception(void) attribute ((interrupt(“IRQ”)));
void UART0_Exception(void)
{
ISR_ENTRY();
uint8 temp = U0IIR;
while ((U0LSR & 0x00000001) != 0)
{
Buf[End++] = U0RBR;
if (End >= BUF_SIZE)
{
End = 0;
}
}
VICVectAddr = 0;
ISR_EXIT();
}
void CommInit(void)//initial the UART0
{
uint16 Fdiv;
PINSEL0 = (PINSEL0 & 0xfffffff0) | 0x05;
U0LCR = 0x80;
Fdiv = (Fpclk / 16) / bps;
U0DLM = Fdiv / 256;
U0DLL = Fdiv % 256;
U0LCR = 0x03;
U0IER = 0x00;
U0FCR = 0x87;
Hard = 0;
End = 0;
VICIntEnClr = 0xffffffff;
VICIntSelect &= 0xffffffbf;
VICVectAddr14 = (uint32)UART0_Exception;
VICVectCntl14 = (0x20 | 0x06);
VICIntEnable = 1 << 6;
U0IER = 0x01;
}
char GetCh(void)// get a character from the buffer
{
char temp;
while (Hard == End);
temp = Buf[Hard++];
if (Hard >= BUF_SIZE)
{
Hard = 0;
}
SendChar(temp);
return temp;
}
void SendChar(char data)
{
while((U0LSR & 0x00000020) == 0);
U0THR = data;
}
//initial the CPU, clock, etc.
void TargetResetInit(void)
{
MEMMAP = 0x02;//Remap to internal RAM
PLLCON = 1;
#if ((Fcclk / 4) / Fpclk) == 1
VPBDIV = 0;
#endif
#if ((Fcclk / 4) / Fpclk) == 2
VPBDIV = 2;
#endif
#if ((Fcclk / 4) / Fpclk) == 4
VPBDIV = 1;
#endif
#if (Fcco / Fcclk) == 2
PLLCFG = ((Fcclk / Fosc) - 1) | (0 << 5);
#endif
#if (Fcco / Fcclk) == 4
PLLCFG = ((Fcclk / Fosc) - 1) | (1 << 5);
#endif
#if (Fcco / Fcclk) == 8
PLLCFG = ((Fcclk / Fosc) - 1) | (2 << 5);
#endif
#if (Fcco / Fcclk) == 16
PLLCFG = ((Fcclk / Fosc) - 1) | (3 << 5);
#endif
PLLFEED = 0xaa;
PLLFEED = 0x55;
while((PLLSTAT & (1 << 10)) == 0);
PLLCON = 3;
PLLFEED = 0xaa;
PLLFEED = 0x55;
MAMCR = 0;
#if Fcclk < 20000000
MAMTIM = 1;
#else
#if Fcclk < 40000000
MAMTIM = 2;
#else
MAMTIM = 3;
#endif
#endif
MAMCR = 2;
VICIntEnClr = 0xffffffff;
VICVectAddr = 0x00000000;
VICIntSelect = 0x00000000;
}
// in the main function. things seems to be:
int main()
{
char tempdata;
TargetResetInit();
CommInit();
IRQ_Enable();
while(1)
{
tempdata = GetCh();
SendChar(tempdata);
}
return 0;
}
Regards,
Kevin