2014-06-13 06:51 AM
Hello,
I have a problem to configure two interruptions in the same time. The first one is to receive data from UART, the second one is to send data to motors. After several successful itterations, UART Status stops at RESET, when the other routine continue to work. You find follow the configurations of the two interruptions : /******************** Config IRQ TIM2 **********************/ void INTTIM_Config_cmd(void) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; NVIC_InitTypeDef NVIC_InitStructure; // Enable the TIM2 gloabal Interrupt NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 5; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); // TIM2 clock enable RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); // Time base configuration TIM_TimeBaseStructure.TIM_Period = 5000 - 1; // 1 MHz down to 1 KHz (1 ms) TIM_TimeBaseStructure.TIM_Prescaler = 84 - 1; // 24 MHz Clock down to 1 MHz (adjust per your clock) TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); // TIM IT enable TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE); // TIM2 enable counter TIM_Cmd(TIM2, ENABLE); } /******************** Config IRQ UART **********************/ void Wifi_HAL_uart_Init(uint32_t baudrate) { GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; /* Enable GPIO clock */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); /* Enable UART clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, ENABLE); //RCC_APB2PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); /* Connect PXx to USARTx_Tx*/ GPIO_PinAFConfig(GPIOC, GPIO_PinSource12, GPIO_AF_UART5); /* Connect PXx to USARTx_Rx*/ GPIO_PinAFConfig(GPIOD, GPIO_PinSource2, GPIO_AF_UART5); /* Configure USART Tx as alternate function */ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_InitStructure); /* Configure USART Rx as alternate function */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; GPIO_Init(GPIOD, &GPIO_InitStructure); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); /* Enable the USART1 Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = UART5_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* USART configuration */ USART_InitStructure.USART_BaudRate = baudrate; 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(UART5, &USART_InitStructure); USART_ITConfig(UART5, USART_IT_RXNE, ENABLE); /* Enable USART */ USART_Cmd(UART5, ENABLE); } // UART routine void UART5_IRQHandler(void) { if(USART_GetITStatus(UART5, USART_IT_RXNE) != RESET) { RxBuffer[RxBufferHead] = USART_ReceiveData(UART5); RxBufferHead = (RxBufferHead + 1) % RX_BUFFER_SIZE; } }