Go Down

Topic: How to program (w/ Arduino ISP) processors of my Arduino Mega-derivative board? (Read 5615 times) previous topic - next topic

FTBug

Dear all,

[Sorry for the long post, but I hope it will help other n00bs like me in the future if I ever find a solution…]
I have just received today the board that I have designed (a derivative of Arduino Mega, with a bunch of peripheral stuff). It is based on the same circuits as the Arduino Mega (I did not want to change the heart of the device) :
- A USB processor (ATMega 16U2)
- A main processor (ATMega 2560)

I now need to program the processors, that are totally empty out of fab.
I tried without success to program the main processor with an Arduino UNO working as an AVR ISP (seen here: http://arduino.cc/en/Tutorial/ArduinoISP) and burning the code from .../Arduino.app/Contents/Resources/Java/hardware/arduino/bootloaders/stk500v2/stk500boot_v2_mega2560.hex… Each time it ended up with :
avrdude: verification error, first mismatch at byte 0x1e000

After hours of Web browsing, terminal invocation of avrdude in interactive mode (I could dump the memory, but my Flash remained painfully empty at address 0x1e000…) and head scratching, I discovered Nick Gammon's magic solution: http://www.gammon.com.au/forum/?id=11635

While looking at his code, I discovered that he was reading address 0x3e000 in the Flash… and after checking in avrdude, in found my program sitting there !! Why on Earth was the ArduinoISP trying to find it at 0x1e000 is beyond my understanding…

Nevertheless, as Nick seems to be the most knowledgeable people here, I switched to his programming sketch… and it worked within a few seconds!!! Amazing !! :smiley-sweat:

Now I tried to program the USB processor, this time again using ArduinoISP and the code found here : https://github.com/arduino/Arduino/blob/6e8e13d7b3679775dae70d9066f05e2f314fe1c1/hardware/arduino/firmwares/arduino-usbserial/Arduino-usbserial-atmega16u2-Mega2560-Rev3.hex

It seemed to program OK (at least Arduino IDE did not complain), so I tried plugging my board on my Mac. Looking at the system details, I see a new USB device, named Arduino (looks good!).
So I tried to upload a blinking sketch… and unfortunately it did not go through : avrdude: ser_recv(): programmer is not responding

I tried to upload it with the Arduino ISP connected to the main processor (and selecting upload with programmer in the IDE menu), it seems not to complain, but then nothing happens when I reset the board.

I'm puzzled…
So now the questions:
- when the Mac sees the USB device, does it mean the USB processor is properly programmed?
- what can I try to progress/validate programming?
- what is the "canonical" way to program such a virgin board?
- is there something wrong with my board? What should I investigate?
- how can I check that the system is alive (after unplugging the Arduino ISP) ?
- where can I learn more about the programming process?

Thanks for your help!! =(

[Edit : changed the title to help understand the issue]

FTBug

Got the scope out! Some more investigations today:
- both quartz seem to oscillate (I see a small 16MHz signal when touching their pins with a x10 probe)
- I see that some digital signals go episodically from the USB processor to the main processor (on the serial line between the 2, named PE0 on the Arduino Mega schematic) when I connect the board to Arduino IDE and try to program a sketch
- I see absolutely no activity on the PE1 line (response from the main processor)

I've double checked my schematic, it is identical to the ArduinoMega

So it seems that the main processor does not answer to the USB processor. Don't know why…

FTBug

Still more news…

I managed to run a small blink program on the main processor, by programming with Arduino ISP.
… but still no luck to get it programmed by USB.

Anyone here ?

nickgammon

Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

nickgammon

My guess is you have the "divide by 8" fuse bit set, but the results of the investigation should confirm this.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

FTBug

Thanks Nick. I ran the board detector : here is the result…
Note : I have played with the HFuse to try D8 and D9 but no difference...

Code: [Select]
Atmega chip detector.
Entered programming mode OK.
Signature = 1E 98 01
Processor = ATmega2560
Flash memory size = 262144
LFuse = FF
HFuse = D9
EFuse = FD
Lock byte = EF
Clock calibration = A4
Bootloader in use: No
EEPROM preserved through erase: No
Watchdog timer always on: No
Bootloader is 8192 bytes starting at 3E000

Bootloader:

3E000: 0D 94 89 F1 0D 94 B2 F1 0D 94 B2 F1 0D 94 B2 F1
3E010: 0D 94 B2 F1 0D 94 B2 F1 0D 94 B2 F1 0D 94 B2 F1
3E020: 0D 94 B2 F1 0D 94 B2 F1 0D 94 B2 F1 0D 94 B2 F1
3E030: 0D 94 B2 F1 0D 94 B2 F1 0D 94 B2 F1 0D 94 B2 F1
3E040: 0D 94 B2 F1 0D 94 B2 F1 0D 94 B2 F1 0D 94 B2 F1
3E050: 0D 94 B2 F1 0D 94 B2 F1 0D 94 B2 F1 0D 94 B2 F1
3E060: 0D 94 B2 F1 0D 94 B2 F1 0D 94 B2 F1 0D 94 B2 F1
3E070: 0D 94 B2 F1 0D 94 B2 F1 0D 94 B2 F1 0D 94 B2 F1
3E080: 0D 94 B2 F1 0D 94 B2 F1 0D 94 B2 F1 0D 94 B2 F1
3E090: 0D 94 B2 F1 0D 94 B2 F1 0D 94 B2 F1 0D 94 B2 F1
3E0A0: 0D 94 B2 F1 0D 94 B2 F1 0D 94 B2 F1 0D 94 B2 F1
3E0B0: 0D 94 B2 F1 0D 94 B2 F1 0D 94 B2 F1 0D 94 B2 F1
3E0C0: 0D 94 B2 F1 0D 94 B2 F1 0D 94 B2 F1 0D 94 B2 F1
3E0D0: 0D 94 B2 F1 0D 94 B2 F1 0D 94 B2 F1 0D 94 B2 F1
3E0E0: 0D 94 B2 F1 41 54 6D 65 67 61 32 35 36 30 00 41
3E0F0: 72 64 75 69 6E 6F 20 65 78 70 6C 6F 72 65 72 20
3E100: 73 74 6B 35 30 30 56 32 20 62 79 20 4D 4C 53 00
3E110: 42 6F 6F 74 6C 6F 61 64 65 72 3E 00 48 75 68 3F
3E120: 00 43 6F 6D 70 69 6C 65 64 20 6F 6E 20 3D 20 00
3E130: 43 50 55 20 54 79 70 65 20 20 20 20 3D 20 00 5F

[cut here because message is too long…]

3FCF0: FE CF 92 BD 81 BD F8 9A 99 27 80 B5 08 95 26 2F
3FD00: F9 99 FE CF 1F BA 92 BD 81 BD 20 BD 0F B6 F8 94
3FD10: FA 9A F9 9A 0F BE 01 96 08 95 F8 94 FF CF FF FF
3FD20: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FD30: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FD40: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FD50: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FD60: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FD70: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FD80: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FD90: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FDA0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FDB0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FDC0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FDD0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FDE0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FDF0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FE00: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FE10: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FE20: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FE30: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FE40: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FE50: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FE60: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FE70: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FE80: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FE90: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FEA0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FEB0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FEC0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FED0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FEE0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FEF0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FF00: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FF10: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FF20: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FF30: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FF40: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FF50: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FF60: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FF70: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FF80: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FF90: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FFA0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FFB0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FFC0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FFD0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FFE0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
3FFF0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF

MD5 sum of bootloader = D9 E6 6B 4E D1 A6 11 2C 61 8F 9B D5 5D 24 E2 13

First 256 bytes of program memory:

0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
10: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
20: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
30: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
40: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
50: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
60: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
70: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
80: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
90: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
A0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
B0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
C0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
D0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
E0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
F0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF


FTBug

BTW, I also changed the ATMega 2560 include file of your Atmega chip programmer, and replaced it with the data found in
.../Apps/Arduino.app/Contents/Resources/Java/hardware/arduino/bootloaders/stk500v2/stk500boot_v2_mega2560.hex

… but it didn't help!

Don't know why it is different from the one you have bundled with the Atmega chip programmer, since they seem to be the same HEX files...

nickgammon

Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

FTBug


Quote

Bootloader in use: No


That's why it won't bootload.


Well… I was playing with the High Fuse (between D8 and D9)… :-)
OK, I tried again, this time with D8 in the High Fuse : the board detector now gives me this:

Code: [Select]
Atmega chip detector.
Entered programming mode OK.
Signature = 1E 98 01
Processor = ATmega2560
Flash memory size = 262144
LFuse = FF
HFuse = D8
EFuse = FD
Lock byte = EF
Clock calibration = A4
Bootloader in use: Yes
EEPROM preserved through erase: No
Watchdog timer always on: No
Bootloader is 8192 bytes starting at 3E000

Bootloader:



… But when I try to load  a sketch through USB, I see the Tx LED blinking a few times (nothing on the Rx LED), and I get this:

Code: [Select]
Taille binaire du croquis : 1 632 octets (d'un max de 258 048 octets)
~/Apps/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/avrdude -C~/Apps/Arduino.app/Contents/Resources/Java/hardware/tools/avr/etc/avrdude.conf -v -v -v -v -patmega2560 -cwiring -P/dev/tty.usbmodem1411 -b115200 -D -Uflash:w:/var/folders/4q/xhh5b2xd1c93p_6jv57jkydw0000gn/T/build8988978563925519059.tmp/BlinkPMC.cpp.hex:i

avrdude: Version 5.11, compiled on Sep  2 2011 at 18:52:52
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "~/Apps/Arduino.app/Contents/Resources/Java/hardware/tools/avr/etc/avrdude.conf"
         User configuration file is "~/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/tty.usbmodem1411
         Using Programmer              : wiring
         Overriding Baud Rate          : 115200
avrdude: wiring_open(): releasing DTR/RTS
avrdude: wiring_open(): asserting DTR/RTS
avrdude: Send: . [1b] . [01] . [00] . [01] . [0e] . [01] . [14]
avrdude: ser_recv(): programmer is not responding
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: Send: . [1b] . [01] . [00] . [01] . [0e] . [01] . [14]
avrdude: ser_recv(): programmer is not responding
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: Send: . [1b] . [01] . [00] . [01] . [0e] . [01] . [14]
avrdude: ser_recv(): programmer is not responding
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: Send: . [1b] . [01] . [00] . [01] . [0e] . [01] . [14]
avrdude: ser_recv(): programmer is not responding
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: Send: . [1b] . [01] . [00] . [01] . [0e] . [01] . [14]
avrdude: ser_recv(): programmer is not responding
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: Send: . [1b] . [01] . [00] . [01] . [0e] . [01] . [14]
avrdude: ser_recv(): programmer is not responding
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer

avrdude done.  Thank you.

nickgammon

Quote

(nothing on the Rx LED),


Do you mean, input to the chip? Clearly that should be flashing as avrdude tries to talk to it. So at this point it is something electrical.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

FTBug

NICK YOU'RE A GENIUS !!!!

Your remark concerning the "divide by 8" clock made me check the corresponding fuse on the main processor (which was OK), but after a few minutes, I realized that I had to check the USB processor as well… and BANG!! It was set to 5E !!

I programmed it with DE and tried to load a sketch via USB… YEESSSSSS !!!!! It works!!!  :smiley-mr-green:

Thank you VERY much !!! I was sooo frustrated that my new board could not be programmed.

PS: I spent quite a lot of time reading the resources on your Web site today, thank you again for the great work!  XD :)

Go Up