UART_FLAG_TXE and UART_FLAG_TC not being set and reset during serial UART communication. How can I fix this?
Hello,
I have made a custom board for the STM32G070KBT6 MCU to interface with other boards in an embedded project. I have added a mini–USB B connector to the PCB to communicate between the MCU and my computer. In the MCU, I am using one of the USART channels in asynchronous mode with hardware flow control (CTS/RTS) for this communication. I have connected the Tx, Rx, CTS, and RTS pins to the corresponding pins on an FTDI USB-UART converter chip (FT231XS-R) in the following configuration:
MCU -> FTDI
-------------------
Tx -> Rx
Rx -> Tx
CTS -> CTS
RTS -> RTS
The FTDI chips connects to an ESD protection IC (USBLC6-2SC6) and then from that IC to the mini-USB connector on the board. When I plug the cable into my computer, I detect the FTDI device on one of my COM ports (COM3).
After I setup the initialisation of all the peripherals on STM32CubeIDE, I wrote the following code in the while(1) loop to test the serial connection:
strcpy((char*)buf, "H");
HAL_UART_Transmit(&huart2, buf, strlen((char*)buf),HAL_MAX_DELAY);In the main function above this loop, I had defined the buffer as follows:
uint8_t buf[10];When I run the program in debug mode, I find that it gets stuck in a loop in the (stm32g0xx_hal_uart.c) file where it is waiting for a flag to be set. When I try to send a different character than just "H" as above ("Hello" for example), the TXE flag is not set and the (UART_WaitOnFlagUntilTimeout) function gets stuck in a loop. When I only send "H", the TC flag is not set and the same functions gets stuck in a loop.
EDIT: I've been doing some research and come across different voltage levels. Do I need to have a voltage level shifter (MAX232 for example) or equivalent to communicate between the MCU and the computer? Or am I not thinking along the correct lines?
I'm not sure what I need to do here to correctly send data. I can provide more information if it's needed.
Thank you!
