STM32F031+串口中断串口中断+DMA发送发送
一、一、GPIO配置配置
上一篇博文已经介绍了F0和F1系列的不同点,这里不再赘述,先上代码:
这里给出相关文档的下载路径:
链接: STM32F031G4中文编程手册.
/*GPIOA初始化配置 */
void GPIOA_Config()
{
GPIO_InitTypeDef GPIO_InitStructure;
/*初始化GPIOA时钟*/
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
/*复用 AF1,看手册*/
GPIO_PinAFConfig(GPIOA,GPIO_PinSource8,GPIO_AF_1);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_1);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_1);
/* 配置PA9 ,PA10 串口*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //设置端口复用
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;/* 推挽输出或开漏输出 */
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; /* 无、上拉或下拉 */
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3;//50MHZ
GPIO_Init(GPIOA, &GPIO_InitStructure);
/*485使能引脚*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_ResetBits(GPIOA, GPIO_Pin_8);//初始化GPIOA8为低电平
}
这里在上一篇文章说过,GPIO要配置成复用功能映射表,此处补充一张复用图:
二、二、USART配置配置
/*串口初始化配置 */
void USART_Config(void)
{
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/*初始化USART1时钟*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
USART_InitStructure.USART_BaudRate = 2500000;//设置串口波特率
评论0