32的中断服务函数 是不是 配置好了 然后 对应串口的RX引脚来了数据 就进中断 我用F4写了一个程序 通过串口接收数据 然后对数据处理后 直接在主函数用printf打印出来 但现在 移植到F1上后 进不了 串口中断的服务函数 是为什么
void USART1_Config(u32 bound) //串口配置{ GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; /* config USART1 clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); /* USART1 GPIO config */ /* Configure USART1 Tx (PA.09) as alternate function push-pull */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); /* Configure USART1 Rx (PA.10) as input floating */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA, &GPIO_InitStructure); /* USART1 mode config */ USART_InitStructure.USART_BaudRate = bound; 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_Cmd(USART1, ENABLE);}
void USART1_IRQHandler(void) //串口1 中断服务函数{ u8 Res; if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) //
{ printf("1"); //这个1始终打印不出来 说明一直就没进中断 也就是没收到数据 但传感器 是一直往外发数据的 (数据线和单片机的PA10直接相连) Res =USART_ReceiveData(USART1); USART_RX_BUF[USART_RX_STA]=Res; if(USART_RX_STA==0&&USART_RX_BUF[0]!=0x42) { USART_RX_STA=0; return; } USART_RX_STA++; f(USART_RX_STA==32) { USART_RX_STA=0; sign=1; } } }
是不是串口的IO的模式不对,检查下自收自发可不可以。