大家好,小弟用107vc的串口1和串口2做实验板子,串口1能进中断,串口2却进不了,但串口2用查询方式可以接收到数据。大家帮忙看看我这样配置哪些地方不对呢。
#define InterruptClear_EnableReg1 (*((volatile unsigned long *)0xE000E184)) //中断允许复位寄存器1
#define InterruptClear_EnableReg2 (*((volatile unsigned long *)0xE000E188)) //中断允许复位寄存器2
#define USART1_IntFlag 0x00000020; //USART1中断允许位偏移值
#define USART2_IntFlag 0x00000040; //USART2中断允许位偏移值
串口1配置
/* Configure UART1 for 2400 baud. */
AFIO->MAPR &= 0xFFFFFFFB; //不映像
GPIOA->CRH &= 0xFFFFF00F;
GPIOA->CRH |= 0x000004B0;
RCC->APB2ENR |= 0x00004000; //Enable USART#1 clock
USART1->BRR = 0x73E0; // Configure 2400 baud
USART1->CR3 = 0x0000; // 8 bit, 1 stop bit
USART1->CR2 = 0x0000; // no parity
USART1->CR1 = 0x202C;
InterruptClear_EnableReg1=0xffffffff;
InterruptSet_EnableReg1=0;
InterruptSet_EnableReg1|=USART1_IntFlag; //NVIC核允许USART1中断发生
串口2配置
/* Configure UART2 for 4800 baud. */
AFIO->MAPR |= 0x00000008; //映像
GPIOD->CRL &= 0xF00FFFFF;
GPIOD->CRL |= 0x04B00000;
RCC->APB1ENR |= 0x00020000; //Enable USART#2 clock ; Disable I2C1
USART2->BRR = 0x1CF8; //Configure 4800 baud
USART2->CR3 = 0x0000; // 8 bit, 1 stop bit
USART2->CR2 = 0x0000; //no parity
USART2->CR1 = 0x202C;
InterruptClear_EnableReg2=0xffffffff;
InterruptSet_EnableReg2=0;
InterruptSet_EnableReg2|=USART2_IntFlag; //NVIC核允许USART2中断发生
#define InterruptSet_EnableReg1 (*((volatile unsigned long *)0xE000E104)) //中断允许置位寄存器1
#define InterruptSet_EnableReg2 (*((volatile unsigned long *)0xE000E108)) //中断允许置位寄存器2
你没有调用库,乱78遭的, 我也遇到过同样的问题。你的问题肯定是中断这块有问题,你好好看看,NVIC定义后有没有调用初始化?中断使能有没有打开?