Dear colleagues,
I'm having trouble making a baud rate setting. I use communication with a UART at 115200 bps, but when I need to change the baud rate for another one, my code doesn't work. I can set the baudrate value only once, then I must restart the microcontroller to be able to change the baud rate. But I need to change the baud rate while running the firmware.
I really appreciate the help.
Chip_UART_SetBaud(LPC_UART1, baudrate);
/* Determines and sets best dividers to get a target bit rate */
uint32_t Chip_UART_SetBaud(LPC_USART_T *pUART, uint32_t baudrate)
{
uint32_t div, divh, divl, clkin;
/* Determine UART clock in rate without FDR */
clkin = Chip_Clock_GetRate(UART_BClock[Chip_UART_GetIndex(pUART)]);
div = clkin / (baudrate * 16);
/* High and low halves of the divider */
divh = div / 256;
divl = div - (divh * 256);
Chip_UART_EnableDivisorAccess(pUART);
Chip_UART_SetDivisorLatches(pUART, divl, divh);
Chip_UART_DisableDivisorAccess(pUART);
/* Fractional FDR alreadt setup for 1 in UART init */
return clkin / div;
}
已解决! 转到解答。
Hello @rubensjunior,
Could you please try to deinitialize the UART before changing the baudrate using Chip_UART_Deinit( )?
After the baudrate change, please re-initialize the module with Chip_UART_Init( ).
Regards, Raul.
Hello @rubensjunior,
Could you please try to deinitialize the UART before changing the baudrate using Chip_UART_Deinit( )?
After the baudrate change, please re-initialize the module with Chip_UART_Init( ).
Regards, Raul.