Serial port and baud rate pclk2 in the end what is the relationship?

2019-06-05
Why register version, serial port initialization function takes two parameters, pclk2 and bound,
while the library function version, only bound one parameter:

The following consolidation from the register version of the Developer's Guide:

The baud rate is calculated

When OVER8 = 0 when


15426916-f6d7bbe9d17985ff.png
image.png
  • Tx / Rx is the baud rate?
  • fPCLKx is a serial clock
    • PCLK1 for USART2 ~ 5
    • PCLK2 for USART1 and USART6
  • USARTDIV is a fixed-point unsigned

Baud Rate Register USART_BRR

Each serial port has STM32F4 baud rate register USART_BRR ,
32 bits, the upper 16 bits are reserved

15426916-b8a66461c181e307.png
image.png

  • mantissa is the integer part
  • fraction is the fractional part * 16 (OVER8 = 0 when multiplied when multiplied by 16, OVER8 = 1 do not know how much)

Baud Rate Calculation Example

1 is assumed to be set as the serial baud rate of 115200, and PCLK2 clock (i.e. APB2 bus clock frequency) of 84M
find USARTDIV

USARTDIV
= fpCLK2 / 16 / baud
= 84000000/16/115200
= 45.572
Therefore,
the integer part of 45, DIV_Mantissa = 45 = 0x2D
fractional part of 0.572, DIV_Fraction = 0.572 * 16 = 9.152 = 0x09

OVER8 bit

The receiver set bit Oversampling: OVER8 bit,
the bit is set in a register inside USART_CR1,
when OVER8 = 0 when using the 16-times oversampling, can increase the tolerance of the receiver clock, high precision, good fault tolerance.
When OVER8 = 1 when a higher speed can be obtained.
We generally set OVER8 = 0, for better fault tolerance, begin with the following OVER8 = 0 are introduced.
For more information about OVER8, see "STM32F4xx Chinese Reference Manual", Section 26.3.3.

in conclusion

The baud rate is plk and values of some other register together determine the
exact, baud rate, the baud rate register USART_BRR, and the corresponding clock frequency is determined by USART_CR1 pclk register of OVER8 bit above formula .
Version register, the value of pclk as parameters involved in the calculation passed in
the library function version, the clock frequency may be obtained by other means, it is possible to set the baud rate directly
i.e.
// libraries Edition void uart_init (u32 bound)
void uart_init (u32 pclk2, u32 bound ) // Version register
these two functions, when bound as parameters, can be considered the effect is equivalent to

Reproduced in: https: //www.jianshu.com/p/cb35cb921a4a

Guess you like

Origin blog.csdn.net/weixin_34236869/article/details/91081621