Atmega328 in programming mode -- garbage values

I am trying to use Nick Gammon's Atmega board detector sketch with a bread-boarded Atmega 328. It mostly works but I get a fair percentage of garbage values back. For example, instead of a block of FF values in the bootloader section it looks like this:

7000: FF FE FF FF FF FF FF FF FF FF FF FF FF FF FF FF 7010: FF FF FF FF FF FF FF FF FF FF 0D FF FF FF FF FF 7020: FF FF FF FF FF 12 FF FF FF FF FF FF FF FF FF FF 7030: FF FF FF FF 1A FF FF FF FF FF FF FF FF FF FF FF 7040: FF FF FF FF FF FF FF FF FF 24 FF FF FF FF FF 27

And it isn't consistent. Occasionally even the signature is corrupted.

My bread board setup looks like this:

|500x375

|500x375

This isn't very different from what is on Nick's web page:

|500x438

I don't have an oscilloscope but I would imagine it's noisy.

Any suggestions as to what I might do to clean things up? Or could it be something else?

I reduced the programming clock speed from 250 to 125kHz and now it works reliably. But if I'm reading the datasheet correctly 250kHz should have been okay, if only barely.

Target is clocked at what frequency?

It's in default mode: internal 8MHz oscillator divided by 8. So 1MHz.

Low:> 2 CPU clock cycles for fck < 12MHz, 3 CPU clock cycles for fck >= 12MHz
High:> 2 CPU clock cycles for fck < 12MHz, 3 CPU clock cycles for fck >= 12MHz

fck is less than 12 MHz so the first conditions apply…

Low:> 2 CPU clock cycles for fck < 12MHz
High:> 2 CPU clock cycles for fck < 12MHz

The next value greater than 2 is obviously 3 so the Low pulse has to be at least 3 CPU clock cycles and the High pulse has to be at least 3 CPU clock cycles. Which means the wavelength / SPI clock has to be at least 3+3 = 6 total CPU clock cycles making the maximum SPI clock…

1000000/(3+3) = 166,666.

The nearest lower SPI clock for an Arduino is 125k.

Coding Badly, thanks for taking the time to answer this. But where did you get that information? Looking at the datasheet I see this text:

Note: 1.
In SPI Programming mode the minimum SCK high/low period is: -2tCLCL for fCK <12MHz

I took this to mean that the SPI clock period could be as short as 4 X system clock. Why am I wrong?

28.8 Serial Downloading

Why am I wrong?

My experience matches yours. I suspect "Note 1" is not correct.

My sketch usually tries to clear the "divide clock by 8" fuse. Do you have the latest version?

  • 2 t CLCL for f CK < 12 MHz
  • 3 t CLCL for f CK > 12 MHz

I’m not familiar with the concept of minus two clock cycles. What are they getting at?

[quote author=Nick Gammon date=1432009684 link=msg=2238050] My sketch usually tries to clear the "divide clock by 8" fuse. Do you have the latest version? [/quote] Fresh from github, version 1.13. As far as I can tell from a quick perusal of the documentation and the code it doesn't change any of the fuses. I wouldn't have been happy had it done anything other than report on what it found.

Also: I accidentally ordered an Atmega328. I had to modify the sketch to add an entry in the signatures table for that part.

[quote author=Nick Gammon date=1432009952 link=msg=2238051] I'm not familiar with the concept of minus two clock cycles. What are they getting at? [/quote] Well, I'm not entirely sure. I finally "decided" that those minus signs were actually just bullets. But the datasheet does say ">2" in that section Coding Badly pointed out. Anyway, it sounds like there isn't really anything especially flaky with my breadboard and wiring.

Inching along...

jboyton: As far as I can tell from a quick perusal of the documentation and the code it doesn't change any of the fuses. I wouldn't have been happy had it done anything other than report on what it found.

Oh yeah, the board detector sketch doesn't change anything. The programmer sketch does.

I had to modify the sketch to add an entry in the signatures table for that part.

I thought I had the Atmega328 in the list. Ah I see, it was only in the board programmer sketch. Updated now, new version pushed to GitHub.

[quote author=Nick Gammon date=1432068813 link=msg=2239114]I thought I had the Atmega328 in the list. Ah I see, it was only in the board programmer sketch. Updated now, new version pushed to GitHub.[/quote]

Unfortunately, @jboyton did not create a pull request with his update. Then you could have done a quick review and merged.

:'(

Sadly that didn't happen. Still, I'm just getting to grips with pull requests myself. I used to eye them with deep suspicion.

Now I understand them a bit better. :)

Nick, I wasn't sure if you would care.

I also had to modify avrdude.conf (IDE 1.0.5) to add the 328, but it looks like that oversight has already been taken care of in 1.6.x. Well, maybe it's time for me to at least start thinking about upgrading.

I wouldn't. I see complaints all day about 1.6.x.

Personally I use 1.0.6 for most tests.