串口配置
[mw_shl_code=c,true]void uart3_init(u32 bound)
{
//GPIO¶Ë¿ÚÉèÖÃ
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
GPIO_PinAFConfig(GPIOB,GPIO_PinSource10,GPIO_AF_USART3);
GPIO_PinAFConfig(GPIOB,GPIO_PinSource11,GPIO_AF_USART3);
/*
* USART3_TX -> PB10 , USART3_RX -> PB11
*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //ÍÆÍ츴ÓÃÊä³ö
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //ÉÏÀ­
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_Init(GPIOB, &GPIO_InitStructure);
//Usart3 NVIC ÅäÖÃ
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1 ;//ÇÀÕ¼ÓÅÏȼ¶1
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //×ÓÓÅÏȼ¶1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQͨµÀʹÄÜ
NVIC_Init(&NVIC_InitStructure); //¸ù¾ÝÖ¸¶¨µÄ²ÎÊý³õʼ»¯VIC¼Ä´æÆ÷
//USART ³õʼ»¯ÉèÖÃ
USART_InitStructure.USART_BaudRate = bound;//Ò»°ãÉèÖÃΪ9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//×Ö³¤Îª8λÊý¾Ý¸ñʽ
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(USART3, &USART_InitStructure); //³õʼ»¯´®¿Ú
USART_Cmd(USART3, ENABLE); //ʹÄÜ´®¿Ú
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);//¿ªÆôÖжÏ
}[/mw_shl_code]
中断这里是原子哥的程序
[mw_shl_code=c,true]void USART3_IRQHandler(void)
{
u8 res;
if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)//½ÓÊÕµ½Êý¾Ý
{
USART3_RX_STA|=1<<15;
res =USART_ReceiveData(USART3);
if((USART3_RX_STA&(1<<15))==0) //½ÓÊÕÍêµÄÒ»ÅúÊý¾Ý,»¹Ã»Óб»´¦Àí,Ôò²»ÔÙ½ÓÊÕÆäËûÊý¾Ý
{
if(USART3_RX_STA<BUFLEN) //»¹¿ÉÒÔ½ÓÊÕÊý¾Ý
{
TIM_SetCounter(TIM7,0); //¼ÆÊýÆ÷Çå¿Õ //¼ÆÊýÆ÷Çå¿Õ
if(USART3_RX_STA==0) //ʹÄܶ¨Ê±Æ÷7µÄÖжÏ
{
TIM_Cmd(TIM7,ENABLE); //ʹÄܶ¨Ê±Æ÷7
}
USART3_RX_BUF[USART3_RX_STA++]=res; //¼Ç¼½ÓÊÕµ½µÄÖµ
}
else
{
USART3_RX_STA|=1<<15; //Ç¿ÖƱê¼Ç½ÓÊÕÍê³É
}
}
}
} [/mw_shl_code]
主函数里我写的很简单就是if(USART3_RX_STA&0X8000) ,然后打印个字符。 我把gps模块接过来,中断进不去。gps我接电脑测是有在发送数据的。搞不懂为啥呀
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>