Using Arduino Zero as an ISP programmer (sync issue)

Hi,

I recently obtained an Arduino M0, wanted a zero but someone displayed the wrong model on Amazon so Zero model in image M0 in post. I did flash over the Zero boot loader though.

I have been trying to burn a boot loader to the Atmega328p on a breadboard using the internal clock however every time no matter what I do I cannot get it to burn the boot loader. I just get the below error even when using an external 8MHz crystal. Has anyone else had success in using the Zero as an ISP programmer?

avrdude: stk500_getparm(): can't get into sync
avrdude: stk500_initialize(): programmer not in sync, resp=0x15
avrdude: stk500_initialize(): programmer not in sync, resp=0x15
avrdude: stk500_initialize(): programmer not in sync, resp=0x15
avrdude: stk500_initialize(): programmer not in sync, resp=0x15

I do have the breadboard “Board” installed in the IDE and powering it from 3v3 which should be supported I think when 8MHz or below.

I am using the attached Arduino project as the ArduinoISP that comes with IDE 1.6.x does not work on the Zero.

Thanks

ArduinoISP.ino (16.6 KB)

Is the 328 running at 3.3V? Otherwise, the M0 might have problems pulling RESET "high enough."

You might also need to figure out how to turn down the SPI speed of the M0. I don't know what it defaults to, but if the chip is running at 48MHz, it could easily be going way too fast for a 1MHz or 8MHz AVR.

Hi

Thanks for the reply. I am running the 328p on the 3.3 volt line as I thought running it at 5 volts on the Zero would kill the 3.3 volt logic. Also I am not sure if this is enough but the attached file has "#define SPI_CLOCK (1000000/6)" set which is 1MHz I think.

Is there anything else that would be done to confirm the SPI speed?

Thanks

I have the same problem.
I am looking into it.

The SPI clock speed is indeed ok. The sketch uses software spi with a suitable speed...
The problem looks related to serial communication (over usb). It gets out of sync from the second command on.

I'll keep you posted.

Can you confirm you have an M0 and not an M0 Pro?
If you have an M0, how did you change the bootloader?

Did not know there was a difference between m0 and m0 pro. But for clarity I have the M0 Pro. I flashed the Zero boot loader with the Arduino IDE. One thing that got me is that when hooking up the analyser to the SPI lines, I could see nothing even when the boot loader flasher is running.

I would have expected to see at least a few pulses (or the my skills with the software is terrible).

But for clarity I have the M0 Pro.

I see. I have a plain M0 which has no onboard debug chip, so right now I cannot burn the boot loader. But that is not a show stopper: I have found a way to use the .cc IDE together with the .org bootloader. (I modified the addresses in the .cc linker script, I compile the sketch in the .cc ide, convert it to hex using arm-none-eabi-objcopy, press the reset button and use the .org avrdude to upload to the M0. Sounds a like "long way to Tipperary" but it works very well).

So I am also using the .cc core, so I think our setup is comparable.

I would have expected to see at least a few pulses

SPI communication starts after the pc and ArduinoISP have exchanged a few messages over serial. We never get that far.

I started debugging the serial communication: the pc sends 0x30 0x20 and the M0 replies nicely with 0x14 0x10. But then the pc sends 'A' 0x80 0x20. This is not correctly received by the M0: it sees 'A' 0x80 0x02. Because ArduinoISP expects 0x20 instead of 0x02, it replies with 0x15 (i.e. 'no sync') and this keeps going for ever.

I don't know why this is happening. The arduino devs have run tests with my ArduinoISP sketch on a real zero and they told me it worked. I fail to see why the M0 would behave differently...to be continued...
(I wanted to run these tests too and ordered an M0 as that is the only thing I can get in Europe).

What does work is using the real uart for serial communication.
For me, I had to do:

#define SERIAL Serial1

and use an usb to serial converter.
For you it is easier, use the programming port:

#define SERIAL Serial

But then you have to disable autoreset (you should check how that can be done on the M0 Pro.)

I am getting somewhere slowly. Communication works now when using baud rate of 19200 (was 115k) however it now tells me this is not an atmega328p even though it is a blank Atmega328p-PU :frowning:

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.11s

avrdude: Device signature = 0xffffff (retrying)

Reading | ################################################## | 100% 0.11s

avrdude: Device signature = 0xffffff (retrying)

Reading | ################################################## | 100% 0.11s

avrdude: Device signature = 0xffff00
avrdude: Expected signature for ATmega328P is 1E 95 0F
         Double check chip, or use -F to override this check.

On which port was that?

If your still on the native usb port, the baud rate does not matter, there is no real uart involved.

If you are on the programming port:

  • you must have #define SERIAL Serial in the sketch e.g.:
// #ifdef SERIAL_PORT_USBVIRTUAL
// #define SERIAL SERIAL_PORT_USBVIRTUAL
// #else
// #define SERIAL SerialUSB
// #endif

#define SERIAL Serial
  • the baud rate must much that of the sketch, i.e. 19200 by default.
  • autoreset must be disabled:
  • From the M0 PRO doc it is not clear to me whether the M0 PRO resets if you open the port at 19200.
  • The Zero doc states that the Zero's main mcu dos NOT reset if you open it at 19200 baud which is ok. (no auto reset so nothing extra to do for you)
    I expect the M0 PRO behaves the same as the Zero, but it is not guaranteed: thatt depends on the firmware in the edbg chip. Therefore you have to try it out: invoke avrdude and watch whether the 3 ArduinoISP leds (err, hb and pmode) blink sequentially (this indicates a reset).

Provided the M0 Pro does not autoreset at 19200 baud, you should be successful using the programming port, since a similar procedure works on my plain M0.

I have it now working on the native usb port too. This means that the new ArduinoISP sketch works without modification on the Zero/M0/M0 Pro too.

As I expected, the problem was caused by problems in the usb driver.

Here are instructions on how to install a core for the Zero that is not yet released. Wit this core, ArduinoISP works correctly on the native USB port.

Hi there

I have a problem here with my arduino m0 pro and im trying to use isp on it but its giving me error of spdr spif declared scope and all how can i get them to fix them