芯片型号是STM32L431,写一个操作寄存器初始化串口3的函数。传输模式是USART_CR1_TE,配置为波特率为115200的8N1模式
时间: 2024-05-15 22:18:20 浏览: 144
好的,下面是操作寄存器初始化串口3的函数代码:
```c
void init_USART3(void)
{
// 使能 USART3 时钟
RCC->APB1ENR1 |= RCC_APB1ENR1_USART3EN;
// 配置 GPIO PB10 和 PB11 作为 USART3 的 TX 和 RX 引脚
GPIOB->MODER &= ~(GPIO_MODER_MODE10 | GPIO_MODER_MODE11);
GPIOB->MODER |= (GPIO_MODER_MODE10_1 | GPIO_MODER_MODE11_1);
GPIOB->AFR[1] |= (7 << GPIO_AFRH_AFSEL10_Pos) | (7 << GPIO_AFRH_AFSEL11_Pos);
// 配置 USART3 Control Register 1
USART3->CR1 &= ~(USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | USART_CR1_OVER8);
USART3->CR1 |= USART_CR1_TE;
// 配置 USART3 Control Register 2
USART3->CR2 &= ~USART_CR2_STOP;
// 配置 USART3 Control Register 3
USART3->CR3 &= ~(USART_CR3_CTSE | USART_CR3_RTSE);
// 配置 USART3 Baud Rate Register
USART3->BRR = (SystemCoreClock / 115200);
// 使能 USART3
USART3->CR1 |= USART_CR1_UE;
}
```
这个函数会使能 STM32L431 的 USART3,配置 PB10 和 PB11 作为 USART3 的 TX 和 RX 引脚,以及配置相应的寄存器,实现 115200 的波特率和 8N1 的数据传输模式。
阅读全文
相关推荐


















