LPCXPRESSO LPC1769 UART baudrate

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

LPCXPRESSO LPC1769 UART baudrate

1,514 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Zahoq on Sun Nov 02 04:17:06 MST 2014
Hello everyone!
I'm atempting to create own library with UART functions but i have problems with calculating baudrate. I found very useful example made by Superfred:
else if ( PortNum == 3 )
  {
  LPC_PINCON->PINSEL0 &= ~0x0000000F;
  LPC_PINCON->PINSEL0 |=  0x0000000A;  /* RxD3 is P0.1 and TxD3 is P0.0 */
  LPC_SC->PCONP |= 1<<4 | 1<<25; //Enable PCUART1
  /* By default, the PCLKSELx value is zero, thus, the PCLK for
all the peripherals is 1/4 of the SystemFrequency. */
  /* Bit 6~7 is for UART3 */
  pclkdiv = (LPC_SC->PCLKSEL1 >> 18) & 0x03;
  switch ( pclkdiv )
  {
  case 0x00:
  default:
  pclk = SystemCoreClock/4;
  break;
  case 0x01:
  pclk = SystemCoreClock;
  break;
  case 0x02:
  pclk = SystemCoreClock/2;
  break;
  case 0x03:
  pclk = SystemCoreClock/8;
  break;
  }
  LPC_UART3->LCR = 0x83;/* 8 bits, no Parity, 1 Stop bit */
  Fdiv = ( pclk / 16 ) / baudrate ;/*baud rate */
  LPC_UART3->DLM = Fdiv / 256;
  LPC_UART3->DLL = Fdiv % 256;
  LPC_UART3->LCR = 0x03;/* DLAB = 0 */
  LPC_UART3->FCR = 0x07;/* Enable and reset TX and RX FIFO. */

  NVIC_EnableIRQ(UART3_IRQn);

  LPC_UART3->IER = IER_RBR | IER_THRE | IER_RLS;/* Enable UART3 interrupt */
  }


Example above is for initiating UART3, i don't understand how DLL and DLM is calculated. For example PCLK is 12MHz and desired baudrate is 9600. so Fdiv=78,125, DLM then should be < 1 and DLL = 0?

If i get Fdiv 78.125 can i round it to 78 and asign to DLL so my final calculation will look like BR = PCLK/(16 * 78) with DLL=78 DLM = 0?
0 Kudos
Reply
3 Replies

836 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Zahoq on Mon Nov 03 16:29:39 MST 2014
Thank you for all your answers, now that's clear to me.
0 Kudos
Reply

836 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Superfred on Mon Nov 03 07:45:39 MST 2014
Hello Zahoq,

DLL=78 DLM = 0 looks OK and gives an relative error of 0.16% which should work.
See 17xx User Manual Chapter 14.4.12.1 for more details.
There you also can find a more complex algorithm for Baudrate calculation, but I never had problems with the above simpler algorithm (at 100MHZ).

Fred
0 Kudos
Reply

836 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by cfb on Mon Nov 03 04:16:31 MST 2014
The formulae are:
                   clock    
     baudrate =   -------  
                   divisor      

                       freq * mulVal
     clock =     -------------------------
                 16 * (mulVal + divAddVal)
                  
     divisor = DLM << 8 + DLL

Constraints:

     1 <= divAddVal <= 15
     divAddVal < mulVal
     2 <= mulVal <= 15
     divisor > 2

For your example the result with the lowest error code is:

PCLK: 12MHz  Baud:   9600  DLM: 0  DLL:  71  mulVal: 10  divAddVal:  1  Err: 3

This result was obtained by running the example Oberon program called CalcBaudRate that we supply with the Astrobe development system. A screenshot showing the output from the program with a range of clock speeds and baud rates can be seen here:

http://www.astrobe.com/M3Examples/ReadMe.htm


0 Kudos
Reply