新手入门
- 积分
- 4
- 金钱
- 4
- 注册时间
- 2018-11-20
- 在线时间
- 1 小时
|
2金钱
我在调试stm32f207zet6 usart1 的接收功能不能进入中断接收。求大神解析
void uart_init(u32 bound){
//GPIO¶Ë¿úéèÖÃ
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE); //ê1ÄüGPIOAê±Öó
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);//ê1ÄüUSART1ê±Öó
//′®¿ú1¶Ôó|òy½Å¸′óÃó3éä
GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_USART1); //GPIOA9¸′óÃÎaUSART1 TX
GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_USART1); //GPIOA10¸′óÃÎaUSART1 RX
//USART1¶Ë¿úÅäÖÃ
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 ;//| GPIO_Pin_10; //GPIOA9óëGPIOA10
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//¸′óÃ1|Äü
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //Ëù¶è50MHz
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //íÆíì¸′óÃêä3ö
//GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //éÏà-
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; //ÎTéÏà2ÎTÏÂà-
GPIO_Init(GPIOA,&GPIO_InitStructure); //3õê¼»ˉPA9£¬ A10
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;//PA10
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//¸¡¿Õêäèë
GPIO_Init(GPIOA, &GPIO_InitStructure);//3õê¼»ˉGPIOA.10
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;//′®¿ú1ÖD¶Ïí¨μà
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2;//ÇàÕ¼óÅÏè¼¶3
NVIC_InitStructure.NVIC_IRQChannelSubPriority =3; //×óóÅÏè¼¶3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQí¨μàê1Äü
NVIC_Init(&NVIC_InitStructure);
//USART1 3õê¼»ˉéèÖÃ
USART_InitStructure.USART_BaudRate = bound;//2¨ìØÂêéèÖÃ
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//×Ö3¤Îa8λêy¾Y¸ñê½
USART_InitStructure.USART_StopBits = USART_StopBits_1;//ò»¸öí£Ö1λ
USART_InitStructure.USART_Parity = USART_Parity_No;//ÎTÆæÅ¼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(USART1, &USART_InitStructure); //3õê¼»ˉ′®¿ú1
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);//¿aÆôÏà1ØÖD¶Ï ½óêÕÖD¶Ï
USART_ClearFlag(USART1, USART_FLAG_TC);
USART_Cmd(USART1, ENABLE); //ê1Äü′®¿ú1
}
void USART1_IRQHandler(void) //′®¿ú1ÖD¶Ï·tÎñ3ìDò
{
uint8_t ReceiveDate;
if(USART1->SR&(1<<5))
{
USART1->SR&=~(1<<5);
ReceiveDate =USART_ReceiveData(USART1); //¶á衽óêÕμ½μÄêy¾Y
sendbuffer[sendlen]=ReceiveDate;
sendlen++;
if(sendlen>10)
{
sendlen=0;
}
}
}
|
|