初级会员

- 积分
- 70
- 金钱
- 70
- 注册时间
- 2018-9-25
- 在线时间
- 13 小时
|
1金钱
当前程序串口发送可以成功,但是接收数据进入中断时,没有进入void USART1_IRQHandler(void) 方法,而是进入了void __attribute__ ((section(".after_vectors")))Default_Handler(void)这是什么问题呢?
看起来貌似跟中断向量是不是有关系啊?这里应该怎么做呢??小弟本行是做Java的,自学这个还是有些吃力。
断点看到的结果
程序部分如下:
common.cpp
---------------------------------
[mw_shl_code=cpp,true]
// 串口1初始化
void uart1_init(u32 baud) {
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA,
ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure USART1 Rx (PA.10) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* USART1 mode config */
USART_InitTypeDef USART_InitStructure;
USART_InitStructure.USART_BaudRate = baud;
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(USART1, &USART_InitStructure);
//Usart1 NVIC 配置
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3; //抢占优先级3
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //子优先级3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); //开启串口接受中断
//使能串口1
USART_Cmd(USART1, ENABLE);
}
//串口1中断服务程序
void USART1_IRQHandler(void) {
u8 Res;
//接收中断(接收到的数据存入缓冲区)
if (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) {
Res = USART_ReceiveData(USART1); //读取接收到的数据
__uart1_buffer[__start + __length] = Res;
__length++;
}
}[/mw_shl_code]
main.cpp
--------------------------
[mw_shl_code=cpp,true]#include "common.h"
int main() {
delay_init();
uart1_init(115200);
u8 count = 0;
while (1) {
uart1_printf("当前count = %d\n", count++);
delay_ms(200);
}
}[/mw_shl_code]
|
|