What do real programmers use to debug software ? Right, printf. And
that’s what I also want to do from my ATMEGA168. So let’s add
a serial interface to the board that allows us to use printf and have
it displayed on our terminal window on our full fletched computer.
Introducing RS232
RS232 is the iconic name for the standard serial way of communicating. For years
all computers were equipped with at least on RS232 port, even further back, it
was all that was available.
One important aspect of RS232 is that both parties in the communication need to
use the same speed. Further, RS232 requires a bit (or voltage peak) to be in
the range of -12V to 12V.
It sounds all pretty old, but even today the basic RS232 remains probably the
best interface for any system to report back to its user. Until further notice,
I believe I will add it to any embedded design I’ll be making ;-)
The MAX232
To convert the -12V to 12V serial signal to one in the range of 0V to 5V, and
vise versa, we can rely on an IC (originally) produced by Maxim, the MAX232.
Integration is really easy and requires a few capacitors to allow the IC to
bump the charge.
Although Maxim isn’t the only vendor anymore, offering this kind of IC, the name
sticks, just like “a coke”.
4 capacitors of 0.1μF, two uplinks to VCC and GND and two connections to the
ATMEGA is all it takes to setup the hardware that allows the ATMEGA to
communicate with the outside world.
Terminal Emulation
Before hooking up TX and RX to the ATMEGA, you can test the MAX232 by itself.
With a wire, connect TX and RX and boot up a terminal session. This loop-back
allows for easy testing of the RS232 part of the design.
Because my Mac doesn’t come with a serial port anymore, I bought a Digitus USB
to serial
adaptor ↗ some time ago. The drivers supplied by
the vendor aren’t that up to date anymore, but luckily the use some other
vendor’s hardware and so I found recent
drivers ↗.
Terminal emulators are one of those whole wars. I tend to rely on
screen.
The Code
After wiring RX to ATMEGA’s pin 2 (PD0/RXD) and TX to pin 3 (PD1/TXD), the
circuit is ready to go. This is only the main part, for all details, refer to
my Github embedded repository ↗.
Compile and upload … (I’m using my cleaned up version of the previous
Makefile here)
Make sure you had a terminal emulation session ready to accept incoming
information …
Sorry, my website doesn’t use any cookies, no invisible pixels or whatever tracking mechanisms the web is littered with these days. It also doesn’t hot link ...
As a consulting nomad, I’m confronted with two kinds of holiday: the one most of us have, a break from the busyness at work, and then I also have the in-betw...
Ja, ik geef het toe: ik heb altijd gezegd dat ik “bij mijn leest ging blijven”. Dat ik de rol van software architect puur ging houden, omdat daar mijn kracht...
Ever since I designed and had my concrete house constructed, I wanted to create some personal concrete art pieces. So, as usual, it took a few years before I...