stm32f103zet6串口初始化代码
时间: 2023-09-18 15:14:34 浏览: 127
STM32F103ZET6串口配置.doc
以下是使用STM32CubeMX生成的代码,用于初始化STM32F103ZET6的USART1串口:
```c
/* USART1 init function */
void MX_USART1_UART_Init(void)
{
huart1.Instance = USART1;
huart1.Init.BaudRate = 115200;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&huart1) != HAL_OK)
{
Error_Handler();
}
}
```
在主函数中调用`MX_USART1_UART_Init()`即可完成串口的初始化。
阅读全文