Elijah Orr

LPC11U24 UART baud rate divisor calculation - UM incorrect?

Discussion created by Elijah Orr on May 18, 2017

I have been writing some code to configure the LPC11U24 UART to send data at a rate of 1MHz. I had configured the UART registers according to the user manual, using some example code as a guide. However, no data would ever be output on the TX line, despite everything appearing to be configured correctly. After playing about with the code and using more of the example code it is now working, however I have discovered that the calculations in the user manual to calculate divisor latch values do not correlate with the calculation used in the now working code, and indeed some (but not all lpc open example code).

The user manual provides the following equation for calculating these values:

UART Baudrate formula

This is used in some (non-working?) example code that I was using at first in this code snippet, which is from LPC11Uxx_Driver_Lib uart.c:

Fdiv = ((SystemCoreClock/LPC_SYSCON->UARTCLKDIV)/16)/baudrate ; /*baud rate */ 
LPC_USART->DLM = Fdiv / 256;
LPC_USART->DLL = Fdiv % 256;

The fractional divider will not be used, so DivAddVal/MulVal will always be 0, therefore it is not considered in the code calculation. We can clearly see that the 16 in the denominator of the UM equation also appears in the code, which would all be fine, if this code actually gave the expected data speed.


In my system the system clock is set up at 48MHz, verified via clkout. In order to get the intended data speed I plugged 1000000 into the equation as my baud rate, which gives a divisor value of 3, however the working code sets this as 24 to give the correct data rate. This is calculated in the working code using a snippet from a different LPC open example, this time the UARTMaster program:

Fdiv = ((SystemCoreClock/regVal)/2)/baudrate ; /* baud rate */

LPC_USART->DLM = Fdiv / 256;
LPC_USART->DLL = Fdiv % 256;

The only difference here is that a value of 2 has been used in the calculation instead of the expected value of 16 used above. Nothing else is configured differently between the two, the second gives the correct data rate, while the first does not.


Am I missing something here or is the equation quoted in the user manual incorrect (and subsequently the example calculations)?