AnsweredAssumed Answered

Uart recive

Question asked by mahmoud boroumand on Mar 11, 2018
Latest reply on Mar 12, 2018 by mahmoud boroumand

hello

i use stm32f107 and use to standard standard peripheral library but now i have use hal drive and i new on it.

i want to build a transmitter receiver.i want when receive data in mcu  i get an interrupt .when i use standard peripheral library i don't have problem and i get interrupt every a byte . i use this code  but i get interrupt only one time 

how can i fix that?

 

GPIO_InitTypeDef GPIO_InitStruct;
/* USER CODE END USART2_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_USART2_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();

/**USART2 GPIO Configuration
PA2 ------> USART2_TX
PA3 ------> USART2_RX
*/
GPIO_InitStruct.Pin = GPIO_PIN_2;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

GPIO_InitStruct.Pin = GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

/* USART2 interrupt Init */
HAL_NVIC_SetPriority(USART2_IRQn, 1, 0);
HAL_NVIC_EnableIRQ(USART2_IRQn);


huart2.Instance = USART2;
huart2.Init.BaudRate = 115200;
huart2.Init.WordLength = UART_WORDLENGTH_8B;
huart2.Init.StopBits = UART_STOPBITS_1;
huart2.Init.Parity = UART_PARITY_NONE;
huart2.Init.Mode = UART_MODE_TX_RX;
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&huart2) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
if(HAL_UART_Receive_IT(&huart2, RxBuffer1 , 2) != HAL_OK)
{
Error_Handler();
}

 

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *UartHandle)
{
///////Receive Data Here 

}

 

void USART2_IRQHandler()
{


HAL_UART_IRQHandler(&huart2);

}

Outcomes