LPC11U24 UART baud rate divisor calculation - UM incorrect?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

LPC11U24 UART baud rate divisor calculation - UM incorrect?

2,498 次查看
elijah
Contributor III

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:

baudratecalc.PNG

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:

regVal = LPC_SYSCON->UARTCLKDIV;
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)? 

标记 (4)
0 项奖励
回复
1 回复

1,677 次查看
elijah
Contributor III

So I discovered the issue, I had synchronous mode enabled at some point during the debugging process, which has the effect of making the bit rate 8x faster with all other configuration the same. I'm not sure why this is and I'm not sure why there is a difference in how the UART speed is decided, I can't seem to find anything in the user manual.

But yeah, the calculation is correct for asynchronous mode, but not synchronous. As for the code differences, one was for asynchronous operation the other for synchronous. I'm not sure why my code didn't work initially, but something fixed it. 

0 项奖励
回复