串口实验进入中断就死掉了。大家碰到过这个现象吗?代码是按照历程写的,芯片是STM32F302,编程模板是从网上找的。大家帮忙解答一下[mw_shl_code=applescript,true]void RS485_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA , ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_7);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_7);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //PA2
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //¸′óÃíÆíì
GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;//PA3
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //¸¡¿Õêäèë
GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2,ENABLE);//¸′λ′®¿ú2
RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2,DISABLE);//í£Ö1¸′λ
USART_InitStructure.USART_BaudRate = 9600;//2¨ìØÂêéèÖÃ
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//8λêy¾Y3¤¶è
USART_InitStructure.USART_StopBits = USART_StopBits_1;//ò»¸öí£Ö1λ
USART_InitStructure.USART_Parity = USART_Parity_No;///ÆæżD£Ñéλ
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//ÎTó2¼têy¾Yá÷¿ØÖÆ
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;//êÕ·¢Ä£ê½
USART_Init(USART2, &USART_InitStructure); ; //3õê¼»ˉ′®¿ú
USART_Cmd(USART2, ENABLE); //ê1Äü′®¿ú
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);//ê1Äü½óêüÖD¶Ï
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; //ê1Äü′®¿ú2ÖD¶Ï
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //ÏèÕ¼óÅÏ輶2¼¶
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //′óóÅÏ輶2¼¶
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //ê1Äüía2¿ÖD¶Ïí¨μà
NVIC_Init(&NVIC_InitStructure); //¸ù¾YNVIC_InitStructÖDÖ¸¶¨μÄ2Îêy3õê¼»ˉíaéèNVIC¼Ä′æÆ÷
// USART_ITConfig(USART2,USART_IT_RXNE,ENABLE);
// USART_ClearFlag (USART2,USART_FLAG_TC);
}
void USART2_IRQHandler(void)
{
// u8 res;
if(USART_GetITStatus(USART2, USART_IT_RXNE)) //½óêÕμ½êy¾Y
{
// res =USART_ReceiveData(USART2); //¶á衽óêÕμ½μÄêy¾Y
USART_SendData(USART1,0x11);
// while (!USART_GetFlagStatus(USART2,USART_FLAG_TC));
// USART_ClearITPendingBit(USART2,USART_IT_RXNE);
}
}
[/mw_shl_code]
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>