UART Rx Buffer
Hi Comunity,
I am very new to STM and got some problems on serial UART. I can get data from my serial, but my problem is if the data received is less than the length of the array, the next data received doesn't overwrite the first data. How do I fix this problem?
The first data is this.

The second data after clearing the array is like this.

The data sent for the board to receive is just "1234567". What I want to achieve is if the data received is less than the array length, the second data I get after that don't continue like the picture above.
The code used is shown below.
char RxData[10];
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART1_UART_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_UART_Receive_IT(&huart1, (uint8_t *)RxData, 10);
HAL_Delay(5000);
for (int i = 0; i < 10; i++){
RxData[i] = '\0';
}
}
/* USER CODE END 3 */
}
