LPC1225 UART Receive Problem

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

LPC1225 UART Receive Problem

2,521件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by angle9 on Wed Jun 22 21:36:26 MST 2011
Dear all...

I am developing GPS system using LPC1225.

Cause, this is new for me, before I used LPC2103, so I test this with simple UART send and receive.

Here is the serial init function


void SER_init (void) {
   
  LPC_IOCON->PIO0_1  =  (2UL <<  0);            
  LPC_IOCON->PIO0_2  =  (2UL <<  0);                          
  /* configure PINs GPIO0.1, GPIO0.1 for UART0 
  LPC_SYSCON->SYSAHBCLKCTRL |= ((1UL << 31) |        
                                (1UL << 16) ); 

 /* configure UART0 115200 bps from 12MHz Internal Osc*/
  LPC_SYSCON->SYSAHBCLKCTRL |=  (1UL << 12);         
  LPC_SYSCON->UART0CLKDIV    =  (2UL <<  0);   

  LPC_UART0->LCR = 0x83;                 
  LPC_UART0->DLL = 4;                     
  LPC_UART0->FDR = 0x85;                  
  LPC_UART0->DLM = 0;                         
  LPC_UART0->LCR = 0x03;                                      
}


Getkey function
int getkey (void) {

  while (!(LPC_UART0->LSR & 0x01));
  return (LPC_UART0->RBR);
}


The main function just printf and call getkey function for receive the data.
When program to flash and execute, I can send the data from MCU, but the MCU can not receive the data send from PC.

Anyone can help me about this issue? Is there something wrong with serial init function?

Thanks

Usman
0 件の賞賛
返信
14 返答(返信)

2,431件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Rob65 on Tue Jun 28 09:46:59 MST 2011
If you do not get an echo on a short between TxD and RxD on the lpc1225 then you have a problem in your connection somewhere.

I have used Flash Magic a few times and the terminal works OK.
Make sure that you have no tick mark near "Modify Default COM port behaviour" (default setting) - that should work.

Rob
0 件の賞賛
返信

2,431件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by angle9 on Tue Jun 28 02:48:35 MST 2011
Oh sorry...first time try, board not powered.

Try again with board powered..
My terminal can not receive echo character!!!

Terminal program use Flash Magic..
0 件の賞賛
返信

2,431件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by angle9 on Tue Jun 28 02:14:35 MST 2011

Quote: Rob65
The problem may be your terminal program.
That is why I suggested to try to short circuit TxD/RxD on the lpc to test an full echo test from PC to lpc module.
making both pins input and creating a short circuit on the lpc module is the quickest way to test this that I could think of.



Try to short TX and RX pin. My terminal program can receive the echo character.
0 件の賞賛
返信

2,431件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Rob65 on Tue Jun 28 01:48:59 MST 2011

Quote: angle9

For uart connection, it should be no problem. Because for it is OK when use as ISP to program the flash memory...



The problem may be your terminal program.
That is why I suggested to try to short circuit TxD/RxD on the lpc to test an full echo test from PC to lpc module.
making both pins input and creating a short circuit on the lpc module is the quickest way to test this that I could think of.

Regards,

Rob
0 件の賞賛
返信

2,431件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by angle9 on Tue Jun 28 01:33:26 MST 2011
@Jharwood & Rob65

Thanks for respons.

I already configure GPIO0_1 as port, and make flip-flop program. No problem as output. I will try to configure as input.

For uart connection, it should be no problem. Because for it is OK when use as ISP to program the flash memory...
0 件の賞賛
返信

2,431件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Rob65 on Tue Jun 28 00:51:47 MST 2011
Strange.
I also do not have an lpc1225 to play with but your code looks OK to me.
You could try to set both pins as GPIO and just copy the RXD bit into TXD and see what happens then.

Maybe a quicker test even is to set both as GPIO input pins and temporarily place a wire in between the P0.1/ P0.2 pins to check if there is a problem with your uart connection towards the terminal program.

Regards,

Rob
0 件の賞賛
返信

2,431件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jharwood on Mon Jun 27 22:09:43 MST 2011
Yes, I can see your concern.

I don't have a 12xx to play with, but looking at the UM, this would probably be the best approach:

uint8_t get_uart_ch(void) {
    //check LSR - line status register
    while (!(LPC_UART0->LSR & 0x01));
    // got one !
    // return a character from the receive buffer register 
    return LPC_UART0->RBR;
}
0 件の賞賛
返信

2,431件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by angle9 on Mon Jun 27 19:52:22 MST 2011
Still confused with LPC1225 UART0...:confused:
0 件の賞賛
返信

2,431件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by angle9 on Thu Jun 23 01:01:57 MST 2011
Change getkey function:


int getkey (void) {
  while (!( LPC_UART0->LSR))
  {
  }
  return (LPC_UART0->LSR);
}


And main function as below:

int main (void) 
{          
   int x;
   SER_init();                                           
   printf ("Serial Test\n");
   x= getkey();
   printf ("x value %d\n\r", x);
  while (1) {                                                  
     x= getkey();
     printf ("x value%d\n\r", x);
  }
}


So, the getkey function result is LSR value.

Result: x value is 129 (0x81):
UART RBR contains at least one UART RX error
RBR contains valid data.
0 件の賞賛
返信

2,431件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by angle9 on Thu Jun 23 00:28:51 MST 2011
LSR register value is 0...:confused:
0 件の賞賛
返信

2,431件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jharwood on Thu Jun 23 00:01:33 MST 2011
Have you tried checking any of the other bits in the LSR register?  Like OE, PE or FE.
0 件の賞賛
返信

2,431件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by angle9 on Wed Jun 22 23:22:46 MST 2011
hi jharwood

thanks for the reply..

Change code

LPC_SYSCON->UART0CLKDIV =1;

Still same condition, MCU can not receive.

Is there any different the configuration of uart0 when use as ISP for downloading program and for uart0?

Because it's no problem when i program the MCU using Flash Magic.

My terminal program no use any modem control..
0 件の賞賛
返信

2,431件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jharwood on Wed Jun 22 22:52:39 MST 2011
No wait!

LPC_SYSCON->UART0CLKDIV    =  (2UL <<  0);


will divide 12Mhz by 2 = 6MHz

So your baud rate will be 14,423

Try setting UART0CLKDIV to 1 instead.
0 件の賞賛
返信

2,431件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jharwood on Wed Jun 22 22:36:03 MST 2011
Your code looks fine to me. Does your terminal program need a modem control line to be active, such as DSR, perhaps?
0 件の賞賛
返信