ATmega328P on a breadboard (8MHz internal clock) programming problem

Hi there,

I'm asking for help because I run out of ideas... (checked similar topics on the forum and nothing worked, or I didn't have tools to do it)

My problem:

I want to program a circuit with ATmega328p without external oscillator. I am using Arduino Uno as a "Arduino as ISP" programmer. I wired everything (correctly - as I thought then) and managed to burn bootloader for "ATmega328 on a breadboard (8MHz internal clock)" board - and it worked fine (at least the message from avrdude was positive). But then I could not connect to the board to upload any sketch (also using Arduino as ISP). Some time later someone suggested me to add a 10k resistor between the reset pin and +5V on programmed ATmega. I did this, and tried to upload a simple sketch and it worked! But only once... (I could not connect to upload another). After that, I realized that I forgot to connect together the GND signals of both microcontrolers (it was because I have an external power source for the entire circuit so I thought I do not have to connect it - I know silly me.. :( ) After fixing this I was able to upload some sketches until once I clicked normal "Upload" button instead of "Upload using Programmer" by mistake and again I returned to the point where I cannot upload anything. Error I get all the time:

avrdude: Device signature = 0x000000

My current connections: ATMega328P Ardiono Uno SCK pin 13 MISO pin 12 MOSI pin 11 RES pin 10 GND GND +5V +5V (I decided to turn off the external source and connect directly to Arduino)

Cap 10uF on RES to GND on ArduinoUno

I checked wires a few times, even replaced them all.

Any ideas what could be wrong, or what else can I do?

The Atmega is in TQFP package and I already soldered it to the board...

Animki6: Any ideas what could be wrong, or what else can I do?

The Atmega is in TQFP package and I already soldered it to the board...

Maybe you programmed the low fuse for an external crystal by mistake?

An easy to test for this (and recover from the problem as well!) is to take a crystal (any value 8mhz, 16mhz... anywhere is the range) and carefully hand hold the leads to the two AVR crystal pins and try programming it.

Use a regular HC-49 crystal, hold it by the [u]body[/u] using a cliplead (the other end grounded to the AVR board) and touch the two pins to the 328p and try to program.

Also check your fuse settings and be sure you have bit 5 of the high fuse (SPI enable) programmed. If not, you will need a high voltage programmer to recover (and lotsa luck doing so with a SMT part!).

Hope this helps.

Good luck.

Thank you for your reply! ;)

I think I have to find a suitable crystal and try it. Should I change something depending on a value of crystal I've got during programming?

Also can you tell me where can I find these fuse settings to check if they're ok?

Animki6: Thank you for your reply! ;)

I think I have to find a suitable crystal and try it. Should I change something depending on a value of crystal I've got during programming?

Also can you tell me where can I find these fuse settings to check if they're ok?

The crystal value just for programming is not important. Anything from 1 mhz to 16 mhz will work fine... even an oddball like 3.579545 (a TV colorburst crystal) will work. Doesn't matter.

The fuse settings are documented in the AVR datasheets for each chip. Here's a link (PDF file) to the 328p:

ATMega328p datasheet (start around page 282)

There is also a nice website that allows you to choose your chip and the fuse settings you want, then it shows you what to program the fuses to:

AVR Fuse Calculator

If you have any other questions, let me know.....

Krupski: (...) The fuse settings are documented in the AVR datasheets for each chip. Here's a link (PDF file) to the 328p:

ATMega328p datasheet (start around page 282)

There is also a nice website that allows you to choose your chip and the fuse settings you want, then it shows you what to program the fuses to:

AVR Fuse Calculator

If you have any other questions, let me know.....

Thanks, very nice site, I am sure I will use it someday ;) But at this point I was asking where can I check (if I can check) the actual fuse values that had been written to the chip?

Animki6: Thanks, very nice site, I am sure I will use it someday ;) But at this point I was asking where can I check (if I can check) the actual fuse values that had been written to the chip?

OK, let me see if this may give you an idea what may be wrong.

First of all, if you can't "get into" the 328p, then you can't read the fuse settings (at least not with a mere "Arduino as ISP" setup).

When you have a bootloader burned into the AVR, the power on reset sequence jumps to the memory address of the bootloader which resides in the very top of the chip's memory space. For example, an Arduino UNO may have the bootloader residing at 0x7C00 to 0x7FFF, so the reset first jumps to 0x7C00 and runs the boot loader code. If the bootloader doesn't get an "upload request" within a timeout period, it ends and jumps to address 0x0000 where your "sketch" (actual program) would be loaded.

If you use "Upload using programmer", the AVR flash memory is erased (including the bootloader code) and your program code loaded into 0x0000. Also, the BOOTRST bit (bit 0) of the low fuse is unprogrammed to tell the AVR to jump DIRECTLY to 0x0000 and run code rather than first trying the bootloader.

Are you using the Arduino IDE, and if so, what version? Try to locate the file named "boards.txt", find within it the definitions for the 328p and see how it's setting the fuse bits, then post it here.

That may at least give me an idea what's going on.

(edit to add): By the way, get rid of the capacitor on the reset pin. No way you're going to program the AVR via the ICSP if reset is not allowed to be toggled!

Arduino IDE 1.6.12, here is "boards.txt" I use while programming Atmega328 with internal 8MHz clock:

##############################################################

atmega328bb.name=ATmega328 on a breadboard (8 MHz internal clock)

atmega328bb.upload.protocol=arduino
atmega328bb.upload.tool=arduino:avrdude
atmega328bb.upload.maximum_size=30720
atmega328bb.upload.speed=57600

atmega328bb.bootloader.low_fuses=0xE2
atmega328bb.bootloader.high_fuses=0xDA
atmega328bb.bootloader.extended_fuses=0x05

atmega328bb.bootloader.file=atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex
atmega328bb.bootloader.tool=arduino:avrdude
atmega328bb.bootloader.unlock_bits=0x3F
atmega328bb.bootloader.lock_bits=0x0F

atmega328bb.build.mcu=atmega328p
atmega328bb.build.f_cpu=8000000L
atmega328bb.build.core=arduino:arduino
atmega328bb.build.variant=arduino:standard

I am not sure if I understand it correct - I don't have to burn bootloader first if I am going to use "Upload using programmer" option for my sketch?

Hello,

I don't know if you managed to fix your problem.... Maybe it will be helpfull for you or someone else with this issue.

Animki6: After fixing this I was able to upload some sketches until once I clicked normal "Upload" button instead of "Upload using Programmer" by mistake and again I returned to the point where I cannot upload anything.

When you clicked normal "Upload" button instead of "Upload using Programmer" you actually write the new program to the Ardino you use as ISP. If you tried to re-upload after, using the same Arduino as ISP without uploading again "Arduino as ISP" sketch it will not work because your arduino is not working as an ISP. Have you tried this?

I'm no expert but I hope this will be useful.