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

Aircon Repair on Hyundai Getz (on the hottest day of the year)

Yesterday was the hottest day of the year 2013 to date. Temperatures reached 36 degrees C. Normal value for this time of year is about 24 degrees (according to KNMI). My wife's car, a Hyundai Getz had a broken AC unit and I decided to fix it.  The AC light lit up just like normal but the clutch to the compressor did not kick in. After spending hours googling for schematics and diagrams, reading forums I found out why. The system is protected by a clever pressure switch, (conveniently located behind the glove compartment) It disables the clutch when pressure is too high or too low. After checking all things electrical, fuses, sensors, the clutch, the fans and switches I was out of options, I could not measure the pressure in the system. I visited a local car repair shop specialized in Airco systems, Rene van de Louw, st. Oedenrodeseweg 40, and he quickly noticed that I had a leak in my condenser. How? He put some pressure on the system with nitrogen and I could hear a hissing so