STM32F103 UART4 设置使能中断,程序无法运行

dpbug_cn 2020-03-04 02:28:12

STM32F103 将UART4设置为使能中断则程序无法运行,注释掉USART_ITConfig( UART4, USART_IT_RXNE, ENABLE)程序就可以运行了,什么原因呢?

UART4配置代码:
void USART4_Init( unsigned int baud )
{
GPIO_InitTypeDef gpioInitStruct;
USART_InitTypeDef usartInitStruct;
NVIC_InitTypeDef nvicInitStruct;

RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC, ENABLE );
RCC_APB1PeriphClockCmd( RCC_APB1Periph_UART4, ENABLE );

gpioInitStruct.GPIO_Pin = GPIO_Pin_10;
gpioInitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
gpioInitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init( GPIOC, &gpioInitStruct );

gpioInitStruct.GPIO_Pin = GPIO_Pin_11;
gpioInitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
gpioInitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &gpioInitStruct);

usartInitStruct.USART_BaudRate = baud;
usartInitStruct.USART_WordLength = USART_WordLength_8b;
usartInitStruct.USART_StopBits = USART_StopBits_1;
usartInitStruct.USART_Parity = USART_Parity_No;
usartInitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
usartInitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init( UART4, &usartInitStruct );

USART_Cmd( UART4, ENABLE );

// USART_ITConfig( UART4, USART_IT_RXNE, ENABLE); // 带着这行代码就无法运行,注释掉后可以运行!!!!!!
USART_ClearFlag( UART4, USART_FLAG_TC );

nvicInitStruct.NVIC_IRQChannel = UART4_IRQn;
nvicInitStruct.NVIC_IRQChannelPreemptionPriority = 3;
nvicInitStruct.NVIC_IRQChannelSubPriority = 3;
nvicInitStruct.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&nvicInitStruct);

}


请各位高手不吝指教,谢谢!
...全文
680 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_41212291 2021-07-13
  • 打赏
  • 举报
回复

大哥,你这最后怎么解决的呢,我也遇到这个问题了,没找到原因,

  • 打赏
  • 举报
回复
这种问题很明显,和你的.s启动文件没有关系的,你把中断打开程序就没法运行,说明你的串口接收中断服务程序没有写或者ISR内部指针跑飞了,如果你写了内部也没什么错误,那就说明你的中断向量表和你的ISR对应不上
hhhh63 2020-03-05
  • 打赏
  • 举报
回复
忘了写中断程序也会出现这个问题
dpbug_cn 2020-03-04
  • 打赏
  • 举报
回复
已解决,应该是.s启动文件错误。

27,370

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 单片机/工控
社区管理员
  • 单片机/工控社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧