cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F0 Baud rate calculation macro

zubizeratta
Associate II
Posted on May 20, 2017 at 21:25

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__))0690X000006073zQAA.png

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

#baud-rate #stm32f0
1 REPLY 1
Posted on May 21, 2017 at 03:31

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

Think of it as adding 0.5 after the division, ie rounding up

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..