Barebone Atmel 328P + Upload sketch

Hi

I have been working with a few barebone atmel 328P the last couple of months. I have always programmed them by sticking them into an arduino uno, uploading from arduino program and then taking it out again. A few days ago i wanted to upload directly to the atmel processor. The bootloaders on these atmels are 8mhz versions (internal clock – programmed using Nick Gammons excellent ISP sketch).

Problem USB -> Atmel328
My problem is, that, I can upload sketches fine to my atmels whenever they are in the arduino, but once i try using serial connection for it, i get timeouts. My pinout is as follows:

Chip: Atmega328P-PU
USB connector: FTDI (A900)

Wiring:
FTDI -> Atmega
GND -> pin 8 & 22
VCC -> pin 7 & 20 & 21
RX -> pin 3 (tx)
TX -> pin 2 (rx)
DTR -> pin 1 (reset)
CST -> nc
I also have a 10k resistor from pin 1 to VCC

I am getting these errors:

-- snippet ---
avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x90
Varef : 269835212.0 V
Oscillator : 3.686 MHz
SCK period : 368336.6 us
avrdude: initialization failed, rc=-1
-- snippet ---

and also a bucket of other avrdude output of course. I am on macosx latest edition.

Hope you can help – it will be very much appreciated

(also posted on AVR freaks, however Arduino forum seemed like a more appropriate place)

Do you have 0.1uF decoupling caps on the VCC and AVCC pins?
Do you have a 0.1uF cap between DTR and Reset?

Hi, welcome to the forum.

Don't connect AREF (pin 21) to VCC.
You need a 100nF capacitor between the DTR and the reset.
Put a diode from reset to VCC (parallel to the 10k), it will prevent that the bootloader gets corrupted with high voltage programming mode.
I think you have to do this: TX to RX and RX to TX.

Check the schematics on the reference page for the Arduino Uno to see the reset circuit. Or check the schematic of the Arduino Nano to see how a FTDI is connected.

Hi Guys !

Thanks for the quick response :grin: very much appreciated !

I do not have any capacitors between DTR & Reset (or anywhere else right now) - maybe this is the common problem? Unfortuanetly I do not have any 100nF capacitors available :frowning: I have a bunch of giant 10 microFarad (35v) battery-shaped capacitors and some very small ones labeled "n10" (I think) with a purple top, all squared. My guess is neither of these would work :confused:

Problem is, my nearest electronic store is like 40 km away and isn't opening again for the next week :sob:

The guide i was following did not use a capacitor here. Its kinda embarrassing, but I know very little of capacitors :-[ . Why is it a capacitor is needed here ?

Oh my guys, i just tried removing the AVCC, putting in the large 10microf capacitor, and it "sorta" works.

I can upload new sketches, atleast once every usb "replug", however, it does give me a bunch of "protocol errors". But it uploads. :money_mouth_face:

Maybe an even more correct capacitor will make it perfect? :smiling_imp:

Can i somehow connect a resistor from my large capacitor to gnd, to lessen the load it contains?

Don't remove the connection from VCC to AVCC.
This is the pinmapping : https://www.arduino.cc/en/Hacking/PinMapping168
The ATmega328P needs GND on both sides and VCC and AVCC to 5V. Leave AREF open.

That capacitor is too big. You really need 100nF.
Open some old electronics, if possible something from a computer, or open a toy. The 100nF capacitors are everywhere. Or show us a photo of an old circuit board, so we can point out the 100nF capacitors.
Today they are almost always smd components, but old digital circuit boards have 100nF next to every chip.

sorry, mistype, i removed from AREF. not AVCC.

Thanks for your help Peter - I will try and see what i can find :sunglasses:

Can i "dumb down" the capacitor with resistors to ground?

No, you need 100nF. For the reset mayby 10nF to 470nF will also work.

Okay, so a quick update. I borrowed a handfull of capacitors from a friend, put in a 100nf between dtr and reset, and now i got this as result:

         Programmer Type : Arduino
         Description     : Arduino
avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x90
avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x90
         Hardware Version: 2
         Firmware Version: 1.-1596612356
avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x90
avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x90
avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x90
avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x90
avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x90
         Vtarget         : 322122167.2 V
         Varef           : 269835212.0 V
Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.
         Oscillator      : 0.001 Hz
         SCK period      : 368336.6 us
avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x90
avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x90
avrdude: stk500_initialize(): (b) protocol error, expect=0x10, resp=0x90
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.
avrdude done.  Thank you.

I then added the LED light (+ to VCC, - to reset pin, parallel to the 10k resistor) - and then i got a bunch of these:

avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00

I then added a 270 nf capacitor between VCC/AVCC and GND. .. voila - it works. Every time :slight_smile:

THANKS GUYS !!! :kissing:

(however, I still dont quite understand what the logic is behind when capacitors are used, and why)

The ATmega328P can do a lot. It will even run without decoupling capacitor... just kidding :o you should not do that.
It needs a decoupling capacitor at VCC - GND to run properly. Because it is running at 16MHz (or 8MHz), it requires pulses of current in the range of 16MHz. With a few wires (which are coils at 16MHz), the ATmega328P has trouble by its own current pulses. A simple 100nF decoupling capacitor can avoid 99% of that trouble.

All microcontrollers and many other IC's require decoupling caps; I put them on every IC, unless I know it doesn't need one.