void USART2_IRQHandler(void)
{
u8 res;
if(USART_GetITStatus(USART2,USART_IT_RXNE))
{
res= USART_ReceiveData(USART2);
USART_SendData(USART1,res);
printf("qwer");
USART_SendData(USART1,0x02);
}
}
复用了2个串口(USART1和USART2),想通过触摸屏按某个坐标,通过串口2接收到串口调试助手发来的数据,进入串口2中断程序,给串口1发送"qwer",但是在串口调试助手接收到乱码
这是发送了3次的。"USART_IT_RXNE"自定义寄存器,整个寄存器的定义每个位的解释在哪,给的资料里面没找到
望吧内大神指导,还有原子哥帮我解释一下
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
我是想让它将数据发到串口2
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); //ê1ÄüUSART1£¬GPIOAê±Ö
//USART1_TX GPIOA.9
GPIO_PinRemapConfig(GPIO_Remap_USART2, DISABLE);
GPIO_InitStructure2.GPIO_Pin = GPIO_Pin_2; //PA.9
GPIO_InitStructure2.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure2.GPIO_Mode = GPIO_Mode_AF_PP; //¸′óÃíÆíìêä3ö
GPIO_Init(GPIOA, &GPIO_InitStructure2);//3õê¼»ˉGPIOA.9
//USART1_RX GPIOA.103õê¼»ˉ
GPIO_InitStructure2.GPIO_Pin = GPIO_Pin_3;//PA10
GPIO_InitStructure2.GPIO_Mode = GPIO_Mode_IN_FLOATING;//¸¡¿Õêäèë
GPIO_Init(GPIOA, &GPIO_InitStructure2);//3õê¼»ˉGPIOA.10
NVIC_InitStructure2.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure2.NVIC_IRQChannelPreemptionPriority=1 ;//ÇàÕ¼óÅÏ輶3
NVIC_InitStructure2.NVIC_IRQChannelSubPriority = 1; //×óóÅÏ輶3
NVIC_InitStructure2.NVIC_IRQChannelCmd = ENABLE; //IRQí¨μàê1Äü
NVIC_Init(&NVIC_InitStructure2); //¸ù¾YÖ¸¶¨μÄ2Îêy3õê¼»ˉVIC¼Ä′æÆ÷
USART_InitStructure2.USART_BaudRate = 38400;//′®¿ú2¨ìØÂê
USART_InitStructure2.USART_WordLength = USART_WordLength_8b;//×Ö3¤Îa8λêy¾Y¸ñê½
USART_InitStructure2.USART_StopBits = USART_StopBits_1;//ò»¸öí£Ö1λ
USART_InitStructure2.USART_Parity = USART_Parity_No;//ÎTÆæżD£Ñéλ
USART_InitStructure2.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//ÎTó2¼têy¾Yá÷¿ØÖÆ
USART_InitStructure2.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //êÕ·¢Ä£ê½
USART_Init(USART2, &USART_InitStructure2); //3õê¼»ˉ′®¿ú1
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);//¿aÆô′®¿ú½óêüÖD¶Ï
USART_Cmd(USART2, ENABLE);
一周热门 更多>