rhs*_*hso 1 c stm32 interruption usart
我在地图上开发我正在研究STM32和USART中断.配置USART1并使能接收中断后.接收中断没有检测到的问题????
Ver*_*rax 10
如果不知道您使用的是哪个特定处理器,您正在使用哪个电路板,和/或您正在使用哪个编译器,则很难回答这样的问题.但是为了有所帮助,这是我的代码.
这是我的GPIO和NVIC初始化代码,使用Sourcery CodeBench Lite和安装在自定义板上的STM32F4处理器.
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_USART3);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_USART3);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
GPIO_Init(GPIOB, &GPIO_InitStructure);
// Enable the USART RX Interrupt
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
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);
Run Code Online (Sandbox Code Playgroud)
当然,您的设置将根据您的处理器,电路板和中断优先级而有所不同.
这是我的中断处理程序代码.在我的开发环境中,这个处理程序在我的启动程序集文件中声明为对Default_Handler... 的弱引用
Default_Handler:
b .
/* ... */
.word USART3_IRQHandler
/* ... */
.weak USART3_IRQHandler
.thumb_set USART3_IRQHandler,Default_Handler
Run Code Online (Sandbox Code Playgroud)
...所以只要我提供这个中断处理程序的新声明和实现,就会替换弱引用.这是我的代码的样子.
//Interrupt handler declaration
void USART3_IRQHandler();
Run Code Online (Sandbox Code Playgroud)
如果您使用的是C++,则需要按如下方式声明:
//Interrupt handler declaration in C/C++
#ifdef __cplusplus
extern "C" {
#endif
void USART3_IRQHandler();
#ifdef __cplusplus
}
#endif
Run Code Online (Sandbox Code Playgroud)
这是中断处理程序的实现.
//Interrupt handler implementation
void USART3_IRQHandler()
{
//handle interrupt
}
Run Code Online (Sandbox Code Playgroud)