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.
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 ;-)
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.
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
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
Terminal emulators are one of those whole wars. I tend to rely on
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
Make sure you had a terminal emulation session ready to accept incoming