LPC1766 UART send garbled

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

LPC1766 UART send garbled

514 Views
125621365
Contributor I

My code is below, when i run this code, I received the data like the picture. Anyone can tell me why?

Receive baudrate is 9600. Use TTL-USB connect to my computer. 

int main(void)
{
uint32_t i,j, k=0;

SystemInit();
UART0_Init(9600);

UART0_SendString("hello world");
Delay(250);
}

#define FOSC                        12000000 

#define FCCLK                      (FOSC  * 8)

#define FCCO                       (FCCLK * 3)

#define FPCLK                      (FCCLK / 4)

void UART0_Init (uint32_t baudrate)
{
uint16_t usFdiv;
/* UART0 */
LPC_PINCON->PINSEL0 |= (1 << 4);
LPC_PINCON->PINSEL0 |= (1 << 6);

LPC_UART0->LCR = 0x83;
usFdiv = (FPCLK / 16) / baudrate;
LPC_UART0->DLM = usFdiv / 256;
LPC_UART0->DLL = usFdiv % 256;
LPC_UART0->LCR = 0x03;
LPC_UART0->FCR = 0x06;
}

pastedImage_2.png

Labels (2)
0 Kudos
2 Replies

416 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Teng,

Regarding your question, I suppose that the incorrect baudrate leads to the issue.

From the code, it seems that the oscillator clock frequency is 12MHz, the cpu core clock frequency FCCLK is 12*8=96MHz, the uart0 driving clock frequency FPCLK is 96MHz/4=24MHz.

Pls confirm whether the peripheral clock is 24MHz, you can output FCCLK signal to CLKOUT pin and use scope to measure the frequency.

usFdiv = (FPCLK / 16) / baudrate;
LPC_UART0->DLM = usFdiv / 256; //LPC_UART0->DLM = usFdiv>>8;
LPC_UART0->DLL = usFdiv&0xFF;

BTW, I suppose you have to write the

PCLKSEL0&=~(0x03<<6); //select FCLK/4

Hope it can help you

BR

XiangJun Rong

0 Kudos

416 Views
125621365
Contributor I

Thank you for your reply, I solved this problem. I used TTL to USB to receive the messages, but there is a MAX232 chip translate the signal to RS232. So when I used RS232 to USB then the data  is normal. 

0 Kudos