串口想做成接收中断方式,
/* 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;
void USART1_IRQHandler(void) //串口中断处理程序
{
UARTLed_Flash(1); //亮灯
Pro_USART1_RecData(); //串口数据处理
}
但是进不了中断,用查询方式是可以的。
想问,还有什么地方要设置的吗?
串口1中断调通了,但串口2中断还是没调通,麻烦帮我看看还有那些地方要设置的。
#define InterruptSet_EnableReg2 (*((volatile unsigned long *)0xE000E108)) //中断允许置位寄存器2
#define USART2_IntFlag 0x00000040; //USART2中断允许位偏移值
/* Configure UART2 for 9600 baud. */
AFIO->MAPR |= 0x00000008; //映像
GPIOD->CRL &= 0xF00FFFFF;
GPIOD->CRL |= 0x04B00000;
RCC->APB1ENR |= 0x00020000; //Enable USART#2 clock ; Disable I2C1
USART2->BRR = 0x073e; //Configure 19200 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中断发生
void USART2_IRQHandler(void) //串口2中断处理程序
{
USART2->CR1 = 0x200C;
Pro_USART2_RecData(); //接收串口2数据
USART2->CR1 = 0x202C;
}