1、无法进入串口接收中断。根据lib中的例程,对串口进行了配置,如下:
void GPIO_Configuration(void)
{
GPIO_InitType GPIO_InitStructure;
//TX
GPIO_Structure_Initialize(&GPIO_InitStructure);
GPIO_InitStructure.Pin = GPIO_PIN_2;
GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP;
GPIO_InitStructure.GPIO_Alternate = GPIO_AF5_USART2;
GPIO_Peripheral_Initialize(GPIOA, &GPIO_InitStructure);
//RX
GPIO_InitStructure.Pin = GPIO_PIN_3;
GPIO_InitStructure.GPIO_Alternate = GPIO_AF5_USART2;
GPIO_Peripheral_Initialize(GPIOA, &GPIO_InitStructure);
}
void RCC_Configuration(void)
{
/* Enable GPIO clock */
RCC_AHB_Peripheral_Clock_Enable(RCC_AHB_PERIPH_GPIOA );
/* Enable USARTy and USARTz Clock */
RCC_APB1_Peripheral_Clock_Enable(RCC_APB1_PERIPH_USART2);
}
void NVIC_Configuration(void)
{
NVIC_InitType NVIC_InitStructure;
/* Enable the USARTy Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Initializes(&NVIC_InitStructure);
}
void uart_init(void)
{
USART_InitType USART_InitStructure;
RCC_Configuration();
NVIC_Configuration();
GPIO_Configuration();
USART_InitStructure.BaudRate = 115200;
USART_InitStructure.WordLength = USART_WL_8B;
USART_InitStructure.StopBits = USART_STPB_1;
USART_InitStructure.Parity = USART_PE_NO;
USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE;
USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX;
/* init uart */
USART_Initializes(USART2, &USART_InitStructure);
/* Enable USARTz Receive and Transmit interrupts */
USART_Interrput_Enable(USART2, USART_INT_RXDNE);
// USART_Interrput_Enable(USART2, USART_INT_TXDE);
/* enable uart */
USART_Enable(USART2);
}
中断程序如下:
void USART2_IRQHandler(void)
{
if (USART_Interrupt_Status_Get(USART2, USART_INT_RXDNE) != RESET)
{
/* Read one byte from the receive data register */
USART_Interrupt_Status_Clear(USART2, USART_INT_RXDNE);
// recv_data = USART_Data_Receive(USART2);
// RingBuffer_Write((uint8_t *)&recv_data, 2);
USART_Data_Send(USART2, USART_Data_Receive(USART2));
LED1_OFF;
if(recv_data == 0x11)
{
LED1_ON;
}
}
}
程序在正常运行的时候,可以正常发送数据,但是进不了串口接收中断。
2、多次下载后,程序无法正常运行。现象是:我在main函数中写了闪灯程序,正常运行的时候,会闪烁。但是多次下载后,就没闪灯了,而且没有串口日志打印,因此判断程序未正常运行。然后debug调试的时候,可以正常运行main函数中的程序,同样无法进入串口接收中断。复位后,板子依然是无法运行程序的状态。
以上是遇到的两个问题,请各位大佬指点指点,或者帮忙分析分析。
|