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

LPC2148 using 2 UARTs at a time

I want to interface MCB2140 with a pressure sensor which will give input for every 1 second.. I connected UART0 to pressure sensor output, UART1 to serial port of PC. The pressure sensor gives the integer value as output.The UART0 will receive data from sensor and should display in hyper terminal for every 1 minute..I wrote the following code..The code gets hanged in startup file at BX R0...Please let me know any other changes required
#include <LPC21xx.H>
void init_serial (void);
int main(void) {
init_serial();

while(1)
{ int getc_serial0;
int putc_serial1;
} }
void init_serial (void) {

PINSEL0 = 0x00050005;

U0LCR = 0x00000083;

U0DLL = 98;

U0LCR = 0x00000003;

U1LCR = 0x00000083;

U1DLL = 98;

U1LCR = 0x00000003;

}

int getc_serial0(void)

{

while (!(U0LSR & 0x01));

return U0RBR;

}
int putc_serial1(void)

{

while (!(U1LSR & 0x20));

U1THR=U0RBR;

return (U1THR);

}

Parents
  • Hello chiranjeevi vivek,

    The reason why your program hangs in the startup file at the SWI_Handler is that you are using SWI functions without providing a SWI handler which processes the SWIs.

    An example for an SWI handler can be found in .\Keil\ARM\Examples\SWI.

    An other reason could be that your program is a RTX application and you do not provide the correct startup file.

    RTX uses SWI functions and the RTX kernel provides a SWI handler. To use this SWI handler you need a slightly different startup file:

    Vectors         LDR     PC, Reset_Addr
                    LDR     PC, Undef_Addr
                    LDR     PC, SWI_Addr
                    LDR     PC, PAbt_Addr
                    LDR     PC, DAbt_Addr
                    NOP                            ; Reserved Vector
    ;               LDR     PC, IRQ_Addr
                    LDR     PC, [PC, #-0x0FF0]     ; Vector from VicVectAddr
                    LDR     PC, FIQ_Addr
    
    Reset_Addr      DCD     Reset_Handler
    Undef_Addr      DCD     Undef_Handler
    SWI_Addr        DCD     SWI_Handler
    PAbt_Addr       DCD     PAbt_Handler
    DAbt_Addr       DCD     DAbt_Handler
                    DCD     0                      ; Reserved Address
    IRQ_Addr        DCD     IRQ_Handler
    FIQ_Addr        DCD     FIQ_Handler
    
                    IMPORT  SWI_Handler
    
    Undef_Handler   B       Undef_Handler
    ;SWI_Handler    B       SWI_Handler            ; Part of RTL
    PAbt_Handler    B       PAbt_Handler
    DAbt_Handler    B       DAbt_Handler
    IRQ_Handler     B       IRQ_Handler
    FIQ_Handler     B       FIQ_Handler
    

    Best Regards, Martin Guenther

Reply
  • Hello chiranjeevi vivek,

    The reason why your program hangs in the startup file at the SWI_Handler is that you are using SWI functions without providing a SWI handler which processes the SWIs.

    An example for an SWI handler can be found in .\Keil\ARM\Examples\SWI.

    An other reason could be that your program is a RTX application and you do not provide the correct startup file.

    RTX uses SWI functions and the RTX kernel provides a SWI handler. To use this SWI handler you need a slightly different startup file:

    Vectors         LDR     PC, Reset_Addr
                    LDR     PC, Undef_Addr
                    LDR     PC, SWI_Addr
                    LDR     PC, PAbt_Addr
                    LDR     PC, DAbt_Addr
                    NOP                            ; Reserved Vector
    ;               LDR     PC, IRQ_Addr
                    LDR     PC, [PC, #-0x0FF0]     ; Vector from VicVectAddr
                    LDR     PC, FIQ_Addr
    
    Reset_Addr      DCD     Reset_Handler
    Undef_Addr      DCD     Undef_Handler
    SWI_Addr        DCD     SWI_Handler
    PAbt_Addr       DCD     PAbt_Handler
    DAbt_Addr       DCD     DAbt_Handler
                    DCD     0                      ; Reserved Address
    IRQ_Addr        DCD     IRQ_Handler
    FIQ_Addr        DCD     FIQ_Handler
    
                    IMPORT  SWI_Handler
    
    Undef_Handler   B       Undef_Handler
    ;SWI_Handler    B       SWI_Handler            ; Part of RTL
    PAbt_Handler    B       PAbt_Handler
    DAbt_Handler    B       DAbt_Handler
    IRQ_Handler     B       IRQ_Handler
    FIQ_Handler     B       FIQ_Handler
    

    Best Regards, Martin Guenther

Children