This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Working with interrupts on LPC2129

I'm just getting started with using the Keil uV3 compiler as well as the Phillips lpc2129. The application I am working on requires both UART0 & 1 as well as the I2C and I'm wondering if anyone has some <sample> code for enabling/using interrupts handy for this part that they might could pass along to help me get started.

Any links related to writing C code for the lpc2129 would also be appreciated.

regards & thanks
-mel

Parents
  • Thanks for the code, for the most part what I came up with was (about) the same. I am not using printf and therefor have not added syscalls.c to my project. Also adding that file will require some work on my part as I have three different put/get-char calls (et al. putchar_uart0, putchar_uart1, putchar_i2c) but no get/put char as required in syscalls.c.

    My code is not performing correctly regarding the interrupts for uart1. I'll post the code here and also in a new thread for possible extra help.

    First of all, here is the main loop...

    	while(1)  {
    
    		cTemp = getchar_uart1();
    		if( cTemp )
    			putchar_uart1( cTemp );
    		cTemp = 0;
    
    	}
    
    

    As you can see it is simply echoing any Rx'd bytes back out uart1. This works fine when I have the uart1 interrupts disabled. However, when I enable nothing happens that I can see, both by monitoring the output and using the uV3 debugger. I suspect that something is amiss in my interrupt code so I'll post that and maybe you can spot what I'm doing wrong...

    void u1_interrupt (void) __attribute__ ((interrupt));   /* generate interrupt */
    
    /*************************************************************************/
    /**************************  interrupt for uart1  ************************/
    void u1_interrupt (void)  {
    	char intrpt;
    	intrpt = U1IIR;   /* reset U1IIR register */
    // for now just trying to echo the Rx'd byte back out uart1...
    	intrpt = U1RBR;	// clear Rx buffer, and reset interrupt
    	putchar_uart1( intrpt );
    
    	VICVectAddr = 0;   /* acknowledge interrupt */
    }/*end u1_interrupt() */
    
    
    
    void init_uart1( void )  {
    	PINSEL0 |= 0x00550000;   /* set P0.8, P0.9, P0.10 and P0.11 as TxD1, RxD1, RTS1, CTS1 */
    	U1LCR = 0x83;   /* set DLAB and word size (8bits), defaults for others yield */
    						 /* no parity, one stop bit, and no break */
    	U1DLL = 0x61;   /* yields 9600 Baud */
    	U1DLM = 0x00;   /* explicit initialization - is also the default */
    	U1LCR &= 0x7f;   /* clear DLAB */
    
    /* set up the interrupts */
    	U1IER = 0x05;   /* enable RBR and RLS interrupts */
    	VICVectAddr1 = (unsigned long) u1_interrupt;   /* set interrupt vector */
    	VICVectCntl1 = 0x20 | 7;   /* use VICVectAddr1 for UART1 interrupts */
    	VICIntEnable = 0x00000080;   /* enable uart1 interrupts */
    
    }/* end init_uart1()
    

    any suggestions?

Reply
  • Thanks for the code, for the most part what I came up with was (about) the same. I am not using printf and therefor have not added syscalls.c to my project. Also adding that file will require some work on my part as I have three different put/get-char calls (et al. putchar_uart0, putchar_uart1, putchar_i2c) but no get/put char as required in syscalls.c.

    My code is not performing correctly regarding the interrupts for uart1. I'll post the code here and also in a new thread for possible extra help.

    First of all, here is the main loop...

    	while(1)  {
    
    		cTemp = getchar_uart1();
    		if( cTemp )
    			putchar_uart1( cTemp );
    		cTemp = 0;
    
    	}
    
    

    As you can see it is simply echoing any Rx'd bytes back out uart1. This works fine when I have the uart1 interrupts disabled. However, when I enable nothing happens that I can see, both by monitoring the output and using the uV3 debugger. I suspect that something is amiss in my interrupt code so I'll post that and maybe you can spot what I'm doing wrong...

    void u1_interrupt (void) __attribute__ ((interrupt));   /* generate interrupt */
    
    /*************************************************************************/
    /**************************  interrupt for uart1  ************************/
    void u1_interrupt (void)  {
    	char intrpt;
    	intrpt = U1IIR;   /* reset U1IIR register */
    // for now just trying to echo the Rx'd byte back out uart1...
    	intrpt = U1RBR;	// clear Rx buffer, and reset interrupt
    	putchar_uart1( intrpt );
    
    	VICVectAddr = 0;   /* acknowledge interrupt */
    }/*end u1_interrupt() */
    
    
    
    void init_uart1( void )  {
    	PINSEL0 |= 0x00550000;   /* set P0.8, P0.9, P0.10 and P0.11 as TxD1, RxD1, RTS1, CTS1 */
    	U1LCR = 0x83;   /* set DLAB and word size (8bits), defaults for others yield */
    						 /* no parity, one stop bit, and no break */
    	U1DLL = 0x61;   /* yields 9600 Baud */
    	U1DLM = 0x00;   /* explicit initialization - is also the default */
    	U1LCR &= 0x7f;   /* clear DLAB */
    
    /* set up the interrupts */
    	U1IER = 0x05;   /* enable RBR and RLS interrupts */
    	VICVectAddr1 = (unsigned long) u1_interrupt;   /* set interrupt vector */
    	VICVectCntl1 = 0x20 | 7;   /* use VICVectAddr1 for UART1 interrupts */
    	VICIntEnable = 0x00000080;   /* enable uart1 interrupts */
    
    }/* end init_uart1()
    

    any suggestions?

Children