AnsweredAssumed Answered

STM32F0 Baud rate calculation macro

Question asked by cctt on May 20, 2017
Latest reply on May 21, 2017 by Clive One

From STM32F0xx_hal_uart.h


/** @brief BRR division operation to set BRR register in 8-bit oversampling mode.
* @param __PCLK__: UART clock.
* @param __BAUD__: Baud rate set by the user.
* @retval Division result
*/
#define UART_DIV_SAMPLING8(__PCLK__, __BAUD__) ((((__PCLK__)*2U) + ((__BAUD__)/2U)) / (__BAUD__))

/** @brief BRR division operation to set BRR register in 16-bit oversampling mode.
* @param __PCLK__: UART clock.
* @param __BAUD__: Baud rate set by the user.
* @retval Division result
*/
#define UART_DIV_SAMPLING16(__PCLK__, __BAUD__) (((__PCLK__) + ((__BAUD__)/2U)) / (__BAUD__))

STM32F0 Baud rate calculation

 

So why is there a (__BAUD__)/2U) term in equations?

 

Outcomes