DIY serial programmer for breadboard Arduino

I setup a breadboard Arduino with the ATMega328 and can program it just fine using my Arduino Uno board.

I started playing around with creating a programmer using a USB to Serial cable and MAX232 chip. I followed the following schematic from this page. I realize that specific setup is for a PIC but it's the same as the diagram on Maxim's site. Here's another tutorial (there are many online)

Anyway, I can load up the Arduino IDE, upload a program (no automatic reset so I manually push the reset button) and it works, but only the first time. The second time and after, I get an error:

avrdude: stk500_getsync(): not in sync: resp=0x00

And I have to unplug the cable from my computer, plug it in again, and it will work one more time. When I try to upload, after pressing the reset button, the led on pin 13 flashes a few times and turns off and stays off for a while (as you would expect). Throughout this time, the IDE is showing an almost full progress bar with "Uploading...". After a few seconds, the sketch already loaded in the chip starts (just blinking pin 13 at different rates so I know if it's an old sketch or the one I'm trying to upload) and after a few more seconds, I'll get that error in the IDE.

My wiring is correct, and I figure it wouldn't work at all if something was out of place. Again, the chip works fine and I can program it flawlessly using my Uno board. The circuit runs fine, the max232 circuit programs it once just fine, and it's fine if I remove the USB from computer and plug it in again. If I reset my chip, disconnect power to everything and start it up again, the issue persists. If I disconnect the USB 232 converter cable from the max232 and plug it in again, the issue persists. The only time it works again is when I disconnect the USB232 converter cable from the computer.

In the Arduino IDE, my board is Arduino Uno and programmer is the default AVRISP mkII. That programmer is the only option that seems to work.

My guess is that the USB to serial cable is somehow buffering stuff, so that when you try to upload a second time output (chip to PC) is being sent which makes it think it is out of sync.

Also try some pull-up resistors on the Rx, Tx lines (MAX232 pins 11 and 12) to guarantee that the line is idle while the chip is booting.

I added the pull up resistors and it seems to work better (I can program at least twice but keep reading)... but I still get errors.

Here is another one I've been getting every once in a while:

avrdude: stk500_paged_load(): (a) protocol error, expect=0x10, resp=0x14
avrdude: stk500_cmd(): programmer is out of sync

I don't know how to reproduce it consistently but I get it more often now with the pull up resistors. When I get this one, the program loads just fine and starts to run. The IDE will be stuck at Uploading... for a few more seconds (after the program has started running on the chip) and then display that error. I guess next step would be to try another cable.

I would be tempted to get an FTDI cable, that removes one device from the train.

Those FTDI cables are kind of expensive, especially for what they are.
(Typically about $20 USD)
There are 3rd party FTDI boards that are considerably cheaper.
And then there are cp2102 boards like this one:
http://www.ebay.com/itm/USB-2-0-to-UART-TTL-6PIN-Module-Serial-Converter-CP2102-NEW-/180925940394?pt=US_Floppy_Zip_Jaz_Drives&hash=item2a2006c2aa
That are probably about as cheap if not cheaper than anything you can make
using a MAX232 chip.
The bummer is that all these cp2102 boards seemed to have hooked up the RST
(cp2102 chip reset) up to the header rather than RTS.
You will have to wire/solder the AVR autoreset signal up to the RTS or DTR signal from cp2102 but
that is pretty easy using the included wires.
I prefer using RTS over DTR just like the FTDI cable for its advantages of not creating an auto-reset
every time the serial port is opened while still allowing auto-reset to work for uploading.

--- bill

You can try grounding the CTS input back to the PC on the DB9 connector.

Another option is MIKROE483 from mouser.com, its the least expensive way to get an FTDI module ($11).

My experience with mouser was that the shipping was a bit high and was unknown until after
the purchase - which I don't like since I don't know up front when I'm actually buying it on
the web page.

There are some FTDI based boards on ebay as well:

http://www.ebay.com/itm/MWC-MINI-USB-FTDI-Basic-USB-PC-Firmware-Programmer-Breakout-Arduino-USB-Cable-/251177941915?pt=LH_DefaultDomain_0&hash=item3a7b5f3b9b

http://www.ebay.com/itm/FTDI-Basic-6-PIN-3-3-5V-For-Arduino-Free-USB-Cable-/230820610037?pt=LH_DefaultDomain_0&hash=item35bdfafff5

http://www.ebay.com/itm/FTDI-Basic-Breakout-USB-TTL-6-PIN-3-3-5V-With-Free-USB-Cable-For-Arduino-/320907184616?pt=LH_DefaultDomain_0&hash=item4ab78f09e8

--- bill

Mouser has this flat rate residential shipping thing now, so shipping is often just $6.99.
For instance, my last order was for several boxes of Phoenix screw terminals, which are pretty heavy. $6.99 shipping.
Everybody is starting to charge sales tax now, that is adding up:

Two examples of recent orders:

Merchandise Total
USD $179.76
Shipping $6.99
TAX $11.24

Merchandise Total
USD $93.50
Shipping $6.99
TAX $5.84

So I connected pins 4 to 6 and 7 to 8 on the DB9 connector and things seem to be working. I still occasionally run into an error and have to unplug the USB cable and plug it in again, but for the most part it works. I just found this tutorial and it suggests

http://arduino.cc/en/Tutorial/ArduinoSoftwareRS232:
Connect pins 1 and 6 to pin 4 and pin 7 to pin 8.

Since I am using pin 4 for DTR (I tried using pin 7 as bperrybap suggested but that didn't work) would it be recommended to connect it and pin 6 to pin 1 or should I leave that open?

I was going to order this FT232RL USB to Serial breakout board but figured I'd try making one myself since I had a MAX232 laying around. It could either save me $14 and I'd learn a thing or two... So from what I gather from this thread, I can buy a cheap one from ebay and still get the same functionality. I've also considered just getting a USBtinyISP or other ISP so I could use those for programming directly to the chip without the Arduino bootloader in the future.

only the first time.

I would suspect that this is due to hitting the RESET button at the wrong time. You only have a window of 1s, in a multi-second compile/link/etc, so timing is pretty critical. Using verbose compile mode may help (release the reset button immediately after seeing the "sketch size" message)

It works the first time because when there is no sketch present, the bootloader just runs again after the 1s is up.

westfw:

only the first time.

I would suspect that this is due to hitting the RESET button at the wrong time. You only have a window of 1s, in a multi-second compile/link/etc, so timing is pretty critical. Using verbose compile mode may help (release the reset button immediately after seeing the "sketch size" message)

It works the first time because when there is no sketch present, the bootloader just runs again after the 1s is up.

I know that can be an issue, but I don't think that's the case here. When I program the chip using my Uno board's RX/TX lines, I also have to manually reset the chip. I reset it the same way every time, using both programmers, and have not had an issue when using the Uno.

I was under the impression that you could run one of the signals from a FTDI cable or other USB to serial breakout through a 100nF cap to the 328P rest pin. I believe it is the RTS on the USB to Serial.

I use the DB9 comm port on my PC a lot to load up sketches and I run pin 4 (DTR) through the 100nF cap and it works every time. A similar setup is documented here, but it uses some transistors instead of a max232 chip.

vogel1230:
I was under the impression that you could run one of the signals from a FTDI cable or other USB to serial breakout through a 100nF cap to the 328P rest pin. I believe it is the RTS on the USB to Serial.

Yes you can use either DTR or RTS pin as the arduino IDE pules both to force the bootloader to run before attempting the upload operation.
Lefty

I use the DB9 comm port on my PC a lot to load up sketches and I run pin 4 (DTR) through the 100nF cap and it works every time. A similar setup is documented here, but it uses some transistors instead of a max232 chip.

http://arduino.cc/en/uploads/Main/ArduinoSeverinoSchematic.png

vogel1230:
I was under the impression that you could run one of the signals from a FTDI cable or other USB to serial breakout through a 100nF cap to the 328P rest pin. I believe it is the RTS on the USB to Serial.

I use the DB9 comm port on my PC a lot to load up sketches and I run pin 4 (DTR) through the 100nF cap and it works every time. A similar setup is documented here, but it uses some transistors instead of a max232 chip.

http://arduino.cc/en/uploads/Main/ArduinoSeverinoSchematic.png

You might be able to fix it, yes, but for working with bare chips it's far easier/better to get a $10 ISP device.

In fact the price has gone down... a USBtinyISP is now under $9! (shipping might be slow at that price though...read feedback before ordering)

I do have automatic reset working with the capacitor so that's nice to have. I'm not sure why it still throws errors in the IDE every once in a while but I'm also ordering a FTDI dongle. This should be OK until that arrives.