AnsweredAssumed Answered

USART Receiver pointer to zero

Question asked by Dani Prieto on Jul 7, 2017
Latest reply on Jul 18, 2017 by Lucas C

I have a problem at the reception for 485.
I use an 8-position buffer where I keep what we receive for USART.
When I receive, if the size of the message is less than that of the buffer, the following receipt is written below what I already had.
How can I restart the index for this reception buffer?

 

/**
* @brief This function handles USART1 global interrupt.
*/

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 */

     receive_uart();
     contreceived++;


  /* USER CODE END USART1_IRQn 1 */
}


void receive_uart(void){
    
     if(HAL_UART_Receive_IT(&huart1, (uint8_t *)buffRx, 16) != HAL_OK)
          {
               /* Transfer error in reception process */
          //  Error_Handler();
          }
                   
     /*****Numero identificacio placa "NUM_IDXX" ********************************/
              
               if(buffRx[0]==0x4E){//'N'     "NUM_ID"
                    if(buffRx[1]==0x55){//'U'    
                         if(buffRx[2]==0x4D){//'M'                   


//REST of the code here, too long

That's what I receive first, and it's OK.

 

 

Here is the second reception, which overwrites the first.



Thank you in advance.
Daniel Prieto

Outcomes