LPC11C24  about   uart

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC11C24  about   uart

324 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by wzq121381 on Tue Nov 05 07:46:08 MST 2013
This  is  my  code,I  want  to  send   01 05 00 02 FF 00 2D FA  then  the  led  is  lighten,and  then  01 05 00 02 00 00 6C 0A,the 
led  is  dark.  after   i  download  the  code  ,the  result  is  not  the  same  as  i  hope .can  you  help me?

#include "driver_config.h"

#include "target_config.h"
#include "gpio.h"

#include "uart.h"

extern volatile uint32_t UARTCount;
extern volatile uint8_t UARTBuffer[BUFSIZE];

int main (void)
{

  UARTInit(9600);
SystemInit();

GPIOSetDir(2,10,1);

  while (1)
  {/* Loop forever */
if ( (UARTBuffer[0]==0x01)&&(UARTBuffer[1]==0x05)&&(UARTBuffer[2]==0x00)&&(UARTBuffer[3]==0x02)&&(UARTBuffer[4]==0xff)&&(UARTBuffer[5]==0x00)&&(UARTBuffer[6]==0x2d)&&(UARTBuffer[7]==0xfa) )
{
LPC_UART->IER = IER_THRE | IER_RLS;/* Disable RBR */
UARTSend( (uint8_t *)UARTBuffer, UARTCount );
GPIOSetValue(2,10,1);

UARTCount = 0;
  LPC_UART->IER = IER_THRE | IER_RLS | IER_RBR;/* Re-enable RBR */
}
else if ( (UARTBuffer[0]==0x01)&&(UARTBuffer[1]==0x05)&&(UARTBuffer[2]==0x00)&&(UARTBuffer[3]==0x02)&&(UARTBuffer[4]==0x00)&&(UARTBuffer[5]==0x00)&&(UARTBuffer[6]==0x6c)&&(UARTBuffer[7]==0x0a) )
{
  LPC_UART->IER = IER_THRE | IER_RLS;/* Disable RBR */
UARTSend( (uint8_t *)UARTBuffer, UARTCount );
  GPIOSetValue(2,10,0);

UARTCount = 0;
LPC_UART->IER = IER_THRE | IER_RLS | IER_RBR;/* Re-enable RBR */
}

  }

}

Original Attachment has been moved to: uart.zip

Labels (1)
0 Kudos
3 Replies

250 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by wzq121381 on Thu Nov 07 06:44:58 MST 2013
thank you  for  the  answer,I  have  no via Paypal  in China,so  i  can  not  pay  you.sorry
0 Kudos

250 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by liaochengyi on Tue Nov 05 08:52:01 MST 2013
Using the debug mode, Learning to set break point at the need checked point.

And check the value of variable: UARTBuffer[].

Are you sure that code can go in if loop?

You can add else{GPIOSetValue(2,10,1);} at the least position.

I think that uart receive has some problem.
0 Kudos

250 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by capiman on Tue Nov 05 08:45:49 MST 2013
Hello wzq121381,

have you checked if UARTCount is incremented when a character was received?
Have you checked (or printed) bytes you have received? Are they correct?

One possible problem in your code is, when you receive one wrong character, e.g. at the beginning, you are out of sync.

Example:
UARTBuffer[0] gets filled with 0x55 (by error). Now you can send your packets as long as you want, you will never get back to control your LED.

Perhaps check byte by byte. Each time you receive a wrong byte (e.g. first byte is not 0x01), reset UARTCounter, so you are ready to receive a new packet.
Other way could be to use a timer. When you received no byte for x seconds, reset UARTCounter back to 0.

Best regards,

Martin

0 Kudos