cancel
Showing results for 
Search instead for 
Did you mean: 

UART_FLAG_TXE and UART_FLAG_TC not being set and reset during serial UART communication. How can I fix this?

HNass.2
Associate II

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Bob S
Principal

UART/RS232 "null modem" (i.e. cross-over) cables need CTS->RTS and RTS->CTS, as well as the RX/TX cross connections you already have.

The FT231X should output 3.3V signal levels. Did you measure the actual voltage levels in your system, or just read about different levels "somewhere on the internet"?

View solution in original post

5 REPLIES 5

Read out and check/post content of UART and relevant GPIO registers.

JW

Bob S
Principal

UART/RS232 "null modem" (i.e. cross-over) cables need CTS->RTS and RTS->CTS, as well as the RX/TX cross connections you already have.

The FT231X should output 3.3V signal levels. Did you measure the actual voltage levels in your system, or just read about different levels "somewhere on the internet"?

You have a common ground connected as well as RX, TX ?

Flags not being set sound more indicative of the peripheral clocks not being enabled.

Dump RCC and UARTx registers

Show the initialization code, for UART, pins, peripheral, clocks.

MCU is going to be operating at CMOS levels, not RS232, so not suitable to connect to a PC's DB9 connector, for example.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Thank you @Bob S​. Rookie error but I hadn't realised I need to cross-over the CTS and RTS cables and I think that was the problem. I believe I was following 'Legacy hardware flow control' (AN0059.0: UART Flow Control (silabs.com)). I've kept the connections as they are on the board for now (will maybe switch them in the next revision) but disabling hardware flow control in the STM32CubeIDE 'Pinout and Configurations' tab seems to have done the trick. I guess the MCU wasn't getting the signal to send the data and therefore wasn't setting the appropriate flags for the transmission registers.

Regarding the signal levels it was just something that I read online. Since I've read your comment though I've probed my board using an oscilloscope. Both at the Tx line from the MCU and at the output of the FT231X (and at the mini-USB B connector) the signals levels are at 3.3V.

Thank you @Community member​. Yes, I have a common ground connected as well. The peripheral clocks were enabled, and the initialisation code I used was auto generated by the IDE. It seems that I had mis-connected the CTS and RTS lines and didn't cross them over. Disabling the hardware flow control in the IDE seems to have fixed the error and I can now send data from my MCU and read it on my computer's serial terminal.