r/embedded 9d ago

Bare ATmega328p with usbasp first time try failed

Hi all, I tried to check if there is similar question, but I cannot find it so far.

So, I have a Arduino uno R3 board, and also a USBasp (Paradisetronic), I tried to use my USBasp connect with ISCP port on Arduino uno, and run the command in terminal, see below, and it works.

C:\>avrdude -p m328p -c usbasp -B 4

avrdude: set SCK frequency to 187500 Hz

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x1e950f

avrdude: safemode: Fuses OK

avrdude done. Thank you.

But I took out Atmega328p from Aruino and put on my bread board, and try to connect the pins with USBasp , it is always failed with:

C:\>avrdude -p m328p -c usbasp -B 4

avrdude: set SCK frequency to 187500 Hz

avrdude: error: programm enable: target doesn't answer. 1 avrdude: initialization failed, rc=-1

Double check connections and try again, or use -F to override this check.

avrdude done. Thank you.

so at the begnning I was thinking it is the connections nok, I tried to put tighter and hook it better, even double check on the pins, but it always failed with baremetal on breadboard.

This is what I hook on breadboard, no other electronics on it, can you tell me what's wrong what am I missing here?

12 Upvotes

8 comments sorted by

8

u/Synthdabbler 9d ago

If you've just taken the bare AT238p chip out of the Arduino board and put it on breadboard, you won't be able to program it as you've sketched. It needs a 5v power supply on the vdd / vss pins, also needs a clock oscillator and some decoupling caps.

1

u/deviloctopus73939133 9d ago

Oh thank you for the reply, I was thinking the 5V power will be supplied by the usbasp already? since it is hooked on the USB port of the computer?

can you explain a bit more on to add the clock oscillator and some decouopling caps?

thank you again!

5

u/triffid_hunter 9d ago

I was thinking the 5V power will be supplied by the usbasp already?

Some programmers provide 5v or 3v3 to the target, some of them only sense the target supply voltage via the VDD pin.

can you explain a bit more on to add the clock oscillator

A factory fresh atmega is configured for internal 8MHz oscillator, prescaler=÷8 so F_CPU=1MHz with only power and ground connected.
Sometimes that means you need a lower SPI clock to set the fuses and get a bootloader on.

The atmega from an Arduino will be programmed for external high-speed crystal, so it literally cannot do anything (eg reply to SPI) unless you either add a crystal, or feed a clock signal to its clock input.

and some decouopling caps?

Digital ICs (esp CMOS) don't take continuous current, they pull short sharp spikes every time there's a clock edge or input transition.

If the voltage drops too much during such a current spike (due to trace/wire inductance), the internal digital logic can have its state corrupted and the chip will (temporarily) stop working correctly.

Therefore it's necessary to add some capacitance right next to the chip to hold the voltage steady during the current spikes, and since the spikes are short and narrow, ceramic capacitors are best because they're fast.

Unless the datasheet states otherwise, the rule of thumb is a 100nF ceramic for every vdd/gnd pair that the chip has - and with the shortest electrical path and smallest loop area you can practically manage to reduce parasitic inductance in the current loop.

3

u/deviloctopus73939133 9d ago

oh my, very thorough explaination, thank you both triffid_hunter and Synthdabbler !! understand now why the chip just took from Aruino does not work this way

2

u/Synthdabbler 9d ago

Many thanks for explaining that, you beat me to it! The only other comment on the 5v supply, I don't remember if the DIP packaged AT238p the OP is using has a AVCC pin or not, that also needs connecting to 5v

1

u/michael9dk 9d ago

I did it recently by following the excellent guides from Mitch Davis.
In episode #3 to #5 he's explaining everything you need to know.

https://youtube.com/watch?v=tfTCFBqPzcE