Question
Read a character from the UART
I want to read one character from the UAR and display it.
I am using CoolTerm.
But nothing is displayed.
What's wrong with my getchar function?
Or is the code in the while loop wrong?
char getchar() {
char data[1];
HAL_UART_Receive(&huart2, (void*)data, 1, HAL_MAX_DELAY);
return data[0];
}
while (1)
{
HAL_UART_Transmit(&huart2,(uint8_t *) "Test",4,HAL_MAX_DELAY);
HAL_UART_Transmit(&huart2,(uint8_t *) getchar(),1,HAL_MAX_DELAY);
}