UART Reception Until Newline Character on STM32F767 with TeraTerm Using CMSIS v2
Hello ST Community,
I’m working on a project with the Nucleo F767ZI development board, and I’m using CMSIS v2 for the RTOS. My goal is to implement UART communication where the system continuously receives characters until a newline character ("\n") is detected. Once "\n" is received, I want to process the received string and transmit it back over UART.
What I've Done:
UART Configuration:
- Baud Rate: 115200
- Data Bits: 8
- Parity: None
- Stop Bits: 1
- Flow Control: None
Task Setup:
I’ve created a uartTask thread that initiates UART reception using HAL_UART_Receive_IT, receiving one character at a time:
void uartTask(void *argument) {
while (1) {
if (huart3.gState == HAL_UART_STATE_READY) {
HAL_UART_Receive_IT(&huart3, &rxBuffer[rxIndex], 1);
}
osDelay(100);
}
}
Callback Function:
In HAL_UART_RxCpltCallback, I check for the newline character and, upon detection, transmit the entire buffer back and reset the index:
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) {
if (huart->Instance == USART3) {
if (rxBuffer[rxIndex] == '\n') {
HAL_UART_Transmit(huart, rxBuffer, rxIndex + 1, HAL_MAX_DELAY);
rxIndex = 0;
} else {
rxIndex++;
}
HAL_UART_Receive_IT(huart, &rxBuffer[rxIndex], 1);
}
}
Issue:
I’m using TeraTerm to test the UART communication. I configured TeraTerm with the following settings:
- Correct COM port for the Nucleo F767ZI
- Baud Rate: 115200
- Data Bits: 8
- Parity: None
- Stop Bits: 1
- Flow Control: None
I’m typing characters directly into TeraTerm and pressing Enter to send the newline character (\r\n). However, the callback function doesn’t always seem to trigger as expected. The characters are not being received continuously until "\n", and sometimes the callback isn’t triggered at all.
Here’s what I’ve already checked:
- UART Interrupts: They are enabled in the NVIC for USART3.
- UART State: I ensure the UART state is ready before initiating reception.
- Echo Test: I tried a simple echo test, and it’s consistent.
Has anyone else experienced similar issues or have suggestions on what might be going wrong? Any help or insights would be greatly appreciated.
Thanks,
Ajaykumar V
