IRC with UART BAUDRATE 115200

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

IRC with UART BAUDRATE 115200

1,293 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tbelo on Sat Dec 14 08:16:44 MST 2013
Hi all,
My issue is that I can't make the uart to work @115200 with IRC oscillator.
Followed are my test results:
1) uart@115200 with XTAL (48000000) ---> OK
2) uart@ 9600    with XTAL (48000000) ---> OK
3) uart@ 9600    with IRC    (12000000) ---> OK
3) uart@ 115200with IRC    (12000000) ---> FAIL

Parts of the engaged code are:
@system_LPC11xx.h
#define CLOCK_SETUP           1
#define SYSCLK_SETUP          1
#define SYSOSC_SETUP          1
#define SYSOSCCTRL_Val        0x00000000
#define WDTOSC_SETUP          0
#define WDTOSCCTRL_Val        0x000000A0
#define SYSPLLCLKSEL_Val      0x00000001
#define SYSPLL_SETUP          1
#define SYSPLLCTRL_Val        0x00000023
#define MAINCLKSEL_Val        0x00000000
#define SYSAHBCLKDIV_Val      0x00000001
#define AHBCLKCTRL_Val        0x0001005F
#define SSP0CLKDIV_Val        0x00000001
#define UARTCLKDIV_Val        0x00000001
#define SSP1CLKDIV_Val        0x00000000

@uart_init (baudrate)
  LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12);
  LPC_SYSCON->UARTCLKDIV = 0x01;     /* divided by 1 */
  LPC_UART->LCR = 0x83;             /* 8 bits, no Parity, 1 Stop bit */
  regVal = LPC_SYSCON->UARTCLKDIV;
  Fdiv = (((SystemCoreClock*LPC_SYSCON->SYSAHBCLKDIV)/regVal)/16)/baudrate ;//i have experiment the 16 to 2,4,8... but no luck
  LPC_UART->DLM = Fdiv / 256;
  LPC_UART->DLL = Fdiv % 256;
  LPC_UART->LCR = 0x03;/* DLAB = 0 */
  LPC_UART->FCR = 0x07;/* Enable and reset TX and RX FIFO. */


Can you advice ?
Best regards
0 Kudos
Reply
2 Replies

1,211 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tbelo on Tue Dec 17 13:34:43 MST 2013
Thanks gbm,
I added the following at it works fine
  /* Enable UART clock */
  LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12);
  LPC_SYSCON->UARTCLKDIV = 0x01;     /* divided by 1 */
  LPC_UART->LCR = 0x83;             /* 8 bits, no Parity, 1 Stop bit */
  regVal = LPC_SYSCON->UARTCLKDIV;
  Fdiv = (((SystemCoreClock*LPC_SYSCON->SYSAHBCLKDIV)/regVal)/16)/baudrate ;/*baud rate */
  //Fdiv = (((SystemCoreClock*LPC_SYSCON->SYSAHBCLKDIV)/regVal)/16 + baudrate/2)/baudrate;
  LPC_UART->DLM = 0;
  LPC_UART->DLL = 4;
  LPC_UART->FDR = 0x85;

  LPC_UART->LCR = 0x03;/* DLAB = 0 */
  LPC_UART->FCR = 0x07;/* Enable and reset TX and RX FIFO. */


0 Kudos
Reply

1,211 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gbm on Sat Dec 14 12:31:00 MST 2013
Your problem is not related to IRC, but to system clock frequency. If you don't use fractional divider, you get approx. 8% error in baud rate at 12 MHz. Either increase your clock frequency to 24 MHz using PLL, or use the fractional divider.
0 Kudos
Reply