Author Topic: Cannot program ATMEGA328P - crystal not oscillating  (Read 8965 times)

0 Members and 1 Guest are viewing this topic.

Offline akupilaTopic starter

  • Newbie
  • Posts: 6
Cannot program ATMEGA328P - crystal not oscillating
« on: June 13, 2013, 10:58:14 am »
Hey guys,

Fairly common problem i guess, at least based on Google results. I not able to talk to a TQFP atmega328p on a custom pcb.

Problem:
When i try to program using avrdude i get:

Code: [Select]
avrdude: stk500v2_command(): command failed
avrdude: stk500v2_program_enable(): bad AVRISPmkII connection status: Unknown status 0x00
avrdude: initialization failed, rc=-1
avrdude: AVR device initialized and ready to accept instructions
avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.
avrdude: Expected signature for ATMEGA328P is 1E 95 0F

So yeah, something is wrong. The power is 3.8v, i have a 10k pullup on the reset line and a 16MHz crystal with 22pF caps. Every vcc pin has a .1uF cap. All normal stuff, but for some reason it' not working.

I've measured continuity on all SPI pins, everything looks good. However when i look at the crystal pins with a scope i get a steady 1.8v on one pin and 2.6v on on the other. It's no oscillating as it should, which i'm guessing is causing the problems..

Board layout with the crystal lines highlighted:


I've tried replacing the crystal with another one. I also replaced the MCU. No change in either case..

I also tried building a barebones arduino based design on a breadboard and hooked the crystal lines into this board. This worked (!?). So maybe it's no the crystal after all?

There's a MAX6675 on the SPI lines too, could this cause issues with programming?

Any suggestions on what i should try next to try to find the problem? Is there a way to somehow test that the MCU is still alive, i guess it's possible it got fried from the heat while soldering?..

Here's the schematic too:


Any pointers are greatly appreciated!
 

Offline amyk

  • Super Contributor
  • ***
  • Posts: 8275
Re: Cannot program ATMEGA328P - crystal not oscillating
« Reply #1 on: June 13, 2013, 11:04:32 am »
The extra capacitance of a scope probe can be enough to cause the oscillator to stop; they're quite sensitive to that. Better to scope the programming signals and verify that they're within tolerance.

You should also read the layout guidelines for the oscillator as your layout looks nothing like the one Atmel recommends: http://www.atmel.com/Images/doc8128.pdf
 

Offline bingo600

  • Super Contributor
  • ***
  • Posts: 1989
  • Country: dk
Re: Cannot program ATMEGA328P - crystal not oscillating
« Reply #2 on: June 13, 2013, 11:27:42 am »
You could have 2 issues here.

1: An AVR is factory set to use the internal Oscillator @1Mhz (On a M328P -  8Mhz Internal Osc and "divide by 8"is selected)
    So the Xtal isn't driven on a "Virgin AVR"
    Note: The programming speed must be Max Fosc/4 ,  This means on a "Virgin AVR" Max programming speed is 250Khz

2: The External SPI chip could interfere with the ISP/SPI programming lines of the AVR.

Assuming that the external SPI chip doesn't interfere (seriously).
First make sure the programming frequency is 250Khz or lower.
Then set the fuses for external highspeed Xtal , see http://www.engbedded.com/fusecalc where it will output avrdude settings.

This might not be bad for a start :
Code: [Select]
avrdude ....  -U lfuse:w:0xff:m -U hfuse:w:0xdb:m -U efuse:w:0xfd:m
Else look at the Atmel design guides AVR042 http://www.atmel.com/Images/doc2521.pdf  (pg. 6) , shows that Atmel recommends resistors between the ISP pins , and external SPI chips.

Hope that helps ...

/Bingo
« Last Edit: June 13, 2013, 11:29:14 am by bingo600 »
 

Offline akupilaTopic starter

  • Newbie
  • Posts: 6
Re: Cannot program ATMEGA328P - crystal not oscillating
« Reply #3 on: June 13, 2013, 11:47:44 am »
Thanks for the quick reply amyk

Fair point, i had to take some shortcuts due to other design constraints. But i'll try to improve the crystal placement in Rev B.

That said though when i hook up an external chip's crystal lines to this one it works fine. Having a 10cm cable in between is of course definitely worse than on the pcb.

Also regarding the oscilloscope: it doesn't matter if have the probes hooked to the pins or not - the result is the same in terms of programming. If i probe the MISO, MOSI, Reset and SCK lines i see some binary data flying by on all of them (i don't have a logic analyzer). The signals are very clean from 0 to VCC (3.8v)

Thanks Bingo too, I've tried setting the fuses but every time the response is the same, i cannot talk to the device at all. I think i'll try removing that external SPI chip..
 

Offline bingo600

  • Super Contributor
  • ***
  • Posts: 1989
  • Country: dk
Re: Cannot program ATMEGA328P - crystal not oscillating
« Reply #4 on: June 13, 2013, 11:50:17 am »
Thanks Bingo too, I've tried setting the fuses but every time the response is the same, i cannot talk to the device at all. I think i'll try removing that external SPI chip..

And you are sure that the avrdude ISP speed is max 250Khz ?
What programmer HW are you using , a real STK500 ?

To show the full avrdude commandline , might not be a bad idea.

Edit: Ohh ... I do hope the 100nF on the xVCC lines are just "invisible" on the schematic , else you have serious trouble ahead.


/Bingo
« Last Edit: June 13, 2013, 11:56:50 am by bingo600 »
 

Offline akupilaTopic starter

  • Newbie
  • Posts: 6
Re: Cannot program ATMEGA328P - crystal not oscillating
« Reply #5 on: June 13, 2013, 12:31:40 pm »
Hmm, when i was going to copy the avrdude command line i realized it was set to use STK500 when i have an AVR ISP2.. d'uh |O

I did remove the other chip too. I think it actually was the incorrect avrdude command but it's now working fine. Also the crystal is oscillating at a nice and steady 16MHz. I guess if you think it's a hardware problem it's actually in software (and the other way around)..

An yeah the decoupling caps are outside of the schematic ;)

Thanks for you help!
 

Offline bingo600

  • Super Contributor
  • ***
  • Posts: 1989
  • Country: dk
Re: Cannot program ATMEGA328P - crystal not oscillating
« Reply #6 on: June 13, 2013, 12:48:53 pm »
Nice that it works

But it seems that "The Dude" have seen a ISPMKII , and could talk to it.  (i missed that)

Quote
avrdude: stk500v2_program_enable(): bad AVRISPmkII connection status: Unknown status 0x00

So depending on what you changed on the commandline , to get it to work.
You might still have a HW prob with the SPI chip.
Do you control the MAX6675 /CS in software , or have it tied to GND ?
If SW controlled , i'd say you might need a 10k pullip on /CS to make sure it's inactive unless explicit driving it low.
The AVR pins are tristated during the programming (RESET) , and can't drive.

If it's tied to GND , you will need some series resistors .... As the chip will always be actibe on the SPI/ISP lines.
And do the above sw + pullup in rev. 2.


/Bingo
 

Offline akupilaTopic starter

  • Newbie
  • Posts: 6
Re: Cannot program ATMEGA328P - crystal not oscillating
« Reply #7 on: June 13, 2013, 01:01:59 pm »
Seems like the chip has something to do with this too. I soldered it back and i have the same issue

Code: [Select]
avrdude -C/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/etc/avrdude.conf -c avrisp2 -p atmega328p -c stk500v2 -P usb -U flash:w:.build/uno/firmware.hex -v
The chip's CS line is software controlled but all the pins are directly connected to the MCU (no pullups/downs).

Here's the schematic for the chip:


So i guess i should put a pullup on temp_cs for rev b. Any other suggested changes?
 

Offline akupilaTopic starter

  • Newbie
  • Posts: 6
Re: Cannot program ATMEGA328P - crystal not oscillating
« Reply #8 on: June 13, 2013, 01:08:16 pm »
Ok, i tried putting a 10k pullup on temp_cs and that solves the upload problem again.
 

Offline bingo600

  • Super Contributor
  • ***
  • Posts: 1989
  • Country: dk
Re: Cannot program ATMEGA328P - crystal not oscillating
« Reply #9 on: June 13, 2013, 01:09:23 pm »
Couldn't you sneak a 10K pullup in on /CS , using wires ?

That'll tell you if it's enough , or you still needs series resistors ....
And maybe make your prototype working  ;)

Oopzz : Too late .... But now you got a working proto.

/Bingo
 

Offline akupilaTopic starter

  • Newbie
  • Posts: 6
Re: Cannot program ATMEGA328P - crystal not oscillating
« Reply #10 on: June 13, 2013, 01:14:23 pm »
Hehe yep. Ghetto wiring a through hole resistor over the IC ;)
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf