cancel
Showing results for 
Search instead for 
Did you mean: 

CubeMX -Uart interrupt work one time

PINI BITON
Associate II
Posted on December 10, 2017 at 11:16

Hi

i'm config evboar  nucleo with CubeMX 

the send  data work fine but  recive data with HAL_UART_RxCpltCallback

i's work one time and second time is stuck in  loop and

don't reach to HAL_UART_IRQHandler(&huart1) again ;

i don't know why it's working one time(  maybe is relevant to RXN flag  )

thanks

static void MX_USART1_UART_Init(void)

{

  huart1.Instance = USART1;

  huart1.Init.BaudRate = 115200;

  huart1.Init.WordLength = UART_WORDLENGTH_8B;

  huart1.Init.StopBits = UART_STOPBITS_1;

  huart1.Init.Parity = UART_PARITY_NONE;

  huart1.Init.Mode = UART_MODE_TX_RX;

  huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;

  huart1.Init.OverSampling = UART_OVERSAMPLING_16;

  huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;

  huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;

  if (HAL_UART_Init(&huart1) != HAL_OK)

  {

    Error_Handler();

  }

HAL_NVIC_EnableIRQ(USART1_IRQn);

}

void USART1_IRQHandler(void)

{

  /* USER CODE BEGIN USART1_IRQn 0 */

  /* USER CODE END USART1_IRQn 0 */

  HAL_UART_IRQHandler(&huart1);

  /* USER CODE BEGIN USART1_IRQn 1 */

  /* USER CODE END USART1_IRQn 1 */

}

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)

{

if(huart->Instance == USART1)

  {

if(RX_Data=='*' || RX_Index>19 )RX_Index=0;

if(RX_Data !='♯')

{

RX_Buff[RX_Index++]=RX_Data;

}

else

{

Sync_RX=1;

}

HAL_UART_Receive_IT(&huart1,&RX_Data,1);

  }

}

#cubemx #uart
1 REPLY 1
Doug Kehn
Senior
Posted on December 12, 2017 at 14:18

I would suggest (1) checking the return value of HAL_UART_Receive_IT() in HAL_UART_RxCpltCallback, (2) implement HAL_UART_ErrorCallback() to determine if an error is being generated.