2017-05-20 12:25 PM
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 */&sharpdefine 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 */&sharpdefine UART_DIV_SAMPLING16(__PCLK__, __BAUD__) (((__PCLK__) + ((__BAUD__)/2U)) / (__BAUD__))So why is there a (__BAUD__)/2U) term in equations?
#baud-rate #stm32f02017-05-20 06:31 PM
>>So why is there a (__BAUD__)/2U) term in equations?
Think of it as adding 0.5 after the division, ie rounding up