大家好,小弟刚接触stm32;最近刚做一板子,其中一功能就是通过串口发送数据,然后接收数据;发送数据没问题,但就是进不了接收中断(通过串口助手监视,有接收数据);最后又试了一下按键(连外部中断14 和15),测试还是进不了中断! 搞了一天,没有结果;希望大侠们指点,帮我“进入中断”;先谢了。。。。
我的中断配置
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
//NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x2000);
// 配置优先级分组,无抢占式优先级
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
// 配置USART1中断优先级
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
// 配置USART2中断优先级
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
// 配置USART3中断优先级
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
// 2010-05-26, zhangxingjuan
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; //中断通道
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //次优先级
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //通道中断使能
NVIC_Init(&NVIC_InitStructure); //初始化中断
}
串口配置
void USART123_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure; // GPIO 初始化结构体
USART_InitTypeDef USART_InitStructure; // USART 初始化结构体
//***********Configure USART1 Tx Pin*********
GPIO_InitStructure.GPIO_Pin = GPIO_Tx1PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//***********Configure USART2 Tx Pin********
GPIO_InitStructure.GPIO_Pin = GPIO_Tx2PIN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//***********Configure USART3 Tx Pin*********
GPIO_InitStructure.GPIO_Pin = GPIO_Tx3PIN;
GPIO_Init(GPIOB, &GPIO_InitStructure);
//***********Configure USART1 Rx Pin*********
GPIO_InitStructure.GPIO_Pin = GPIO_Rx1PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//***********Configure USART2 Rx Pin*********
GPIO_InitStructure.GPIO_Pin = GPIO_Rx2PIN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//***********Configure USART3 Rx Pin*********
GPIO_InitStructure.GPIO_Pin = GPIO_Rx3PIN;
GPIO_Init(GPIOB, &GPIO_InitStructure);
//********USART1 configure para*********
USART_InitStructure.USART_BaudRate = 2400;
USART_InitStructure.USART_WordLength = USART_WordLength_9b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_Even;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_Init(USART1,&USART_InitStructure);
/********USART2 configure para*********/
USART_Init(USART2,&USART_InitStructure);
/********USART3 configure para**********/
USART_Init(USART3,&USART_InitStructure);
// 使能USART1、2、3的接收中断
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
// 使能USART1、2、3
USART_Cmd(USART1, ENABLE);
USART_Cmd(USART2, ENABLE);
USART_Cmd(USART3, ENABLE);
}
/**
* @描述:配置系统中断
* @入口参数: 无
*/
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
//NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x2000);
// 配置优先级分组,无抢占式优先级
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
// 配置USART1中断优先级
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
// 配置USART2中断优先级
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
// 配置USART3中断优先级
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
// 2010-05-26, zhangxingjuan
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; //中断通道
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //次优先级
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //通道中断使能
NVIC_Init(&NVIC_InitStructure); //初始化中断
}
是不是还缺少设置什么?
加一天班,现在是彻底的晕了~~~~ |