Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

Re: UART ISR

2004-11-04 by peterburdine

--- In lpc2000@yahoogroups.com, "peterburdine" <lordofdawn@h...> wrote:
> 
> I know I've asked this question many many times, but I still can't
> figure out what is wrong.  I've tried some of the code on the forums,
> and that seemed to work.  When I cut and paste it into my project it
> no longer seems to work.  I've reduced this to as simple as I can get
> it, can anyone see some thing wrong?
> 
> The main.c there in full, you should just be able to compile it if you
> use Keil's (if you have gcc, it might need a minor modification).  I
> believe that this should send out an infinite number of 'a's, which of
> course it does on the simulator, but not in real life.  When I debug
> it via JTAG in uVision3, I see the THRE interrupt for a short while,
> but then it dissappears, but the ISR is never called (as seen by the
> LED still being on).  Yes I have tested the LED code, it works.
> 
> Hear is some code from my startup.s (I'm using Keil's)
> 
> // Enter Supervisor Mode and set its Stack Pointer
>                	MSR     CPSR_c, #Mode_SVC|I_Bit|F_Bit
>                	MOV     SP, R0
>                	SUB     R0, R0, #SVC_Stack_Size
> 
> 		// Stay in supervisor mode, IRQ and FIQ
> 		MSR 	CPSR_c, #Mode_SVC
> 
> // Enter the C code
>                 LDR     R0,=main
>                 TST     R0,#1       ; Bit-0 set: main is Thumb
>                 LDREQ   LR,=exit?A  ; ARM Mode
>                 LDRNE   LR,=exit?T  ; Thumb Mode
>                 BX      R0
>                 ENDP
> 
> 
> Here is my main.c
> 
> #define		PINSEL0 		(*((volatile unsigned long *) 0xE002C000))
> #define		VICIntSelect  	(*((volatile unsigned long *) 0xFFFFF00C))
> #define		VICIntEnable  	(*((volatile unsigned long *) 0xFFFFF010))
> #define		VICIntEnClr		(*((volatile unsigned long *) 0xFFFFF014))
> #define		VICVectAddr		(*((volatile unsigned long *) 0xFFFFF030))
> #define		VICVectAddr0	(*((volatile unsigned long *) 0xFFFFF100))
> #define		VICVectCntl0	(*((volatile unsigned long *) 0xFFFFF200))
> #define		VICVectAddr1	(*((volatile unsigned long *) 0xFFFFF104))
> #define		VICVectCntl2	(*((volatile unsigned long *) 0xFFFFF204))
> 
> #define		U0THR			(*((volatile unsigned long *) 0xE000C000))
> #define		U0RBR			(*((volatile unsigned long *) 0xE000C000))
> #define		U0DLL			(*((volatile unsigned long *) 0xE000C000))
> #define		U0DLM			(*((volatile unsigned long *) 0xE000C004))
> #define		U0IER			(*((volatile unsigned long *) 0xE000C004))
> #define		U0IIR			(*((volatile unsigned long *) 0xE000C008))
> #define		U0FCR			(*((volatile unsigned long *) 0xE000C008))
> #define		U0LCR			(*((volatile unsigned long *) 0xE000C00C))
> #define		U0LSR			(*((volatile unsigned long *) 0xE000C014))
> #define		U0SCR			(*((volatile unsigned long *) 0xE000C01C))
> 
> #define		IO0PIN		 	(*((volatile unsigned long *) 0xE0028000))
> #define		IO0SET		 	(*((volatile unsigned long *) 0xE0028004))
> #define		IO0DIR		 	(*((volatile unsigned long *) 0xE0028008))
> #define		IO0CLR		 	(*((volatile unsigned long *) 0xE002800C))
> 
> #define LED_PIN				0x00000100
> #define LED_OFF				(IO0SET = LED_PIN)
> #define LED_ON				(IO0CLR = LED_PIN)
> 
> #define 	PCLK			(60000000)
> #define 	UART_BAUD(baud)	((unsigned short)((PCLK / ((baud) * 16.0)) +
> 0.5))
> 
> void main (void);
> void uart_isr (void);
> 
> static int irq_occured = 0;
> 
> void main(void) {
> 	unsigned short uart_divisor;
> 	volatile unsigned char dummy;	
> 	unsigned int x = 0;
> 
> 	IO0DIR = LED_PIN;	/* enable as output */
> 	LED_ON;
> 
> 	PINSEL0 = 0x00000005;
> 
> 	// Setup UART
> 	U0IER = 0x00;
> 	dummy = U0IIR;
> 	dummy = U0IIR;
> 	dummy = U0DLM;
> 
> 	U0LCR = 0x80; // Enable DLAB
> 	uart_divisor = ((unsigned short)((PCLK / ((19200) * 16.0)))+0.5);
> 	U0DLL = uart_divisor&0xff;
> 	U0DLM = 0;
> 	U0LCR &= 0x7F;  // Disable DLAB
> 	U0LCR = 0x03; // Enable DLAB
> 	U0IER = 0x07;
> 
> 	// Setup interrrupts
> 	VICIntSelect = 0x00000000; // No FIQs
> 	VICIntEnable = (0x1 << 6);  // 6 = Uart 0
> 	VICVectCntl0 = 0x20 | 6;
> 	VICVectAddr0 = (unsigned long)uart_isr;
> 
> 	U0THR = '1';
> 	U0THR = '2';
> 	U0THR = '3';
> 	U0THR = '4';
> 	U0THR = '5';
> 	U0THR = '6';
> 
> 	while(1);
> }
> 
> void uart_isr (void) __irq {
> 	volatile char dummy;
> 
> 	LED_OFF;
> 	dummy = U0IIR;
> 	dummy = U0LSR;	
> 	U0THR = 'a';
> 
> 	VICVectAddr = 0;
> }

I also noticed something else.  The last character that was sent was
being corrupted.  If I removed the interrupt code that would not
happen.  I noticed this when trying to add a timer interrupt (which
also works in Keil's simulator but not when I put it on the chip).

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.