void USART2_IRQHandler(void);
void USART3_IRQHandler(void);
u8 YUcmd = 0;
u8 Location=0;
int main()
{
SysTick_Init(); //Ïμí3μÎ′e¶¨ê±Æ÷3õê¼»ˉ
usart3_init(); //′®¿ú33õê¼»ˉ
usart2_init();
while(1)
{
if(Location!=0)//¶¨μÄUSART ÖD¶Ï·¢éúóë·ñ
{
USART_SendData(USART2,Location);
while(USART_GetFlagStatus(USART2,USART_FLAG_TC)==Bit_RESET);
Location=0;
}
}
}
void USART2_IRQHandler(void) //′®¿ú2ÖD¶Ïoˉêy
{
static u8 k;
USART_ClearFlag(USART2,USART_FLAG_TC);
if(USART_GetITStatus(USART2,USART_IT_RXNE)!=Bit_RESET)//¼ì2éÖ¸¶¨μÄUSART ÖD¶Ï·¢éúóë·ñ
{
k=USART_ReceiveData(USART2);
YUcmd=k;
}
}
void USART3_IRQHandler(void) //′®¿ú2ÖD¶Ïoˉêy
{
static u8 k;
USART_ClearFlag(USART3,USART_FLAG_TC);
if(USART_GetITStatus(USART3,USART_IT_RXNE)!=Bit_RESET)//¼ì2éÖ¸¶¨μÄUSART ÖD¶Ï·¢éúóë·ñ
{
k=USART_ReceiveData(USART3);
Location=k;
}
}
这个程序就是串口助手由USART3口通过485发送数据给STM32,然后再由STM32将数据发送到USART2口由无线传输模块进行传输,但是通过运行,发现程序进不去USART3的中断程序USART3_IRQHandler。求助各位高手
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
{
GPIO_InitTypeDef GPIO_InitStructure; //éùÃ÷ò»¸ö½á11ìå±äá¿£¬óÃà′3õê¼»ˉGPIO
USART_InitTypeDef USART_InitStructure; //′®¿ú½á11ì嶨òå
NVIC_InitTypeDef NVIC_InitStructure;//ÖD¶Ï½á11ì嶨òå
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); //′ò¿aê±Öó
/* ÅäÖÃGPIOμÄÄ£ê½oíIO¿ú */
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10;//TX //′®¿úêä3öA2
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP; //¸′óÃíÆíìêä3ö
GPIO_Init(GPIOB,&GPIO_InitStructure); /* 3õê¼»ˉ′®¿úêäèëIO */
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_11;//RX //′®¿úêäèëA3
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING; //Ä£Äaêäèë
GPIO_Init(GPIOB,&GPIO_InitStructure); /* 3õê¼»ˉGPIO */
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_1;//TX //′®¿úêä3öA2
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP; //¸′óÃíÆíìêä3ö
GPIO_Init(GPIOB,&GPIO_InitStructure); /* 3õê¼»ˉ′®¿úêäèëIO */
USART_InitStructure.USART_BaudRate=115200; //2¨ìØÂêéèÖÃÎa9600 //2¨ìØÂê
USART_InitStructure.USART_WordLength=USART_WordLength_8b; //êy¾Y3¤8λ
USART_InitStructure.USART_StopBits=USART_StopBits_1; //1λí£Ö1λ
USART_InitStructure.USART_Parity=USART_Parity_No; //ÎTD§Ñé
USART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None; //ê§Äüó2¼tá÷
USART_InitStructure.USART_Mode=USART_Mode_Rx|USART_Mode_Tx; //¿aÆô·¢Ëíoí½óêüÄ£ê½
USART_Init(USART3,&USART_InitStructure); /* 3õê¼»ˉUSART2 */
USART_Cmd(USART3, ENABLE); /* ê1ÄüUSART2 */
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);//ê1Äü»òÕßê§ÄüÖ¸¶¨μÄUSARTÖD¶Ï ½óêÕÖD¶Ï
USART_ClearFlag(USART3,USART_FLAG_TC);//Çå3yUSARTxμÄ′y′|àí±ê־λ
/* éèÖÃNVIC2Îêy */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn; //′ò¿aUSART2μÄ諾ÖÖD¶Ï
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //ÇàÕ¼óÅÏ輶Îa0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //Ïìó|óÅÏ輶Îa0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //ê1Äü
NVIC_Init(&NVIC_InitStructure);
}
void usart2_init()
{
GPIO_InitTypeDef GPIO_InitStructure; //éùÃ÷ò»¸ö½á11ìå±äá¿£¬óÃà′3õê¼»ˉGPIO
USART_InitTypeDef USART_InitStructure; //′®¿ú½á11ì嶨òå
NVIC_InitTypeDef NVIC_InitStructure;//ÖD¶Ï½á11ì嶨òå
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); //′ò¿aê±Öó
/* ÅäÖÃGPIOμÄÄ£ê½oíIO¿ú */
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_2;//TX //′®¿úêä3öA2
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP; //¸′óÃíÆíìêä3ö
GPIO_Init(GPIOA,&GPIO_InitStructure); /* 3õê¼»ˉ′®¿úêäèëIO */
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_3;//RX //′®¿úêäèëA3
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING; //Ä£Äaêäèë
GPIO_Init(GPIOA,&GPIO_InitStructure); /* 3õê¼»ˉGPIO */
USART_InitStructure.USART_BaudRate=115200; //2¨ìØÂêéèÖÃÎa9600 //2¨ìØÂê
USART_InitStructure.USART_WordLength=USART_WordLength_8b; //êy¾Y3¤8λ
USART_InitStructure.USART_StopBits=USART_StopBits_1; //1λí£Ö1λ
USART_InitStructure.USART_Parity=USART_Parity_No; //ÎTD§Ñé
USART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None; //ê§Äüó2¼tá÷
USART_InitStructure.USART_Mode=USART_Mode_Rx|USART_Mode_Tx; //¿aÆô·¢Ëíoí½óêüÄ£ê½
USART_Init(USART2,&USART_InitStructure); /* 3õê¼»ˉUSART2 */
USART_Cmd(USART2, ENABLE); /* ê1ÄüUSART2 */
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);//ê1Äü»òÕßê§ÄüÖ¸¶¨μÄUSARTÖD¶Ï ½óêÕÖD¶Ï
USART_ClearFlag(USART2,USART_FLAG_TC);//Çå3yUSARTxμÄ′y′|àí±ê־λ
/* éèÖÃNVIC2Îêy */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; //′ò¿aUSART2μÄ諾ÖÖD¶Ï
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //ÇàÕ¼óÅÏ輶Îa0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //Ïìó|óÅÏ輶Îa0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //ê1Äü
NVIC_Init(&NVIC_InitStructure);
}
一周热门 更多>