Go Down

Topic: Standalone Mega2560 boot time (Read 5040 times) previous topic - next topic

gabidanpremier

Hello everyone. I'm new to this forum and I hope you'll be able to help me.

I built a standalone Mega2560 board with the Atmega16U2 to be able to use my system as closest as possible to a real Arduino.

Everything in my setup is working perfectly, except 1 small detail. Since I don't own a real Arduino Mega2560, I want to check with other users if it's something wrong or not.

When I power up the unit, the program on the Mega2560 starts right away. If I program it using the Arduino software, again, the program starts right at the end of the process. But, when I open the serial monitor, the chip resets and the program starts 9.5 seconds later. Is this delay normal ? On my Uno, this same delay is near nothing.

Of course, I've made some research on the net, on the forum, etc. I used my oscilloscope and found the reset is working normally (same behavior as on my Uno). The only other connection to the Mega2560 is the serial connection. Again, the TX of the Atmega16U2 goes low (for 39 us) when the chips resets the Mega2560 and this is the same with my Uno.

I tried to use the exact same settings of the real Mega2560. I'm using an AVR MkII clone and AtmelStudio 6. For the PCB, I simply followed the Eagle schematics of the real one. Here is the details of my bootloaders and initial chip settings (programs found in Arduino 1.0.3 directory) :

Atmega16U2
Arduino-usbserial-atmega16u2-Mega2560-Rev3.hex
Extended : 0xF4
High : 0xD9
Low f : 0xEF
Lock bits : 0xEC

Mega2560
stk500boot_v2_mega2560.hex
Extended : 0xFD
High : 0xD8
Low f : 0xFF
Lock bits : 0x0F

Thank you for your help !

Nick Gammon

No it's not normal. Try the bootloader (for the 2560) from here:

https://github.com/arduino/Arduino-stk500v2-bootloader/blob/master/goodHexFiles/stk500boot_v2_mega2560.hex
Please post technical questions on the forum, not by personal message. Thanks!

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

Nick Gammon

Are they the actual fuse settings? Or what is in board.txt?

Use avrdude to read back the signatures fuses and show us that.
Please post technical questions on the forum, not by personal message. Thanks!

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

gabidanpremier

The fuses settings are from boards.txt and they are the actual fuses settings.

I tried the firmware, no change.

I'm not using avrdude, but AtmelStudio 6. Can this be an issue ?

Nick Gammon

Can you read the fuses with avrdude and copy and paste the results here please?

A 9 second delay sounds suspiciously like you have the "divide by 8" fuse set (for the clock).
Please post technical questions on the forum, not by personal message. Thanks!

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

gabidanpremier

#5
Jan 26, 2013, 06:19 pm Last Edit: Jan 26, 2013, 09:19 pm by gabidanpremier Reason: 1
Here is what I got from avrdude. The results where in a bin file.

Command : avrdude -c avrispmkII -p m2560 -P usb -U efuse:r:ext:r
Result : 0xFD

Command : avrdude -c avrispmkII -p m2560 -P usb -U hfuse:r:high:r
Result : 0xD8

Command : avrdude -c avrispmkII -p m2560 -P usb -U lfuse:r:low:r
Result : 0xFF

Any hint ?

Thank you for your help !

gabidanpremier

I don't know avrdude a lot, but I think this information may be more useful. Using the command : avrdude -c avrispmkII -p m2560 -P usb -v

I got :

-----------------Begin-----------------

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

         System wide configuration file is "C:\WinAVR-20100110\bin\avrdude.conf"


         Using Port                    : usb
         Using Programmer              : avrispmkII
avrdude: usbdev_open(): Found AVRISP mkII, serno: 000200012345
         AVR Part                      : ATMEGA2560
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PA0
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page
      Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    10     8    0 no       4096    8      0  9000  90 00 0x00 0x00
           flash         65    10   256    0 yes    262144  256   1024  4500  45 00 0x00 0x00
           lfuse          0     0     0    0 no          1    0      0  9000  90 00 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  90 00 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  90 00 0x00 0x00
           lock           0     0     0    0 no          1    0      0  9000  90 00 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0  0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0  0 0x00 0x00

         Programmer Type : STK500V2
         Description     : Atmel AVR ISP mkII
         Programmer Model: AVRISP mkII
         Hardware Version: 0
         Firmware Version Master : 1.17
         Vtarget         : 3.3 V
         SCK period      : 8.00 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.05s

avrdude: Device signature = 0x1e9801
avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as D8
avrdude: safemode: efuse reads as FD

avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as D8
avrdude: safemode: efuse reads as FD
avrdude: safemode: Fuses OK

avrdude done.  Thank you.

-----------------End-----------------

Hopping this may be helpful !

Nick Gammon

The fuses look OK.

I just tried my Mega2560 with the ASCII table example. Re-opening the serial monitor resets the program, but it seems to start instantly.

There is something wrong with your hardware, I suggest. Noise (or lack of pull-up resistors) between the Atmega16U2 and the Atmega2560, or maybe the wrong crystal, or it isn't oscillating correctly. Also make sure you have decoupling capacitors.
Please post technical questions on the forum, not by personal message. Thanks!

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

gabidanpremier

I checked both crystal using my oscilloscope, everything appears to be normal. I used the same crystal with the same resistor as the Arduino board (CSTCE16M0V53-R0 16MHZ (built-in capacitor) with 1M ohm resistor). The blink program makes the LED blink at the exact timing (1000 ms on, 1000 ms off).

I tried to program the 16U2 using the hex file on my Uno and its fuses settings, no improvement. Always exactly 9,5 seconds (within the precision of me using a chronograph !).

I may have missed something... If someone has an idea, I'm listening :)

Nick Gammon

I would try two things in your shoes.

1. Change the fuse to enable clock output. Then put a scope or logic analyzer on the clock output pin.

2. Put a scope or logic analyzer on the main Tx/Rx pins and see if there is activity on them during those 9 seconds.
Please post technical questions on the forum, not by personal message. Thanks!

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

gabidanpremier

Thank Nick for your help, it's greatly appreciated.

1.   I tried the CKOUT Fuse and watch the CLKO with my oscilloscope. Everything is normal, the clock is constant and always working. No problem there.

2.   There is absolutely no activity on either Rx/Tx pins except what I described before (which is happening in the firsts 15 ms).

Nick Gammon


1.   I tried the CKOUT Fuse and watch the CLKO with my oscilloscope. Everything is normal, the clock is constant and always working. No problem there.


At 16 MHz?
Please post technical questions on the forum, not by personal message. Thanks!

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

gabidanpremier

Yes, 16,03 MHz (62.4 ns period).

Nick Gammon

Can you run my sketch here please, and copy and paste the output? (in code tags)

http://www.gammon.com.au/forum/?id=11633
Please post technical questions on the forum, not by personal message. Thanks!

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


Go Up