void UART2_Init(void)
{
UART2_CR1 = 0x00; // Set word length bit[5:4] --- 8 bit : 0x00
// --- 9 bit : 0x10
// Set Parity Control bit [2:1] --- 0x00 : No Parity
// --- 0x04 : Even Parity
// --- 0x06 : Odd Parity
UART2_CR3 = 0x0; // Set the STOP bits
// 1 bit = 0x00
// 0.5 bit = 0x10
// 2 bit = 0x20
// 1.5 bit = 0x30
// Set the UART1 BRR1 and BRR2 according to UART1_BaudRate value:
// 8000000 / 9600 = 341H
// 8000000 / 115200 = 45H
UART2_BRR2 = 0x04;
UART2_BRR1 = 0x05;
UART2_CR2 |= 0x0C; // Enable Transmit and Receive
// UART2_CR2 |= 0x0A; // Enable Transmit and Receive Interrupt
// Set the Clock Enable bit, lock Polarity, lock Phase and Last Bit Clock pulse bits according to UART1_Mode value
UART2_CR3 |= 0x08;
}
|