最近项目需要用上了stm32f0系列的030cct6,有六个串口,调试配置六路串口的时候总是发现进入异常中断,然后一个个排除,发现仅有串口1和串口2进入接收中断并清除中断标志,串口3到串口6都无法进入接收中断清除中断标志。其后追到中断向量表,惊奇的发现竟然没有串口3到串口6的中断函数,百思不得其解,求各路大神帮帮忙
部分代码如下
void uart_init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA|RCC_AHBPeriph_GPIOB, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_USART6,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2|RCC_APB1Periph_USART3|RCC_APB1Periph_USART4|RCC_APB1Periph_USART5,ENABLE);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9,GPIO_AF_1);//引脚复用配置
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10,GPIO_AF_1);//引脚复用配置.....1
GPIO_PinAFConfig(GPIOA, GPIO_PinSource0,GPIO_AF_4);//引脚复用配置
GPIO_PinAFConfig(GPIOA, GPIO_PinSource1,GPIO_AF_4);//引脚复用配置.....4
GPIO_PinAFConfig(GPIOB, GPIO_PinSource10,GPIO_AF_4);//引脚复用配置
GPIO_PinAFConfig(GPIOB, GPIO_PinSource11,GPIO_AF_4);//引脚复用配置.....3
GPIO_PinAFConfig(GPIOA, GPIO_PinSource2,GPIO_AF_1);//引脚复用配置
GPIO_PinAFConfig(GPIOA, GPIO_PinSource3,GPIO_AF_1);//引脚复用配置.....2
GPIO_PinAFConfig(GPIOB, GPIO_PinSource3,GPIO_AF_4);//引脚复用配置
GPIO_PinAFConfig(GPIOB, GPIO_PinSource4,GPIO_AF_4);//引脚复用配置.....5
GPIO_PinAFConfig(GPIOA, GPIO_PinSource4,GPIO_AF_5);//引脚复用配置
GPIO_PinAFConfig(GPIOA, GPIO_PinSource5,GPIO_AF_5);//引脚复用配置.....6
//USART1_TX GPIOA.9
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//输入GPIO_Mode_IN、输出GPIO_Mode_OUT、GPIO_Mode_AF复用功能、GPIO_Mode_AN模拟功能
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推完输出GPIO_OType_PP、漏极输出GPIO_OType_OD
GPIO_Init(GPIOA, &GPIO_InitStructure);
//USART1_RX GPIOB.10
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//输入GPIO_Mode_IN、输出GPIO_Mode_OUT、GPIO_Mode_AF复用功能、GPIO_Mode_AN模拟功能
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;//GPIO_PuPd上下拉: 浮空GPIO_PuPd_NOPULL、上拉GPIO_PuPd_UP、下拉GPIO_PuPd_DOWN
GPIO_Init(GPIOA, &GPIO_InitStructure);
//USART4_TX GPIOA.0
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//输入GPIO_Mode_IN、输出GPIO_Mode_OUT、GPIO_Mode_AF复用功能、GPIO_Mode_AN模拟功能
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推完输出GPIO_OType_PP、漏极输出GPIO_OType_OD
GPIO_Init(GPIOA, &GPIO_InitStructure);
//USART4_RX GPIOB.1
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//输入GPIO_Mode_IN、输出GPIO_Mode_OUT、GPIO_Mode_AF复用功能、GPIO_Mode_AN模拟功能
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;//GPIO_PuPd上下拉: 浮空GPIO_PuPd_NOPULL、上拉GPIO_PuPd_UP、下拉GPIO_PuPd_DOWN
GPIO_Init(GPIOA, &GPIO_InitStructure);
//USART3_TX GPIOB.10
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//输入GPIO_Mode_IN、输出GPIO_Mode_OUT、GPIO_Mode_AF复用功能、GPIO_Mode_AN模拟功能
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推完输出GPIO_OType_PP、漏极输出GPIO_OType_OD
GPIO_Init(GPIOB, &GPIO_InitStructure);
//USART3_RX GPIOB.11
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//输入GPIO_Mode_IN、输出GPIO_Mode_OUT、GPIO_Mode_AF复用功能、GPIO_Mode_AN模拟功能
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;//GPIO_PuPd上下拉: 浮空GPIO_PuPd_NOPULL、上拉GPIO_PuPd_UP、下拉GPIO_PuPd_DOWN
GPIO_Init(GPIOB, &GPIO_InitStructure);
//USART2_TX GPIOA.2
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//输入GPIO_Mode_IN、输出GPIO_Mode_OUT、GPIO_Mode_AF复用功能、GPIO_Mode_AN模拟功能
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推完输出GPIO_OType_PP、漏极输出GPIO_OType_OD
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;//GPIO_PuPd上下拉: 浮空GPIO_PuPd_NOPULL、上拉GPIO_PuPd_UP、下拉GPIO_PuPd_DOWN
GPIO_Init(GPIOA, &GPIO_InitStructure);
//USART2_RX GPIOA.3
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//输入GPIO_Mode_IN、输出GPIO_Mode_OUT、GPIO_Mode_AF复用功能、GPIO_Mode_AN模拟功能
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;//GPIO_PuPd上下拉: 浮空GPIO_PuPd_NOPULL、上拉GPIO_PuPd_UP、下拉GPIO_PuPd_DOWN
GPIO_Init(GPIOA, &GPIO_InitStructure);
//USART5_TX GPIOB.3
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//输入GPIO_Mode_IN、输出GPIO_Mode_OUT、GPIO_Mode_AF复用功能、GPIO_Mode_AN模拟功能
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推完输出GPIO_OType_PP、漏极输出GPIO_OType_OD
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;//GPIO_PuPd上下拉: 浮空GPIO_PuPd_NOPULL、上拉GPIO_PuPd_UP、下拉GPIO_PuPd_DOWN
GPIO_Init(GPIOB, &GPIO_InitStructure);
//USART5_RX GPIOB.4
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//输入GPIO_Mode_IN、输出GPIO_Mode_OUT、GPIO_Mode_AF复用功能、GPIO_Mode_AN模拟功能
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;//GPIO_PuPd上下拉: 浮空GPIO_PuPd_NOPULL、上拉GPIO_PuPd_UP、下拉GPIO_PuPd_DOWN
GPIO_Init(GPIOB, &GPIO_InitStructure);
//USART6_TX GPIOA.4
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//输入GPIO_Mode_IN、输出GPIO_Mode_OUT、GPIO_Mode_AF复用功能、GPIO_Mode_AN模拟功能
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推完输出GPIO_OType_PP、漏极输出GPIO_OType_OD
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;//GPIO_PuPd上下拉: 浮空GPIO_PuPd_NOPULL、上拉GPIO_PuPd_UP、下拉GPIO_PuPd_DOWN
GPIO_Init(GPIOA, &GPIO_InitStructure);
//USART6_RX GPIOA.5
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//输入GPIO_Mode_IN、输出GPIO_Mode_OUT、GPIO_Mode_AF复用功能、GPIO_Mode_AN模拟功能
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;//GPIO_PuPd上下拉: 浮空GPIO_PuPd_NOPULL、上拉GPIO_PuPd_UP、下拉GPIO_PuPd_DOWN
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = 115200;//串口波特率
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字长为8位数据格式
USART_InitStructure.USART_StopBits = USART_StopBits_1;//一个停止位
USART_InitStructure.USART_Parity = USART_Parity_No;//无奇偶校验位
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件数据流控制
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //收发模式
USART_Init(USART1, &USART_InitStructure);
USART_InitStructure.USART_BaudRate = 115200;//串口波特率
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字长为8位数据格式
USART_InitStructure.USART_StopBits = USART_StopBits_1;//一个停止位
USART_InitStructure.USART_Parity = USART_Parity_No;//无奇偶校验位
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件数据流控制
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //收发模式
USART_Init(USART4, &USART_InitStructure);
USART_InitStructure.USART_BaudRate = 115200;//串口波特率
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字长为8位数据格式
USART_InitStructure.USART_StopBits = USART_StopBits_1;//一个停止位
USART_InitStructure.USART_Parity = USART_Parity_No;//无奇偶校验位
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件数据流控制
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //收发模式
USART_Init(USART3, &USART_InitStructure);
USART_InitStructure.USART_BaudRate = 115200;//串口波特率
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字长为8位数据格式
USART_InitStructure.USART_StopBits = USART_StopBits_1;//一个停止位
USART_InitStructure.USART_Parity = USART_Parity_No;//无奇偶校验位
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件数据流控制
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //收发模式
USART_Init(USART2, &USART_InitStructure);
USART_InitStructure.USART_BaudRate = 115200;//串口波特率
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字长为8位数据格式
USART_InitStructure.USART_StopBits = USART_StopBits_1;//一个停止位
USART_InitStructure.USART_Parity = USART_Parity_No;//无奇偶校验位
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件数据流控制
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //收发模式
USART_Init(USART5, &USART_InitStructure);
USART_InitStructure.USART_BaudRate = 115200;//串口波特率
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字长为8位数据格式
USART_InitStructure.USART_StopBits = USART_StopBits_1;//一个停止位
USART_InitStructure.USART_Parity = USART_Parity_No;//无奇偶校验位
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件数据流控制
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //收发模式
USART_Init(USART6, &USART_InitStructure);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);//开启串口接受中断
USART_ITConfig(USART4, USART_IT_RXNE, ENABLE);//开启串口接受中断
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);//开启串口接受中断
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);//开启串口接受中断
USART_ITConfig(USART5, USART_IT_RXNE, ENABLE);//开启串口接受中断
USART_ITConfig(USART6, USART_IT_RXNE, ENABLE);//开启串口接受中断
USART_Cmd(USART1, ENABLE);
USART_Cmd(USART4, ENABLE);
USART_Cmd(USART3, ENABLE);
USART_Cmd(USART2, ENABLE);
USART_Cmd(USART5, ENABLE);
USART_Cmd(USART6, ENABLE);
//NVIC----TIM.c
}
void Nvic_Init(void) //中断优先级设置
{
NVIC_InitTypeDef NVIC_InitStructure;
/*******************Tim3中断优先级设定**************************系统**/
NVIC_InitStructure.NVIC_IRQChannel=TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/*******************USART1中断优先级设定***********************SENSOR**/
NVIC_InitStructure.NVIC_IRQChannel=USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/*******************USART2中断优先级设定***********************SENSOR**/
NVIC_InitStructure.NVIC_IRQChannel=USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/*******************USART3中断优先级设定**************************UWB**/
NVIC_InitStructure.NVIC_IRQChannel=USART3_6_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void USART1_IRQHandler (void)
{
uint16_t temp;
if(USART_GetITStatus(USART1,USART_IT_RXNE)!= RESET) //Receive Data register not empty interrupt.
{
USART_ClearITPendingBit(USART1,USART_IT_RXNE);
temp = USART_ReceiveData(USART1);
//USART_SendData(USART1,temp);
}
}
void USART2_IRQHandler (void)
{
uint16_t temp;
if(USART_GetITStatus(USART2,USART_IT_RXNE)!= RESET) //Receive Data register not empty interrupt.
{
USART_ClearITPendingBit(USART2,USART_IT_RXNE);
temp = USART_ReceiveData(USART2);
//USART_SendData(USART2,temp);
}
}
void USART3_IRQHandler (void)
{
uint16_t temp;
if(USART_GetITStatus(USART3,USART_IT_RXNE)!= RESET) //Receive Data register not empty interrupt.
{
USART_ClearITPendingBit(USART3,USART_IT_RXNE);
temp = USART_ReceiveData(USART3);
//USART_SendData(USART3,temp);
}
}
void USART4_IRQHandler (void)
{
uint16_t temp;
if(USART_GetITStatus(USART4,USART_IT_RXNE)!= RESET) //Receive Data register not empty interrupt.
{
USART_ClearITPendingBit(USART4,USART_IT_RXNE);
temp = USART_ReceiveData(USART4);
//USART_SendData(USART4,temp);
}
}
void USART5_IRQHandler (void)
{
uint16_t temp;
if(USART_GetITStatus(USART5,USART_IT_RXNE)!= RESET) //Receive Data register not empty interrupt.
{
USART_ClearITPendingBit(USART5,USART_IT_RXNE);
temp = USART_ReceiveData(USART5);
//USART_SendData(USART5,temp);
}
}
void USART6_IRQHandler (void)
{
uint16_t temp;
if(USART_GetITStatus(USART6,USART_IT_RXNE)!= RESET) //Receive Data register not empty interrupt.
{
USART_ClearITPendingBit(USART6,USART_IT_RXNE);
temp = USART_ReceiveData(USART6);
//USART_SendData(USART6,temp);
}
}
i have configures properly and also the peripherals clock but still not working
Below i have attached the my program configuration
i have configures properly and also the peripherals clock but still not working
Below i have attached the my program configuration
[mw_shl_code=c,true]#include "main.h"
Void USART_Configuration(void);
Void USART1_Configuration(void);
Void USART2_Configuration(void);
Void USART3_Configuration(void);
Void USART4_Configuration(void);
Void USART5_Configuration(void);
USART1_Configuration void (void)
{
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHBPeriphClockCmd (RCC_AHBPeriph_GPIOA, the ENABLE);
RCC_APB2PeriphClockCmd (RCC_APB2Periph_USART1, the ENABLE);
GPIO_PinAFConfig (with GPIOA, GPIO_PinSource9, GPIO_AF_1);
GPIO_PinAFConfig (with GPIOA, GPIO_PinSource10, GPIO_AF_1);
/ * The Configure the USART1 pins: the Rx and the Tx ---------------------------- * /
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed GPIO_Speed_50MHz =;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init (with GPIOA, & GPIO_InitStructure);
/ * * the Enable the USART1 the IRQ /
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
NVIC_InitStructure .NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
USART_InitStructure.USART_BaudRate = 9600;
= USART_WordLength_8b USART_InitStructure.USART_WordLength;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init (the USART1, & USART_InitStructure);
USART_Cmd (the USART1, the ENABLE);
USART_ITConfig (the USART1, USART_IT_TXE, ENABLE);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
}
Void USART2_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHBPeriphClockCmd (RCC_AHBPeriph_GPIOA, the ENABLE);
RCC_APB1PeriphClockCmd (RCC_APB1Periph_USART2, the ENABLE);
GPIO_PinAFConfig (with GPIOA, GPIO_PinSource2, GPIO_AF_1);
GPIO_PinAFConfig (with GPIOA, GPIO_PinSource3, GPIO_AF_1);
/ * the Configure USART2 is always pins: the Rx and the Tx --------- * ------------------- /
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure .GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Enable USART2 IRQ */
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
= 0 NVIC_InitStructure.NVIC_IRQChannelPriority;
NVIC_InitStructure.NVIC_IRQChannelCmd = the ENABLE;
NVIC_Init (& NVIC_InitStructure);
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode USART_Mode_Rx = | USART_Mode_Tx;
USART_Init (USART2 is always, & USART_InitStructure);
USART_Cmd (USART2 is always, the ENABLE);
USART_ITConfig (USART2 is always, USART_IT_TXE, the ENABLE);
USART_ITConfig (USART2 is always, USART_IT_RXNE, the ENABLE);
}
Void USART3_Configuration (void)
{
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHBPeriphClockCmd (RCC_AHBPeriph_GPIOB, the ENABLE);
RCC_APB1PeriphClockCmd (RCC_APB1Periph_USART3, the ENABLE);
GPIO_PinAFConfig (GPIOB, GPIO_PinSource10, GPIO_AF_4);
GPIO_PinAFConfig (GPIOB, GPIO_PinSource11, GPIO_AF_4);
/ * the Configure USART3 pins: Rx and Tx ----------------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
GPIO_InitStructure.GPIO_Speed ​​= GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
= GPIO_PuPd_UP GPIO_InitStructure.GPIO_PuPd;
GPIO_Init (GPIOB, & GPIO_InitStructure);
/ * * the Enable USART3 the IRQ /
NVIC_InitStructure.NVIC_IRQChannel = USART3_6_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = the ENABLE;
NVIC_Init (& NVIC_InitStructure);
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure = USART_WordLength_8b .USART_WordLength;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init (USART3, & USART_InitStructure);
USART_Cmd (USART3, the ENABLE);
USART_ClearFlag (USART3, USART_FLAG_TC);
USART_ITConfig (USART3, USART_IT_TXE, the ENABLE);
USART_ITConfig (USART3, USART_IT_RXNE, the ENABLE);
}
Void USART4_Configuration (void)
{
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHBPeriphClockCmd (RCC_AHBPeriph_GPIOA, the ENABLE);
RCC_APB1PeriphClockCmd (RCC_APB1Periph_USART4, the ENABLE);
GPIO_PinAFConfig (with GPIOA, GPIO_PinSource0, GPIO_AF_0);
GPIO_PinAFConfig (with GPIOA, GPIO_PinSource1, GPIO_AF_0);
/ * The Configure USART4 pins: the Rx and the Tx ---------------------------- * /
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
GPIO_InitStructure.GPIO_Speed GPIO_Speed_50MHz =;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init (with GPIOA, & GPIO_InitStructure);
/ * * the Enable USART4 the IRQ /
NVIC_InitStructure.NVIC_IRQChannel = USART3_6_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
NVIC_InitStructure .NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
USART_InitStructure.USART_BaudRate = 115200;
= USART_WordLength_8b USART_InitStructure.USART_WordLength;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init (USART4, & USART_InitStructure);
USART_Cmd (USART4, the ENABLE);
USART_ITConfig (USART4, USART_IT_TXE, the ENABLE);
USART_ITConfig (USART4, USART_IT_RXNE, the ENABLE);
}
void USART5_Configuration (void)
{
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHBPeriphClockCmd (RCC_AHBPeriph_GPIOB, the ENABLE);
RCC_APB1PeriphClockCmd (RCC_APB1Periph_USART5, the ENABLE);
GPIO_PinAFConfig (GPIOB, GPIO_PinSource3, GPIO_AF_1);
GPIO_PinAFConfig (GPIOB, GPIO_PinSource4, GPIO_AF_1);
/ * the Configure USART5 pins: the Rx and the Tx --------- * ------------------- /
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure .GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Enable USART5 IRQ */
NVIC_InitStructure.NVIC_IRQChannel = USART3_6_IRQn;
= 0 NVIC_InitStructure.NVIC_IRQChannelPriority;
NVIC_InitStructure.NVIC_IRQChannelCmd = the ENABLE;
NVIC_Init (& NVIC_InitStructure);
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode USART_Mode_Rx = | USART_Mode_Tx;
USART_Init (USART5, & USART_InitStructure);
USART_Cmd (USART5, the ENABLE);
USART_ITConfig (USART5, USART_IT_TXE, the ENABLE);
USART_ITConfig (USART5, USART_IT_RXNE, the ENABLE);
}
Void USART_Configuration(void)
{
USART1_Configuration();
USART2_Configuration();
USART3_Configuration();
USART4_Configuration();
USART5_Configuration();
}
int main(void)
{
SystemInit();
USART_Configuration();
Delay_Init() ;
while(1)
{
USART_SendData(USART1, Data1);
Delay_Ms(1000);
USART_SendData(USART2, Data2);
Delay_Ms(1000);
USART_SendData(USART3, Data3);
Delay_Ms(1000);
USART_SendData(USART4, Data4);
Delay_Ms(1000);
USART_SendData(USART5, Data5);
Delay_Ms(1000);
}
}
[/mw_shl_code]
While transmitting data through usart 1 and 2 it is recving but not for USART 3,4 and 5
一周热门 更多>