# Serial communication between STM32F4 and PC -USART-

The question I will ask now is not about how to solve something, I am currently able to make the connection as it will be mentioned below, but my problem is I really did not understand WHY ? Thanks in advance.

Hey, I am trying to connect my STM32F4-DISC board to PC via USART. It is a very common and basic example like sending a string to PC COM port which is covered by lots of tutorials on the web. But my question is,

I first used this product and directly connected to my board's RX TX pins and I was able to get data but all the data was a mess.(Not random, always same but some characters I have never seen before.)

I think there was nothing wrong with connections because when I disconnect the jumper which connects the Rx of converter and Tx of DISC board, there was nothing ongoing even that messed up characters.

After lots of thinking about "what is wrong? is it code?( It could not be because only 3 lines of code and all examples writes the same thing) ", I found a little device which has a chip on it( I can't read what is the model or manufacturer) and one side is D sub 9 male and other side has 4 jumpers come out of that named as Rx,Tx,GND and 3.3V. Then I also used it and created a connection like this:

PC --USB ENTRANCE-- DIGITUS USB to serial adaptor -- D SUB 9 ENTRANCE -- THE IC I MENTIONED ABOVE -- JUMPERS -- STM32F4

After this setup I was able to see the correct text on the screen and everything worked well.

I researched about why this could be but did not understand. The digitus product itself looks like the only necessity to connect my board to PC but It does not work alone.

I wonder what is the real case?

USB to Serial adapters with a DE9 connector use RS-232 Voltage levels, where logical 0 is a positive voltage between 3 and 15 volts, and logical 1 is a negative voltage between -3 and -15 volts.

STM32 Microcontrollers use TTL-like signaling, where logical 0 is between approximately 0 and 0.7 volts, logical 1 is between 2 and 5 volts. Voltages below 0V would be registered as logical 0, as long as the MCU works, but they can likely damage it permanently. Apart from being extremely lucky that your board didn't blow up, you've got the bits inverted, that's why strange characters have appeared.

The other device would be a level converter, which translates the signals between the two standards.

There are products that can directly connect an USB ports to a 3.3V microcontroller UART port, look for an USB RS232 TTL 3.3V adapter.

I've disassembled an USB-RS232 adapter similar to that of the question. There is the FT232RL doing the USB to serial-TTL conversion, and an RS-232 transceiver, doing the voltage level shifting. You could theoretically remove the SP213E part, and connect the microcontroller UART port directly to the FT232RL.

Top side

IC markings on top side

Bottom side

IC markings on bottom side

• Hey @berendi thanks for your explanation, It was what I think also, but I that usb-serail adapter datasheet says that it uses a FTDI232RL chip on it. And on youtube I saw some videos in which people are connecting PC to Board without any addition using only that FTDI232RL (for example : youtube.com/watch?v=ewEne937YyQ ). This issue also confused my mind. – muyustan Jul 12 '19 at 8:40
• And also I used it connected for a long time while trying to understand what is wrong but it did not harm my MCU, could the reason be the following? : I was only sending data from MCU not receiving any. In this case it may be did not receive any harmful voltage. At least this is what I can think. – muyustan Jul 12 '19 at 8:41
• There is no telling what the actual drive strength and voltage levels are, and what additional components are in the adatper, without taking the thing apart, or measuring it. The FTDI232RL has a couple of configuration options. – followed Monica to Codidact Jul 12 '19 at 8:52
• The adapter can use any USB UART chip, and it has nothing to do with voltages on connector. Inside the adapter there is also a TTL to RS232 interface chip to convert the voltage levels. So it is not direct connection. – Justme Jul 12 '19 at 9:03
• @Justme hey, thanks for the answer. What I understood from your answer is, the thing creates voltage differences is the connector parts (D sub 9 in this case). Did I get it right ? – muyustan Jul 12 '19 at 9:08

The first product is a USB to RS232 interface converter, the standard RS232 interface sends UART data between devices using RS232 voltage levels, Logic 1 is negative and Logic 0 is positive, for voltages about +/- 5V to +/- 15V.

The STM32 Discovery board does not have a RS232 interface, the UART pins that use 3.3V MCU voltage logic levels are at the connector.

Therefore connecting this to a RS232 adapter does not work as the data is inverted, and the high voltage and current driving ability can break the MCU. So this is why you need a RS232 to logic level interface chip between STM32 and RS232 port, or the other solution would of course be to just get a 3.3V level USB adapter for direct connection.

Your STM32 board most likely has a logic-level USART (also known as TTL-level) while the Digitus device uses RS232 signaling. The difference, other than potentially different voltage levels, is that logic-level serial signal idle at 0 volts and a one bit is indicated by 3.3 or 5 volts while RS232 signals are inverted, idling high and going low for a one’s bit.

The intermediate device probably has an RS232 level converter chip, such as the MAX232 (Wikipedia). This both inverts the signals and contains a charge pump circuit to generate the higher voltages specified for RS232.

As a rule of thumb, if you have a DB connector or a 9 or 10 pin connector, you are probably working with RS232. If you have a simple row of 3, 4 or 5 pins, you probably have logic-level signaling.

• Hey @DoxyLover thanks for that useful answer, So then what is a USB to Serial device exactly? Because that Digitus product calls itself as being a USB to Serial converter. So when I want to communicate between a microcontroller and PC cannot I use a USB to serial named device? Does any product sold as USB to TTL contain these 2 steps as integrated? Sorry for these nested questions and thanks in advance. – muyustan Jul 12 '19 at 8:52
• It says on the product page that it is a USB to RS232 level serial adapter. It is not a USB to TTL level serial adapter. Both are serial adapters but with different voltage levels. All USB to Serial chips are TTL levels and they specifically need a extra RS232 tranceiver chip to become USB to RS232 adapters so USB to TTL adapters just omit the RS232 tranceiver. – Justme Jul 12 '19 at 9:12
• @Justme hey, please see the answer above which berendi edited with his images. It was that you are talking about right? – muyustan Jul 12 '19 at 16:59