Question
USART Receiver pointer to zero
Posted on July 07, 2017 at 11:19
Thank you in advance.
Daniel Prieto
#buffer #rs485 #usart
I have a problem at the reception for 4
I use an 8-position buffer where I keep what we receive for USART. When I receive, if the size of the messageis less than that of the buffer, the following receipt is written below what Ialready 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
#buffer #rs485 #usart