Doorgaan naar hoofdcontent

RX TX of a USART is easy (right?)

Today I figured it out.
What did you figure out, I hear you say...

I finally resolved a problem with a USART on a STM32F407 board, that was easy to spot if I had just looked closely. I just lost a day in trying to find the fault.

I am working with this board made by Olimex (

And connected it using ST-Link interface to my PC.

I connected the SWD pins to the JTAG connector of the Olimex

SWD-pin-1 ------ JTAG-pin-1 (VCC)
SWD-pin-2 ------ JTAG-pin-9 (TCK)
SWD-pin-3 ------ JTAG-pin-4,6,8 (GND)
SWD-pin-4 ------ JTAG-pin-7 (TMS)
SWD-pin-5 ------ JTAG-pin-15 (TRST)
SWD-pin-6 ------ JTAG-pin-13 (TDO)

I connected the serial port (USART6 is pins 3 and 4 of UEXT) of the Olimex to the TX/RX lines of the ST-link (see the green circle)

Then I wrote a program and tested it.
I made sure the PLL of the STM32F407 was running, configured all the needed files.

  • defined the target cpu in stm32f4xx.h (STM32F40_41xxx)
  • defined the real crystal frequency to be 12MHz (HSE_VALUE 12000000 in stm32f4xx.h)
  • defined the PLL values in system_stm32fxx.c (used cubeMX to verify many times)
  • defined the correct baud rate, bits and parity...
It almost worked..

The output of the USART (my print statements) looked fine for about 30 chars and the became a mess.

I googled for a day, checking baud-rates and device initialization.
Changed baud-rates, clock frequencies and everything else.... but still it would go messy after about 30 chars..

Guess what happend, I mixed up TX and RX... Transmit and Receive wires..
But.. but... I can hear you thinking, why did it work for the first 30 chars?

Well.. take a look at my setup..

As you can see the TX and RX wires are 25 cm long and very parallel because it was cut from a standard flat cable.

Looking up the specs for flat cable :

Capacitance— 46pF/m for normal 1.27mm flat cable.
So we have about 11 pF between the RX and TX wire.

Since the RX wires are not terminated on any side (no pull ups present) the impedance of the RX is very high, so high that the capacitive coupling between TX and RX was enough to swing the RX input the rhythm of the TX wire.
This works because of the large pause at the start of the transmission and possibly the impedance change of the RX during reset of the MCU (did not check this).
After about 30 chars the voltage between RX and TX is equalized and the receiver can not detect the edges of the signal anymore.

Lessons learned :
  • make sure RX is terminated with a pull up, or at least pulled up via software
  • check wire connections
  • the MCU world is not a digital world, it just looks that way when stuff is working well.
Until next time.


Populaire posts van deze blog

Denon DHT T100 DESIGNED TO FAIL : bad caps (ceramic caps this time)

A friend gave me a Denon DHT-T100 to look at. Do not spend much time on it.. ok. It had a problem, it started clicking and ticking after power on, and after some time. (a so called intermittent problem) Sometimes it did not tick or click, but it was basically not usable. The clicking had a sharp click in one channel and repeated after about a second, then sound recovered and it would click and drop out again. He told me, do not spend any time on it, yeah, right. ;-) like I would give up after 15 minutes. I wanted to know what was going on with this thing, I found some schematic online and started measuring the usual things. The power supply, 24V did it drop down when a tick occurred ? Difficult to find out because sometimes the thing would play for hours without a glitch. I eventually found out the 24 V PSU, the step down SMPS on board and the LDO's were all ok, all power rails remained within spec, but it still glitched sometimes. (while power was ok) I investigat

Fixed voltage on cheap buck converter (MP1584) conversion with single 0805 resistor

Everywhere I look on the Ali and Ebays I see these step down converters based on MP1584. I bought a couple and actually they are not bad at all. The output voltage is set by the trimming-resistor in the left top corner of the picture. This works OK, but.. it is dangerous because it is rather sensitive to the touch. I decided that I wanted fixed output, so I had to figure out how this thing worked. The datasheet looks like this : R1 in the datasheet is what I call "R feedback" in my image. The value of R2 is mostly 8.2K Ohm in the boards I have seen.  So to set some common values for output voltage: change R1 to 27K for 3V3 output (actually 3.4 volt, but 27K is a standard value) or change R1 to 43K0 for 5.0 Volt output. (43 K is a standard value) A standard 0805 size resistor fits precisely, how convenient ;-). Make sure the other resistor is really 8.2K because that determines the feedback ratio. This way you can not burn up your circ

DPS5005 power supply, remote control using python serial port modbus

Just a short one. I bought one of these things. It can do 50 volt 5 Amp, I have not looked at the quality of the output (noise, overshoot all unknown to me)  but should be alright to control a lamp, a battery or a strip of LED's is my guess. You can easily control the current and voltage output using a serial port. (a usb-serial-rs485 was provided) I seems to talk modbus protocol. To change the baud rate and modbus-slave-address, keep POWER button pressed during power on, this will enter you into the configuration menu. register list here : Register Map for this device. Function Description Number of bytes Decimal places UNIT Read/Write Register address U-SET Voltage setting 2 2 V R/W 0000H I-SET Current setting 2 3 A R/W 0001H UOUT Output voltage display value 2 2 V R 0002H IOUT Output