STM32 USART1中断进不了串口 别的中断(外部)都可以进去,就是USART1_IRQn进不去
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
不加这句不卡NVIC_Init(&NVIC_InitStructure);
加上这句就卡住不动了.
????请高手解决!!!
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
/* Uncomment the line below to enable peripheral header file inclusion */
/* #include "stm32f10x_adc.h" */
#include "stm32f10x_bkp.h"
/* #include "stm32f10x_can.h" */
#include "stm32f10x_cec.h"
#include "stm32f10x_crc.h"
/* #include "stm32f10x_dac.h" */
#include "stm32f10x_dbgmcu.h"
/* #include "stm32f10x_dma.h" */
#include "stm32f10x_exti.h"
/* #include "stm32f10x_flash.h" */
/* #include "stm32f10x_fsmc.h" */
#include "stm32f10x_gpio.h"
/* #include "stm32f10x_i2c.h"*/
/* #include "stm32f10x_iwdg.h" */
#include "stm32f10x_pwr.h"
#include "stm32f10x_rcc.h"
/* #include "stm32f10x_rtc.h" */
/* #include "stm32f10x_sdio.h" */
/* #include "stm32f10x_spi.h" */
/* #include "stm32f10x_tim.h" */
#include "stm32f10x_usart.h"
/* #include "stm32f10x_wwdg.h" */
#include "misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */
LOVE_FYD 太厉害了!!!!!这是他给解决的程序!
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) //接收中断(接收到的数据必须是0x0d 0x0a结尾)
{
USART_ClearFlag(USART1,USART_FLAG_RXNE);
USART_ClearITPendingBit(USART1, USART_IT_RXNE);
Res =USART_ReceiveData(USART1);//(USART1->DR); //读取接收到的数据
printf("iojwfo ");
if((USART_RX_STA&0x80)==0)//接收未完成
{
if(USART_RX_STA&0x40)//接收到了0x0d
{
if(Res!=0x0a)USART_RX_STA=0;//接收错误,重新开始
else USART_RX_STA|=0x80; //接收完成了
}
else //还没收到0X0D
{
if(Res==0x0d)USART_RX_STA|=0x40;
else
{
USART_RX_BUF[USART_RX_STA&0X3F]=Res ;
USART_RX_STA++;
if(USART_RX_STA>63)USART_RX_STA=0;//接收数据错误,重新开始接收
}
}
}
}
}
还有把发送中断使能注释掉
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(USART1, &USART_InitStructure);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
// USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
//USART_ClearFlag(USART1,USART_FLAG_TC);
USART_Cmd(USART1, ENABLE);
---------------------------------
可是我试了一下,不清除中断标志(USART_ClearFlag(USART1,USART_FLAG_RXNE);
USART_ClearITPendingBit(USART1, USART_IT_RXNE); 不要这2句)也可以发送数据。这是怎么回事?
一周热门 更多>