Uploading to ATmega328 from Raspberry Pi

Hello, everyone,

I am uploading my sketches onto the ATmega328 via USB and FT232RL. I am using the standard setup, except for using a resonator (crystal with in-built 30pF capacitors). I use Arduino IDE.

Interestingly, there is no problem when I upload sketches from my PC. However, when I upload from Raspberry Pi (/dev/ttyUSB0), there are always mismatch errors, like this one:

avrdude: verification error, first mismatch at byte 0x0105
         0x27 != 0x2f

The error numbers keep changing.

Also, there is no problem when uploading sketches to Arduino Uno from the same Raspberry Pi (/dev/ttyACM0).

Since it works on PC, this is more of an annoyance than a real problem, but I would still like to solve it.

Is it always one bit that fails? I've seen it before in other posts but don't know if it got solved. I would try some different cables first (between the FTDI and the Pi.

Yes, but it seems that Arduino IDE stops verification as soon as it bumps across the first mismatch.

But if you try again, is there again a single bit difference?

No, occasionally it is two bits, e.g.

avrdude: verification error, first mismatch at byte 0x01f4
         0xff != 0x9f

OK, I don't know.

As said, I would try some other cables.

If you're having serial comms issues I would look at the subsystems that are responsible for making them work and if there's two thing I know in this world it's that:

  1. There's no such thing as a free lunch
  2. You can't have serial comms if your clock has issues

So my long worded question is, what's different about your timing setup?

I did initially suspected resonator, but then I realised that there is no problem when I upload sketches from PC.

I assume you essentially suggest that I go with a crystal and two 22pF capacitors?

Yup, the resonator effects all the timers, while you may be able to use a slow serial protocol, you are having issues with any reasonable serial speed. This is a known issue.
Why, if I may ask, did you choose the resonator and which model is it?

It is easier to handle one component than three. Also, resonators are used by default on Arduino Mini and Nano. I am using DIP version ZTT 16.00MX.

That resonator is perfectly capable of running anywhere between 15.5 and 16.5 MHz maybe even wider. I know very little about fundamental electronics, but I do know how to generate reliable timing down to about 2.5ns.

But here's the cool part, don't listen to me, test it for yourself. 2 machines identical except the resonator, shared signal ground and power source, same source code, and a single button connected to both machines. Do a couple billion things like taking random readings from the analog pins then do hashes with them. Just be sure not to use constants for the math or the compiler will optimize them out.
I'll bet you a glazed donut that they never finish at the same time.

Well, I will definitely make a test with an oscillator and two capacitors when I get some.

Cool, I buy these:

It's 6 complete Unos minus the USB chips, so you have to program them with a serial adapter or another Arduino.
I recommend them because the entire 6 pack cost me $30 including shipping.
So easy to slap together a duino sandwich.

Using crystal plus two condensers did not help. About 70 eurocents of components wasted.

I think that communication protocols are robust enough to tolerate small differences in timing. Plus resonators are most probably better than your estimate.

Why do you say that? It’s datasheet says 1.1% accuracy, including temperature variation and aging effects. (0.5% without.). Your claim is more than 5 to 10x worse.

Resonators are generally accepted to be “good enough” for serial comm, and “real” arduino unos use resonators as well.

(Although, 1% error in a clock is about 14 minutes per day, which we’d consider unacceptable in a wrist-watch…)

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.