μKenbak-1 Can the ATMega328 be programmed through its serial port?

23 views
Skip to first unread message

Frank P.

unread,
Nov 17, 2018, 4:21:33 PM11/17/18
to Altair-Duino
Can the ATMega328 be programmed directly through its serial port, without an intervening Arduino UNO?

Jim Manley

unread,
Nov 17, 2018, 6:39:23 PM11/17/18
to fcpr...@gmail.com, uken...@googlegroups.com

On Sat, Nov 17, 2018 at 2:21 PM Frank P. <fcpr...@gmail.com> wrote:
Can the ATMega328 be programmed directly through its serial port, without an intervening Arduino UNO?

--
You received this message because you are subscribed to the Google Groups "Altair-Duino" group.
To unsubscribe from this group and stop receiving emails from it, send an email to altair-duino...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/altair-duino/03a4d51b-87ca-447e-acc4-bbe020d832ad%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jim Manley

unread,
Nov 17, 2018, 6:53:56 PM11/17/18
to fcpr...@gmail.com, uken...@googlegroups.com

Frank P.

unread,
Nov 17, 2018, 7:38:47 PM11/17/18
to uken...@googlegroups.com
So as close as I can tell, you'd need 3 lines from the serial port (TX, RX, and RTS) connected to (TX, RX, and RST) on the chip to use program via the serial port, correct? That is, TX and RX alone are not sufficient?

The Vero/stripboard shows the RTS capacitively coupled to the RST through a 0.1uf cap; I assume that signal is what puts the chip in programming mode, correct?

This is all pretty new to me.

Jim Manley

unread,
Nov 17, 2018, 8:53:47 PM11/17/18
to uken...@googlegroups.com
If the capacitor is in series, it's to block DC offsets, which isn't necessary if you know there won't be any DC.

On Sat, Nov 17, 2018 at 5:38 PM Frank P. <fcpr...@gmail.com> wrote:
So as close as I can tell, you'd need 3 lines from the serial port (TX, RX, and RTS) connected to (TX, RX, and RST) on the chip to use program via the serial port, correct? That is, TX and RX alone are not sufficient?

The Vero/stripboard shows the RTS capacitively coupled to the RST, but in Mark Wilson's prototype, it's directly connected.

jim3...@gmail.com

unread,
Nov 18, 2018, 3:38:31 AM11/18/18
to Altair-Duino
I'm not sure what he is trying to do with the RTS. It is capacitively coupled to RST (the reset pin). It looks like he is pulling RTS low when he resets the processor, then letting it "float" high through the capacitor.

If you had hardware handshaking on, that should block any serial traffic until after things reset and also until power is applied. (Which would be my guess at what he wants to achieve.)

Thanks,
Jim

Frank P.

unread,
Nov 18, 2018, 7:40:30 AM11/18/18
to Altair-Duino
All of that is true, but my real question is:
"Is the RTS-RST connection essential to being able to program the chip through the serial port?".

That is: What is it that the Arduino IDE does that makes programming different from just normal programmed serial communication over TX/RX? I know it has to talk to the bootloader, but what causes the bootloader to run?

jim3...@gmail.com

unread,
Nov 18, 2018, 9:25:36 AM11/18/18
to Altair-Duino
Actually I had my DTR and DSR backward in my thinking.

I think it is necessary and I also think that a protective diode (while probably not a big deal) is missing.

Some details here:


On our AVR microcontrollers we use the RESET pin that halts the execution of any sketch or bootloader and puts the microcontroller in a specific state where it listens to the commands arriving from the SPI interface. The very first command that the protocol requires is the one that enters the microcontroller in the Serial Programming Mode.

Once this specific mode is active, we can write and read all the microcontroller programmable areas: Flash, EEPROM and Fuses. At the end of the Flash memory, we have the bootloader code area, as highlighted in the image at the beginning of this article. The "Burn Bootloader" procedure also sets properly the fuses of the microcontroller according to the design of the board. This is one of the reasons why you have to burn the bootloader selecting your exact board model in the list.

It looks like a chunk of the stand-alone circuit was lifted from the design of the Uno. I'm looking at the schematic here:


On the Uno, when you are powering through the USB, the I/O chip (the ATMega16) can pull RST of the ATMega 328 into the desired state when you are programming using CTS.

It is the state of the RST (Reset) pin on the device being programmed that matters. You also don't want to leave it in that state for too long (or depend on power-up to get you into the proper state) because garbage on the serial lines might kick you out of the mode allowing loading of the bootstrap.

So on the stand-alone programmer, the RTS is used to "pulse" the RST low and place the device to be programmed in the proper mode.

On the Uno, there is a diode (D2) on the reset pull-up resistor (RN10). I think a similar diode should be across R1 of the stand-alone programmer. When the RTS like goes high, since it is capacitaively coupled, it could actually pull the RST pin above the Vcc. I don't think it would have enough umph to really do any damage, but I also doubt that the Uno R3 has it if there is absolutely no need for it.

Interesting question and I've learned something. :-)

Thanks,
Jim

jim3...@gmail.com

unread,
Nov 18, 2018, 10:10:34 AM11/18/18
to Altair-Duino
>Actually I had my DTR and DSR backward in my thinking.

I meant DTE and DCE. I have not idea where that came from except for maybe old age... :-)

Thanks,
Jim

Frank P.

unread,
Dec 7, 2018, 9:33:30 AM12/7/18
to Altair-Duino
YES YOU CAN!

Now that my serial port is installed in the box (and with much appreciated help from Jim and Jim above), I can indeed program the ATMega328 from the serial port. The best part is that since this doesn't require an erase, my programs stored in EEPROM remain intact through a re-program.

The secret indeed is a 0.1μF capacitor from the terminal's (i.e.: the Arduino IDE's) RTS line to pin 1 of the ATMega328, plus a 10K pullup resistor on pin 1 (got this from some of the PaperDuino drawings). A transition from 5V to GND on this line occurs when the Arduino IDE opens the port, and the pulse on pin 1 kicks the ATMega328 into the boot loader for about 1/2 second before re-starting the sketch. During that time, the IDE establishes a programming connection with the boot loader and starts the upload. It only takes about 10 seconds to send the whole μKenbak-1 sketch, after which the boot loader starts the sketch running.

Because the logic signals on my female RS-232 module are referenced to the computer and not the terminal, the terminal's RTS line (pin 7 on the DB9) presents itself as a logic level output on the module pin labeled CTS.

Here's a photo of my board mod to make this happen. Note that I'm only using the lower 5 pins of the header because the top pin (which I cut off) is way too close to the power connector when the case is closed. I jumpered the Vcc down to the unused second pin from the bottom, and used the unused bottom pin for my RTS/RST hookup.

IMG_8119.JPG


Jim Manley

unread,
Dec 7, 2018, 10:53:35 AM12/7/18
to Altair-Duino
One way to eliminate the need for an on-board USB port, or a USB-serial converter, in order to program these ATMega microcontrollers is via a $5 Raspberry Pi Zero, a $10 Zero W with WiFi and Bluetooth LE, or any other Pi, for that matter, albeit at higher cost and credit-card size, up to a "whopping" $35 for a 1.4 GHz quad-core ARM Cortex M4 with 1 GB of RAM, four USB 2.x ports, 100 Base-T Ethernet, WiFi, Bluetooth LE, a Display Serial Interface, a Camera Serial Interface (also on the Zero and Zero W).  All Pi models have 1080p/60Hz HDMI output, at least one USB 2.x port, and 40 General Purpose I/O (GPIO) pins connected directly to the System-on-a-Chip (SoC - CPU, GPU, glue-ware, and up to 512 MBs of Package-on-Package (PoP) RAM on models without 1 GB of off-SoC RAM).

Some of the GPIO pins are preconfigured as a hardware or software handshake serial port up to 115Kbps, and other pins can be so configured, when not used for multiple default I2C, SPI, and PWM I/O ports.  There's a fully-supported Debian Linux-based official Arduino IDE that can be downloaded via a simple apt-get install that has configurations for all of the Usual Suspect Arduino models.  For any that aren't in the default list, the IDE can be updated with the configurations for the less popular or newer ones (e.g., the Due).

Plus, all of the Pi models are full-fledged Debian-based systems, with a honkin' little OpenGL SE compliant GPU (99% of the die area, in fact!) that can become miniature desktop systems with the addition of an HDMI/DVI/NTSC LCD display/TV and a USB keyboard and mouse/trackpad/trackball (I like the Logitech K400 integrated wireless keyboard/trackpad available at any Walmart for under $20).  The "hard disk" can be a micro-SD card (8 GBs minimum for the current full Raspbian distro, but there are cut-down versions that still have core functionality as small as 400 MBs in size - see the DietPi easy-peasy customization tool at https://dietpi.com, or embedded versions as small as 35 MB - see the Not Another Raspberry Distro - NARD - at http://www.nard.se).

If Debian doesn't do it for you, there are distros for Ubuntu, Arch, RISC-OS, and even Bell Labs' network-distributed Plan 9 Unix follow-on research OS ... now with support for USB, audio, and WiFi, in addition to the GUI!  Per Plan 9, I suspect the primary developers Rob Pike, Ken Thompson, Dave Presotto and Phil Winterbottom, technical manager Dennis Ritchie (head of the Bell Labs Computing Techniques Research Department at the time), and official release (through v4) contributors Brian Kernighan, Tom Duff, Doug McIlroy, Bjarne Stroustrup, and Bruce Ellis very likely highly approve of how the 9front fork community has continued to extend and support it in its now open-source form.

If you wind up down many rabbit holes exploring PiWorld, don't blame me, as I'm warning you ... I've been down here for coming up on seven years in March, when the first Pi were released into the wild (I was one of the first in the U.S. to get one)!


--
You received this message because you are subscribed to the Google Groups "Altair-Duino" group.
To unsubscribe from this group and stop receiving emails from it, send an email to altair-duino...@googlegroups.com.

jim3...@gmail.com

unread,
Dec 7, 2018, 11:19:37 AM12/7/18
to Altair-Duino
>YES YOU CAN!

That is pretty cool. Thanks for sharing the results. I was kind of thinking about using one of the RS232 modules I have laying around, but they are bargain boards (around $2 each) and don't have handshaking. Now I'm thinking I'll spring for one with handshaking and use this approach.

With an assembler, serial loader, and the ability to upload updated sketches, this thing is morphing in some very interesting ways.

Thanks,
Jim

Frank P.

unread,
Dec 7, 2018, 11:20:30 AM12/7/18
to Altair-Duino
Jim, I have a cheapo Prolific USB-RS-232 port on my Windows machine that works fine.

But I do share your enthusiasm for the PIs. I have 3: one is a Software Defined Radio server; the second runs Kodi and is hooked to my TV; and the third has a camera and microphone and was built as a baby monitor for my son, but I kept a copy and use it to keep an eye (and ear) on my furnace while I'm on vacation (it uploads to a YouTube live stream). They're super versatile and can compile their own programs, be remote-desktop-ed into, and well... are just a cigarette-pack-sized PC.

This whole Arduino thing is a new experience for me, kind of a big step down in a way, but pretty interesting.

Jim Manley

unread,
Dec 7, 2018, 4:38:50 PM12/7/18
to Altair-Duino
Arduinos are based on microcontrollers (e.g., ATMega328P) that have built-in digital and analog I/O, flash memory, a small amount of RAM (2KBs to 512KBs, IIRC, depending on which family) and a bootloader that can be readily accessed via the Arduino IDE to load and run user-level code in the form of an Arduino "sketch" file, etc.

The Pi microcomputer models have purely digital I/O built-in (if you don't count the NTSC video and stereo audio outputs).  More recent Pi models can boot from a micro-SD card, a USB storage device, or over a network, and all models (except a Pi 1 or early Pi 2 series) can boot via another Linux system over USB under Raspbian Stretch using the usbboot utility (e.g., https://dev.webonomic.nl/how-to-run-or-boot-raspbian-on-a-raspberry-pi-zero-without-an-sd-card).

--
You received this message because you are subscribed to the Google Groups "Altair-Duino" group.
To unsubscribe from this group and stop receiving emails from it, send an email to altair-duino...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages