[Stm32 study notes] - serial communication

Serial port settings General Procedure:
1, the serial clock enable, the GPIO clock enable
2, serial reset
3, GPIO port mode
4, the serial port parameters are initialized
(opening interrupts) 5, enable interrupts and initialize the NVIC
. 6, so that the serial port
7, writing interrupt handlers

Serial Clock Enable: in stm32f103, the serial clock has peripheral clock enable control register.
(Ps APB1ENR, APB2ENR)

Serial port baud rate settings: STM32 each port has a separate bit rate register USART_BRR, by setting the configuration register corresponding to the baud rate. Members register is described below.

All sixteen of the register high is set to 0, the low sixteen each represent an integer portion and a fractional part of the division factors.
STM32 baud rate is calculated as follows:

molecule is a serial clock (PCLK1 for USART2,3,4,5, PCLK2 for the USART1)
USARTDIV unsigned fixed point numbers.

As long as we get the value of USARTDIV, the baud rate can be obtained register
register USART1-> BRR values, in turn, we obtain USART1-> BRR value may be derived USARTDIV
value.

We assume that the serial port 1
to set the baud rate of 115200, and PCLK2 clock is 72Mhz. Thus, according to the above formula has:
USARTDIV = 72000000 / (115200 16) = 39.0625
DIV_Fraction = 16
0.625 = = 0X01. 1;
DIV_Mantissa = 39 = 0x27;
so, we get USART1-> BRR value 0X0271. Just set the serial register value BRR 1
0X0271 115200 baud rate can be obtained.

Serial control: Each serial port STM32F1 has three control registers USART_CR1 ~ 3
upper 16 bits of the register are not used, the function provided for the lower 16 bits of the serial port.
Low 16 Reference Manual Chinese

Guess you like

Origin www.cnblogs.com/Lingh/p/11768565.html