Q:这个配置方法我是按照阿波罗USART1配置的,测试下来USART3->DR未有数据无法进入接收中断,usart3对外发数据是成功的
此外我配置usart3接收DMA是可以正常收到数据的
请问这个怎么破?有空调试的朋友留下邮箱,我把文件发给你
/**************************************´®¿Ú3µÄÏà¹ØÅäÖà start************************************/
#if EN_USART3_RX //Èç¹ûʹÄÜÁ˽ÓÊÕ
//´®¿Ú1ÖжϷþÎñ³ÌÐò
//×¢Òâ,¶ÁÈ¡USARTx->SRÄܱÜÃâĪÃûÆäÃîµÄ´íÎó
u8 USART3_RX_BUF[USART_REC_LEN]; //½ÓÊÕ»º³å,×î´óUSART_REC_LEN¸ö×Ö½Ú.
u16 USART3_RX_STA=0; //½ÓÊÕ״̬±ê¼Ç
UART_HandleTypeDef UART3_Handler; //UART¾ä±ú
//³õʼ»¯IO ´®¿Ú3
//bound:²¨ÌØÂÊ
void uart3_init(u32 bound)
{
UART3_Handler.Instance=USART3; //USART3
UART3_Handler.Init.BaudRate=bound; //²¨ÌØÂÊ
UART3_Handler.Init.WordLength=UART_WORDLENGTH_8B; //×Ö³¤Îª8λÊý¾Ý¸ñʽ
UART3_Handler.Init.StopBits=UART_STOPBITS_1; //Ò»¸öֹͣλ
UART3_Handler.Init.Parity=UART_PARITY_NONE; //ÎÞÆæżУÑéλ
UART3_Handler.Init.HwFlowCtl=UART_HWCONTROL_NONE; //ÎÞÓ²¼þÁ÷¿Ø
UART3_Handler.Init.Mode=UART_MODE_TX_RX; //ÊÕ·¢Ä£Ê½
HAL_UART_Init(&UART3_Handler); //NOTE:此处会调用void HAL_UART_MspInit(UART_HandleTypeDef *huart)
}
//´®¿Ú3ÖжϷþÎñ³ÌÐò
void USART3_IRQHandler(void)
{
u8 Res;
#if SYSTEM_SUPPORT_OS //ʹÓÃOS
OSIntEnter();
#endif
if((__HAL_UART_GET_FLAG(&UART3_Handler,UART_FLAG_RXNE)!=RESET)) //½ÓÊÕÖжÏ(½ÓÊÕµ½µÄÊý¾Ý±ØÐëÊÇ0x0d 0x0a½áβ)
{
HAL_UART_Receive(&UART3_Handler,&Res,1,1000);
if((USART3_RX_STA&(1<<15))==0)//½ÓÊÕÍêµÄÒ»ÅúÊý¾Ý,»¹Ã»Óб»´¦Àí,Ôò²»ÔÙ½ÓÊÕÆäËûÊý¾Ý
{
if(USART3_RX_STA<USART_REC_LEN) //»¹¿ÉÒÔ½ÓÊÕÊý¾Ý
{
__HAL_TIM_SET_COUNTER(&TIM7_Handler,0);//¼ÆÊýÆ÷Çå¿Õ
if(USART3_RX_STA==0) //ʹÄܶ¨Ê±Æ÷7µÄÖжÏ
{
__HAL_TIM_ENABLE(&TIM7_Handler);//ʹÄÜTIM7
}
USART3_RX_BUF[USART3_RX_STA++]=Res; //¼Ç¼½ÓÊÕµ½µÄÖµ
Res=0;
}
else
{
USART3_RX_STA|=1<<15; //Ç¿ÖƱê¼Ç½ÓÊÕÍê³É
}
}
}
#if SYSTEM_SUPPORT_OS //ʹÓÃOS
OSIntExit();
#endif
}
#endif
/**************************************´®¿Ú3µÄÏà¹ØÅäÖà end************************************/
void HAL_UART_MspInit(UART_HandleTypeDef *huart)
{
//GPIO¶Ë¿ÚÉèÖÃ
GPIO_InitTypeDef GPIO_Initure;
if(huart->Instance==USART1)//Èç¹ûÊÇ´®¿Ú1£¬½øÐд®¿Ú1 MSP³õʼ»¯
{
__HAL_RCC_GPIOA_CLK_ENABLE(); //ʹÄÜGPIOAʱÖÓ
__HAL_RCC_USART1_CLK_ENABLE(); //ʹÄÜUSART1ʱÖÓ
GPIO_Initure.Pin=GPIO_PIN_9; //PA9
GPIO_Initure.Mode=GPIO_MODE_AF_PP; //¸´ÓÃÍÆÍìÊä³ö
GPIO_Initure.Pull=GPIO_PULLUP; //ÉÏÀ­
GPIO_Initure.Speed=GPIO_SPEED_FAST; //¸ßËÙ
GPIO_Initure.Alternate=GPIO_AF7_USART1; //¸´ÓÃΪUSART1
HAL_GPIO_Init(GPIOA,&GPIO_Initure); //³õʼ»¯
A9
GPIO_Initure.Pin=GPIO_PIN_10; //PA10
HAL_GPIO_Init(GPIOA,&GPIO_Initure); //³õʼ»¯
A10
__HAL_UART_DISABLE_IT(&UART1_Handler,UART_IT_TC);
#if EN_USART1_RX
__HAL_UART_ENABLE_IT(&UART1_Handler,UART_IT_RXNE);//¿ªÆô½ÓÊÕÖжÏ
HAL_NVIC_EnableIRQ(USART1_IRQn); //ʹÄÜUSART1ÖжÏͨµÀ
HAL_NVIC_SetPriority(USART1_IRQn,3,3); //ÇÀÕ¼ÓÅÏȼ¶3£¬×ÓÓÅÏȼ¶3
TIM3_Init(100-1,9000-1); //TIM7_Init(1000-1,9000-1)=100ms
#endif
}
if(huart->Instance==USART2)//Èç¹ûÊÇ´®¿Ú2£¬½øÐд®¿Ú2 MSP³õʼ»¯
{
__HAL_RCC_GPIOA_CLK_ENABLE(); //ʹÄÜGPIOAʱÖÓ
__HAL_RCC_USART2_CLK_ENABLE(); //ʹÄÜUSART2ʱÖÓ
GPIO_Initure.Pin=GPIO_PIN_2; //PA2
GPIO_Initure.Mode=GPIO_MODE_AF_PP; //¸´ÓÃÍÆÍìÊä³ö
GPIO_Initure.Pull=GPIO_PULLUP; //ÉÏÀ­
GPIO_Initure.Speed=GPIO_SPEED_FAST; //¸ßËÙ
GPIO_Initure.Alternate=GPIO_AF7_USART2; //¸´ÓÃΪUSART2
HAL_GPIO_Init(GPIOA,&GPIO_Initure); //³õʼ»¯
A9
GPIO_Initure.Pin=GPIO_PIN_3; //PA3
HAL_GPIO_Init(GPIOA,&GPIO_Initure); //³õʼ»¯
A10
__HAL_UART_DISABLE_IT(&UART2_Handler,UART_IT_TC);
#if en_USART2_RX
__HAL_UART_ENABLE_IT(&UART2_Handler,UART_IT_RXNE);//¿ªÆô½ÓÊÕÖжÏ
HAL_NVIC_EnableIRQ(USART2_IRQn); //ʹÄÜUSART2ÖжÏͨµÀ
HAL_NVIC_SetPriority(USART2_IRQn,3,2); //ÇÀÕ¼ÓÅÏȼ¶3£¬×ÓÓÅÏȼ¶2
TIM3_Init(100-1,9000-1); //TIM3_Init(10-1,9000-1);1ms
#endif
}
if(huart->Instance==UART4)//Èç¹ûÊÇ´®¿Ú4£¬½øÐд®¿Ú4 MSP³õʼ»¯
{
__HAL_RCC_GPIOA_CLK_ENABLE(); //ʹÄÜGPIOAʱÖÓ
__HAL_RCC_UART4_CLK_ENABLE(); //ʹÄÜUSART4ʱÖÓ
GPIO_Initure.Pin=GPIO_PIN_0; //PA0
GPIO_Initure.Mode=GPIO_MODE_AF_PP; //¸´ÓÃÍÆÍìÊä³ö
GPIO_Initure.Pull=GPIO_PULLUP; //ÉÏÀ­
GPIO_Initure.Speed=GPIO_SPEED_FAST; //¸ßËÙ
GPIO_Initure.Alternate=GPIO_AF8_UART4; //¸´ÓÃΪUSART4
HAL_GPIO_Init(GPIOA,&GPIO_Initure); //³õʼ»¯
A0
GPIO_Initure.Pin=GPIO_PIN_1; //PA1
HAL_GPIO_Init(GPIOA,&GPIO_Initure); //³õʼ»¯
A1
__HAL_UART_DISABLE_IT(&UART4_Handler,UART_IT_TC);
#if EN_USART4_RX
__HAL_UART_ENABLE_IT(&UART4_Handler,UART_IT_RXNE);//¿ªÆô½ÓÊÕÖжÏ
HAL_NVIC_EnableIRQ(UART4_IRQn); //ʹÄÜUSART4ÖжÏͨµÀ
HAL_NVIC_SetPriority(UART4_IRQn,3,1); //ÇÀÕ¼ÓÅÏȼ¶3£¬×ÓÓÅÏȼ¶1
TIM7_Init(100-1,9000-1); //TIM7_Init(1000-1,9000-1)=100ms
#endif
}
if(huart->Instance==USART3)//Èç¹ûÊÇ´®¿Ú3£¬½øÐд®¿Ú3 MSP³õʼ»¯
{
__HAL_RCC_GPIOB_CLK_ENABLE(); //ʹÄÜGPIOBʱÖÓ
__HAL_RCC_USART3_CLK_ENABLE(); //ʹÄÜUSART3ʱÖÓ
GPIO_Initure.Pin=GPIO_PIN_10; //PB10
GPIO_Initure.Mode=GPIO_MODE_AF_PP; //¸´ÓÃÍÆÍìÊä³ö
GPIO_Initure.Pull=GPIO_PULLUP; //ÉÏÀ­
GPIO_Initure.Speed=GPIO_SPEED_FAST; //¸ßËÙ
GPIO_Initure.Alternate=GPIO_AF7_USART3; //¸´ÓÃΪUSART3
HAL_GPIO_Init(GPIOB,&GPIO_Initure); //³õʼ»¯B10
GPIO_Initure.Pin=GPIO_PIN_11; //PB11
HAL_GPIO_Init(GPIOB,&GPIO_Initure); //³õʼ»¯B11
__HAL_UART_DISABLE_IT(&UART3_Handler,UART_IT_TC);
#if EN_USART3_RX
__HAL_UART_ENABLE_IT(&UART3_Handler,UART_IT_RXNE);//¿ªÆô½ÓÊÕÖжÏ
HAL_NVIC_EnableIRQ(USART3_IRQn); //ʹÄÜUSART3ÖжÏͨµÀ
HAL_NVIC_SetPriority(USART3_IRQn,3,0); //ÇÀÕ¼ÓÅÏȼ¶3£¬×ÓÓÅÏȼ¶0
TIM7_Init(100-1,9000-1); //TIM7_Init(1000-1,9000-1)=100ms
#endif
}
}
一周热门 更多>