STM32单片机USART3接收中断进不去。求大神解答。。

初学STM32不久,程序自USART1的程序改的(改了时钟和端口)。USART1可以收发,USART3却只能发送,接收时无法进入中断。
通过串口助手可以接收数据,调试的时候发现程序根本进不了中断,而USART3->DR的值是接收到的第一个字节的值,比如串口助手收到一组数:11 22 33,USART3->DR的值始终是11 。这可以说明线路没有连接错吧。
不知道什么原因就是无法进入中断。
这是初始化的一些程序。
void USART3_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;

/* config USART3 clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);

/* USART3 GPIO config */
/* Configure USART3 Tx (PB10) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);

/* Configure USART3 Rx (PB11) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);

/* USART3 mode config */
USART_InitStructure.USART_BaudRate = 38400;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
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);
}
中断配置:
void USART3_NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure the NVIC Preemption Priority Bits */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_3);

/* Enable the USARTy Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
中断函数:
void USART3_IRQHandler(void)
{
u8 c;
if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)
{
c=USART3->DR;
RxCamera[RxPoint3]=c;
RxPoint3++ ;
}

1、中断标志位要清零USART_ITConfig(USART1, USART_IT_RXNE, DISABLE);表示寄存器非空

2、NVIC_PriorityGroupConfig(NVIC_PriorityGroup_3);优先级设得低了,3改成0追问

我嘞个去。。。

1,那是将RXNE禁止了,应该是ENABLE;
2,那个“3”不是优先级,是指高三位配置响应优先级,最低一位配置响应优先级。

温馨提示:内容为网友见解,仅供参考
第1个回答  2015-05-14

    RCC_APB2Periph_AFIO;USART3没开IO口复用

    USART3没开接收中断

    进入中断后要清中断

第2个回答  2014-05-10
中断标志位有清吗追问

加了这句“USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);”就可以了,也不算是清标志位吧?使能接收中断。
那为什么USART1就不需要这句话呢?是因为USART1是默认的下载口?

相似回答