stm32f103rct6引脚串口使能初始化
时间: 2023-09-14 07:05:07 浏览: 101
对于这个问题,我可以为您提供一个简单的初始化代码,以使能STM32F103RCT6的串口引脚:
```c
#include "stm32f103xx.h"
void USART1_Init(void)
{
RCC->APB2ENR |= RCC_APB2ENR_USART1EN; // enable USART1 clock
RCC->APB2ENR |= RCC_APB2ENR_IOPAEN; // enable GPIOA clock
GPIOA->CRH |= GPIO_CRH_MODE9_0; // set PA9 as TX pin
GPIOA->CRH |= GPIO_CRH_CNF9_1; // set PA9 as AF push-pull
GPIOA->CRH |= GPIO_CRH_MODE10_0; // set PA10 as RX pin
GPIOA->CRH &= ~GPIO_CRH_CNF10; // set PA10 as input floating
USART1->BRR = 72000000/9600; // set baud rate
USART1->CR1 |= USART_CR1_TE | USART_CR1_RE; // enable transmit and receive
USART1->CR1 |= USART_CR1_UE; // enable USART1
}
```
请注意,这只是一个简单的初始化代码示例,如果您需要更复杂的串口通信功能,请寻求其他可靠的资源并适当修改代码。
阅读全文