各位叔叔阿姨,大哥大姐,各位同僚们好,小弟最近弄
STM32的UART4卡住了,主要问题是UART4能发数据,不能进入中断,但是UART5就可以。特意求助
芯片型号:STM32F103VGT6
串口 SP3232:
出问题串口 UART4 PC10 PC11
现象:不能进入中断
库版本V3.5.0
配置是:HD
/***********************************************************UART4**********************************************/
/************************************************************************************
* 函数名:NVIC_Configura
tion_Usart5
* 描述 :NVIC_Configuration_Usart5
* 输入 :无
* 输出 : 无
* 调用 :外部调用
***********************************************************************************/
void NVIC_Configuration_Usart4(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure the NVIC Preemption Priority Bits */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
/* Enable the USARTy Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/************************************************************************************
* 函数名:USART5_Config
* 描述 :USART5 GPIO 配置,工作模式配置。9600 8-N-1
* 输入 :无
* 输出 : 无
* 调用 :外部调用
***********************************************************************************/
void UART4_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
//配置接收管脚PC11
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOC, &GPIO_InitStructure);
//配置发送管脚PC10
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
//波特率、字长、停止位、奇偶校验位、硬件流控制、异步串口为默认(被屏蔽字设置)
USART_InitStructure.USART_BaudRate = 9600;
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(UART4, &USART_InitStructure);
USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);
USART_Cmd(UART4, ENABLE);
NVIC_Configuration_Usart4();
}
void UART4_IRQHandler(void)
{
if(USART_GetITStatus(UART4, USART_IT_RXNE) != RESET)
{
USART_SendData(UART4, UART4->DR);
}
}
/***********************************************************UART5**********************************************/
/************************************************************************************
* 函数名:NVIC_Configuration_Usart5
* 描述 :NVIC_Configuration_Usart5
* 输入 :无
* 输出 : 无
* 调用 :外部调用
***********************************************************************************/
void NVIC_Configuration_Usart5(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure the NVIC Preemption Priority Bits */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
/* Enable the USARTy Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = UART5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/************************************************************************************
* 函数名:USART5_Config
* 描述 :USART5 GPIO 配置,工作模式配置。9600 8-N-1
* 输入 :无
* 输出 : 无
* 调用 :外部调用
***********************************************************************************/
void UART5_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD, ENABLE);
//配置接收管脚PD2
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOD, &GPIO_InitStructure);
//配置发送管脚PC12
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
//波特率、字长、停止位、奇偶校验位、硬件流控制、异步串口为默认(被屏蔽字设置)
USART_InitStructure.USART_BaudRate = 9600;
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(UART5, &USART_InitStructure);
USART_ITConfig(UART5, USART_IT_RXNE, ENABLE);
USART_Cmd(UART5, ENABLE);
NVIC_Configuration_Usart5();
}
void UART5_IRQHandler(void)
{
if(USART_GetITStatus(UART5, USART_IT_RXNE) != RESET)
{
USART_SendData(UART5, UART5->DR);
}
}
http://wenku.baidu.com/link?url=LpUUvM-7JosKA2p7TGH_i0-P350OaQ_Y42pUYeL64v1JM6jEbwfnfC1x2g3m1t6NddNzh_7_zW5DthwUf8aW_qcsCkA4FuZu-CDgmzcTn8a
参考一下本篇文章
你好我这个也看过了,依旧没有什么进展
一周热门 更多>