欢迎来到天天文库
浏览记录
ID:37711876
大小:36.50 KB
页数:4页
时间:2019-05-29
《STM32的串口中断配置》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、STM32的串口中断配置,也是很简单的.首先是配置UART的GPIO口/********************************************************************************Name:UART1_GPIO_Configuration*Deion:Configurestheuart1GPIOports.*Input:None*Output:None*Return:None********************************************************
2、***********************/voidUART1_GPIO_Configuration(void){GPIO_InitTypeDefGPIO_InitStructure;//ConfigureUSART1_Txasalternatepush-pullGPIO_InitStructure.GPIO_Pin=GPIO_Pin_9;GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;GPIO_I
3、nit(GPIOA,&GPIO_InitStructure);//ConfigureUSART1_RxasinputfloatingGPIO_InitStructure.GPIO_Pin=GPIO_Pin_10;GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;GPIO_Init(GPIOA,&GPIO_InitStructure);}然后是配置串口参数/******************************************************************
4、**************Name:UART1_Configuration*Deion:Configurestheuart1*Input:None*Output:None*Return:None*******************************************************************************/voidUSART_Configuration(void){USART_InitTypeDefUSART_InitStructure;USART_ClockInitTypeDefUSAR
5、T_ClockInitStructure;Uart1_GPIO_Configuration();USART_ClockInitStructure.USART_Clock=USART_Clock_Disable;USART_ClockInitStructure.USART_CPOL=USART_CPOL_Low;USART_ClockInitStructure.USART_CPHA=USART_CPHA_2Edge;USART_ClockInitStructure.USART_LastBit=USART_LastBit_Disable;/
6、*ConfiguretheUSART1synchronousparamters*/USART_ClockInit(USART1,&USART_ClockInitStructure);USART_InitStructure.USART_BaudRate=9600;USART_InitStructure.USART_WordLength=USART_WordLength_8b;USART_InitStructure.USART_StopBits=USART_StopBits_1;USART_InitStructure.USART_Parit
7、y=USART_Parity_No;USART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None;USART_InitStructure.USART_Mode=USART_Mode_Rx
8、USART_Mode_Tx;/*ConfigureUSART1basicandasynchronousparamters*/USART_Init(USART1,&USART_InitStructure);/*EnableUSART1Receiveinterrup
9、ts*/USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);/*EnableUSART1*/USART_Cmd(USART1,ENABLE);}然后是在中断设置,需要修改
此文档下载收益归作者所有