Toggle navigation
科创
{{ getSearchSuggestionLabel(suggestion) }}
{{ part.text }}
查看更多
登录
 
注册
电波
论坛
专栏
应用
登录
注册
{{ getSearchSuggestionLabel(suggestion) }}
{{ part.text }}
查看更多
论坛
>
电子信息
>
电子技术
>
嵌入式
文号
t28540
阅读
16895
回复
9
收藏
6
stm32 的问题,usart 中断怎么进不去
azenis_xing
2010/08/20
电子技术
IP:陕西
我的stm32 中断为什么进不去,都弄了好几天了,郁闷啊!
望高手指教,代码如下:
#include <stm32f10x.h>
#include "stm32f10x_it.h"
void UART2_GPIO_Configuration(void);
void UART2_Configuration(void);
void NVIC_Configuration(void);
void delay(uint32_t nCount);
int main()
{
SystemInit();
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
NVIC_Configuration();
UART2_GPIO_Configuration();
UART2_Configuration();
while(1)
{
这里不停的发送那个变量的值,初始值为0,进入接受中断后更改其值
}
}
/*********************************配置UART2的GPIO口*************************************/
void UART2_GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
// Configure USART1_Tx as alternate function push-pull
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
// Configure USART1_Rx as input floating
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE); //复用重映射UART2
}
/************************************配置串口2参数***********************************/
void UART2_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
USART_InitStructure.USART_BaudRate = 115200;
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(USART2, &USART_InitStructure);
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); //使能UART2接收中断
USART_Cmd(USART2, ENABLE);
}
/*******************************************************************************
* Function Name : NVIC_Configuration
* Description : Configures NVIC and Vector Table base location.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure one bit for preemption priority */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
中断服务程序如下:
if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)
{
/* Disable SC_USART RXNE Interrupt */
在这里我通更改一个变量的值,然后再主函数里继续死循环的发送。
}
但是,一旦从电脑上通过串口发送个数据,就死掉了,是怎么回事啊!
来自:
电子信息
/
电子技术
/
嵌入式
9
0
全部
只看作者
azenis_xing
作者
16年5个月前
IP:未同步
250404
1楼
再补充一点,就是在中断里已经通过读取数据进行过清除中断标志了,用过了clearpending 了,望老手指教,怎么回事啊
加载全文
引用
评论
0
azenis_xing
作者
16年5个月前
IP:未同步
250535
5楼
继续问
现在不死了,可能先前是哪没连接好吧
现在的问题是进入不了接收中断,也就是在串口调试助手上看不到接收的数据,看了下配置,应该没问题啊,到底怎么回事啊?
加载全文
引用
评论
0
全部
只看作者
在列表中查看
笔记
{{note.content}}
{{n.user.username}}
{{fromNow(n.toc)}} {{n.status === noteStatus.disabled ? "已屏蔽" : ""}} {{n.status === noteStatus.unknown ? "正在审核" : ""}} {{n.status === noteStatus.deleted ? '已删除' : ''}}
编辑
删除
{{n.status === 'disabled' ? "解除屏蔽" : "屏蔽" }}
保存
取消
我也是有底线的
保存中...
保存