我用stm32f030的Usart中断方式为什么始终进不了中断,求高手指点,谢谢!代码如下: void USART1_Configuration(void) { USART_InitTypeDef USART_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; /* ʹÄÜAHBʱÖÓ */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC | RCC_AHBPeriph_GPIOF, ENABLE); /* ʹÄÜAPB2ʱÖÓ */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); /* ÍâÉèÖÐ¶Ï */ NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; //IRQͨµÀ:´®¿Ú1 NVIC_InitStructure.NVIC_IRQChannelPriority = 1; //ÓÅÏȼ¶ :1¼¶ NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //ʹÄÜIRQͨµÀ NVIC_Init(&NVIC_InitStructure); GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_1); GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1); /* ¶¨ÒåUSART TX_RX Òý½ÅΪ¸´ÓÃÊä³ö */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10; //Òý½Å GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //¸´ÓÃģʽ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //¸ßËÙ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //ÍÆÍêÊä³ö GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //ÉÏÀ GPIO_Init(GPIOA, &GPIO_InitStructure); /****************************************************************** USART²ÎÊý³õʼ»¯: ²¨ÌØÂÊ ´«ÊäλÊý ֹͣλÊý УÑéλÊý 9600 8 1 0(NO) *******************************************************************/ USART_InitStructure.USART_BaudRate = 9600; //É趨´«ÊäËÙÂÊ 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); //³õʼ»¯USART1 USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); //ʹÄÜUSART1½ÓÊÕÖÐ¶Ï USART_Cmd(USART1, ENABLE); /* Clear Transmission complete flag */ USART_ClearFlag(USART1, USART_FLAG_TC); } void sInitMCU(void) { USART1_Configuration(); } int main(void) { sInitMCU(); while(1) { } } void USART1_IRQHandler(void) { if(USART_GetITStatus(USART1,USART_IT_RXNE) == SET) { lubReceiveData = USART_ReceiveData(USART1); USART_ITConfig(USART1, USART_IT_TC, ENABLE); USART_SendData(USART1,lubReceiveData); // USART_ClearITPendingBit(USART1,) } if(USART_GetITStatus(USART1,USART_IT_TC) == SET) { USART_SendData(USART1,lubReceiveData); USART_ITConfig(USART1, USART_IT_TC, DISABLE); USART_ClearITPendingBit(USART1,USART_IT_TC); } } |
可参考HAL库的例程;
调试好了,程序没问题 !
谢谢你的回复,程序中有启动中断的,是“USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); ”
谢谢你的回复,程序中有启动中断的,是“USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); ”
RCC_GetClocksFreq(&RCC_Clocks);
开始时钟,
SysTick_Config(RCC_Clocks.HCLK_Frequency / 100000); //内部定时器
加入试试