I'm using below LPCOPEN based codes for configging UART on my LPC812.
for normal baud rate below 115200(most usual) it works fine,but when i set a custom baud rate like(115200 *2) or
(115200 *n) it does not work either.whats problem?
//---UART Initialing---------------------------------
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM);
/* Divided by 1 */
Chip_Clock_SetUARTClockDiv(1);
/* Connect the U0_TXD_O and U0_RXD_I signals to port pins(P0.4, P0.0) */
Chip_SWM_DisableFixedPin(4);
Chip_SWM_MovablePinAssign(SWM_U1_TXD_O, 4);
Chip_SWM_MovablePinAssign(SWM_U1_RXD_I, 0);
/* Disable the clock to the Switch Matrix to save power */
//Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM);
Chip_UART_Init(LPC_USART1);
Chip_UART_ConfigData(LPC_USART1, UART_CFG_DATALEN_8 | UART_CFG_PARITY_NONE | UART_CFG_STOPLEN_1);
Chip_Clock_SetUSARTNBaseClockRate((115200 * 16), true);
Chip_UART_SetBaud(LPC_USART1, 115200);
Chip_UART_Enable(LPC_USART1);
Chip_UART_TXEnable(LPC_USART1);
I can see two options to get to higher baud rates:
Hi Mahmond,
I am not expert but a quick testing using LPCOpen for LPC812MAX board and Example_UART0_Terminal example shows the core clock is set to 24MHz and default baud is 9600.
Changing the BRG value from 155 to 12 allowed the baud to work successfully at 115200.
But trying to double it to 230400 baud did not work (I set BRG=5). But I believe the reason is too much error as the calculated BRG was 5.5 and rounding it to nearest integer didn't work. However increasing to 249600 baud had calculated BRG ~5 and that worked fine for me using Putty as my PC terminal utility.
// Configure the USART0 baud rate generator
LPC_USART0->BRG = 5; //DES was 155; 155 for 9600 baud and 12 for 115200 baud, 10 for 134400 baud
//DES 9 for 153600, 7 for 192000 baud, 6 for 211200 baud, 5(5.5 calculated) for 230400 baud...NOT WORKING
//DES 5 for 249600 baud....WORKING
//DES Summary: Too much error in UART clock config when core at 24MHz to achieve 2*115200 baud.
Regards,
David
Dear David,
Really thanks for your great help,
is there any calculator tools which be able to calculate register values & error for custom baud rates?
Hi Mahmoud,
You are welcome.
Sorry there is no calculator that I know of.
Regards,
David