Problem uploading to standalone ATMega328P by serial/usb

Hi
I'm trying to design a circuit that includes the ability to program using a USB to Serial TTL board. It so very nearly works it's frustrating. I have checked the ATMega has bootloader installed - if I place it in my Uno it works perfectly for programming using the USB, and the built-in LED does the rapid 3 flashes at power on.

When I connect the FTDI USB board via TX, RX, RTS (also tried DTR) and GND and try and upload a sketch I get various STK500 errors - mostly SYNC errors. With an LED attached to pin 19 I see the rapid 3 flashes which would suggest the reset signal gets through.

I've attached (hopefully) the circuit diagram I'm using. I really don't know what I'm missing despite a lot of searching online.

Any help greatly appreciated!

Thanks.

daveJ's schematic:

You forgot the 0.1 uF decoupling capacitor between Vcc and Gnd.

I've always supplied power also to AVcc, with another 0.1 uF decoupling capacitor on that line. I'm not sure whether that's required.

I also don't recommend connecting the LED with no current limiting resistor.

As mentioned a LED needs a ~330Ω series resistor.

You need 100nF decoupling capacitors on 5v.

AVCC connects to +5v.

Use DCD.

Show us a good image of your wiring.

Hi Pert and Larry, thanks for the replies.

I made some adjustments to the circuit: I've added the decoupling capacitors to VCC and AVC (as well as 5v to that one). I've also tried using DCD although that didn't seem to reset the 328 chip. I've got the LED connected infrequently just to check the chip is powered up and running, although that's now in series with a 220 ohm resistor.

I was still getting varying degrees of success with that.

I have then rebuilt the circuit on what I hope is better quality breadboard. I got better results with that and actually managed to upload a sketch, although even then the connection failed during the read/verify stage.

I've also changed the USB cable I'm using from my PC to the FTDI board, which made things a bit more stable; I suspect that's down do having more reliable power (I was using a 2 meter, very thin, USB cable). Saying that, I have also tried various different arrangements of powering the FTDI board and the 328 circuit itself.

I strongly suspect I am currently learning a valuable lesson about using quality components, as the results are inconsistent.

For what it's worth here's a snippet of the most common output I get from avrdude:

----snip----

         Programmer Type : Arduino
         Description     : Arduino
         Hardware Version: 3
         Firmware Version: 4.4
         Vtarget         : 0.3 V
         Varef           : 0.3 V
         Oscillator      : 28.800 kHz
         SCK period      : 3.3 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: reading input file "/tmp/arduino_build_809503/BlinkAndSerial.ino.hex"
avrdude: writing flash (2086 bytes):

Writing | ################################################## | 100% 0.31s

avrdude: 2086 bytes of flash written
avrdude: verifying flash memory against /tmp/arduino_build_809503/BlinkAndSerial.ino.hex:
avrdude: load data flash data from input file /tmp/arduino_build_809503/BlinkAndSerial.ino.hex:
avrdude: input file /tmp/arduino_build_809503/BlinkAndSerial.ino.hex contains 2086 bytes
avrdude: reading on-chip flash data:

Reading | #######################avrdude: stk500_loadaddr(): (a) protocol error, expect=0x14, resp=0x00

avrdude: stk500_paged_load(): (a) protocol error, expect=0x14, resp=0x00
avrdude: stk500_paged_load(): (a) protocol error, expect=0x14, resp=0x00

###avrdude: stk500_cmd(): programmer is out of sync
avr_read(): error reading address 0x0000
    read operation not supported for memory "flash"
avrdude: failed to read all of flash memory, rc=-2
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x00

avrdude done.  Thank you.

----snip----

That did successfully upload the sketch (I've just done it on three different chips while I'm writing this), but as I said above it fails before completing the verify stage.

Any suggestions, even if it's to agree I must have something in my setup which is low quality, are appreciated.

Thanks

Dave

Show us a good image of your wiring.

Aside from me missing the decoupling capacitor on the VCC and GND pins and remedying that, I became convinced the problem wasn't with the circuit but with the quality of my breadboard and dupont wires. Varying results without changing anything didn't make sense.

Turns out I was right - it seems I've bought some cheap low quality breadboards and/or dupont wires.

I've built the updated circuit now on a PCB with all the components soldered and it works consistently, no random errors from avrdude. I used all the same components except the breadboard and wires, everything else is the same.

ATMega328P-SerialProgrammingCircuit.png

That circuit works 100% for me now

Lesson learnt :slight_smile:

ATMega328P-SerialProgrammingCircuit.png

Learn to make your own 'Dupont connector' terminated wires.

See:
http://forum.arduino.cc/index.php?topic=376971.msg2599211#msg2599211

Thanks larryd, that's a great post and guide for the dupont type wires. I've got the tools and components to make them but have struggled. I'll have another go now :slight_smile:
Cheers