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 (https://www.olimex.com/Products/ARM/ST/STM32-E407/open-source-hardware)



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 : https://www1.elfa.se/data1/wwwroot/assets/datasheets/ep171_xxG_dat_en.pdf

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.






Reacties

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 investigated methodically,…

Raspberry Pi, PyFace Digital, the lost documentation, I found it finally

The Raspberry PI or R-pi from http://www.raspberrypi.org/ is well known these days.
It is not an accident that I have one, I have been doing Linux stuff since 1991, and professionally since 1996 I can not skip over these developments, have to keep up with the new kids. :-)
Times have changed, hardware has become very affordable, everybody knows the Arduino, Raspberry Pi and Beagle-Bone-Black (BBB). Not everybody knows the stuff that http://www.acmesystems.it/ aka Acme-Systems and https://github.com/OLIMEX/OLINUXINO aka Olimex make, so I will endorse them here.
Since I am an engineer I expect to connect switches and relays to the boards and some documentation with products, not so with the "PiFace Digital" board, it comes without serious documentation, not a even the schematic. All links on their blog point nowhere. People asked them many times, yet nowhere is the schematic to be found.

I finally found some info after hours of google-work, someone made a copy!
https://github.c…

Nederland van het aardgas af, dat schiet lekker op (NOT!)

Om dingen even in perspectief te plaatsen moet je gewoon even wat berekeningen maken.
We gaan Nederland van het aardgas afhalen (de burgers) omdat?

https://www.ad.nl/wonen/nederland-heeft-nog-lange-weg-te-gaan-gasverbruik-stijgt~aaf1527e/

In USA fakkelen ze 2123763,4944 m3 aardgas af per UUR
(bij winning van olie, gas is ongewenst daar, opslag niet handig, goedkoper om te fakkelen)


1.8 miljard cubic feet per dag...

Ons Nederlandse gasverbruik (huishoudens) is : 1500 m3 per jaar per huishouden

Even rekenen 2.1 miljoen m3 per uur, dat is

24 * 365 * 2.100.000,00 = 18.400.000.000,00 m3 aardgas affakkelen per jaar

(even de rekenmachine pakken)

18.400.000.000 / 1500 => aantal huishoudens Nederland

dat is voor 12.3 miljoen huishoudens (met gasverbruik van 1550 m3/jr)

Naast het opbranden lozen ze ook nog gewoon aardgas direct in de atmosfeer. (genaamd Venting)

Waarom moet ik ook alweer van het aardgas af?

Niet voor het milieu en de toekomst van onze kinderen, daarvoor helpt het helemaal…