В продолжение темы о прерываниях. USART2 почему-то упорно не хочет генерировать повторное прерывание. Один раз все случилось, благополучно обработалось, а второй и последующие разы - полный игнор. Ниже привожу процедуры инициализации USART2:
Код
/*******************************************************************************
* Function Name : UsartInit
* Description : Configures the USART2.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void USART_Init() {
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
USART_DeInit(USART2);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); /* Enable GPIO clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); /* Enable UART clock */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_USART2); /* Connect alternate function pins to USART */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_USART2); /* Connect alternate function pins to USART */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource1, GPIO_AF_USART2); /* Connect alternate function pins to USART */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource0, GPIO_AF_USART2); /* Connect alternate function pins to USART */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_1; /* Configure USART Tx as alternate function push-pull */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_0; /* Configure USART Rx as input floating */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_RTS_CTS;
USART_InitStructure.USART_BaudRate = 921600;
USART_Init(USART2, &USART_InitStructure); /* USART configuration */
NVIC_SetPriority(USART2_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 4, 0));
NVIC_EnableIRQ(USART2_IRQn);
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
USART_Cmd(USART2, ENABLE); /* Enable USART */
}
/*******************************************************************************/
и процедуру обработки прерывания:
Код
/*------------------------------------------------------------------------------
This function handles USART2 global interrupt request.
*-----------------------------------------------------------------------------*/
void USART2_IRQHandler(void) {
if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) {
HostProt_Parser(); // обработка принятого символа
} else {
ClearUSART_IT_Bits(USART2);
}
USART_ClearITPendingBit(USART2, USART_IT_RXNE);
}
/*------------------------------------------------------------------------------
В том что символ приходит на вход RX - уверен на 100%.
P.S. Я где-то натыкался на подобную тему, но не смог найти. Буду благодарен за любые подсказки.