Arduino Forum

Using Arduino => Microcontrollers => Topic started by: HH75 on Mar 05, 2013, 08:50 am

Title: standalone MEGA 2560
Post by: HH75 on Mar 05, 2013, 08:50 am
Can anyone direct me on how to go about for a standalone Mega 2560...

Besides soldering the Atmega 2560 to a PCB board what are the steps to get it working like an arduino mega.


Thanks
Title: Re: standalone MEGA 2560
Post by: qwertysimo on Mar 05, 2013, 01:29 pm
Guidelines for 328 apply to 2560 as well. See http://arduino.cc/en/Tutorial/ArduinoToBreadboard.
Title: Re: standalone MEGA 2560
Post by: CrossRoads on Mar 05, 2013, 03:21 pm
connect up 16 MHz xtal, two 22pf caps, 10K reset pullup resistor, 100nF/0.1uF caps on the VCC/AVCC pins.
Connect up ICSP header with +5, Gnd, Reset, SCK, MISO, MOSI.
Apply power, bootload with Atmel AVR ISP MKii, or wth Nick Gammon's Arduino as ISP sketch.
http://www.gammon.com.au/forum/?id=11635
Title: Re: standalone MEGA 2560
Post by: HH75 on Mar 06, 2013, 08:28 am
Thanks for the reply.

According to this link http://arduino.cc/en/Main/Standalone, to burn the bootloader do I need both the AVR programmer and the FT232 USB to serial breakout board?

Can I only use the AVR programer alone since it connects to the MISO, MOSI, SCK, RESET of the microcontroller and it has a USB on the other end to connect to PC?

Why is the need for the FT232 breakout board?

Thanks
Title: Re: standalone MEGA 2560
Post by: fungus on Mar 06, 2013, 09:19 am

Thanks for the reply.

According to this link http://arduino.cc/en/Main/Standalone, to burn the bootloader do I need both the AVR programmer and the FT232 USB to serial breakout board?


No.


Can I only use the AVR programer alone since it connects to the MISO, MOSI, SCK, RESET of the microcontroller and it has a USB on the other end to connect to PC?


Yes.


Why is the need for the FT232 breakout board?


You need it to program the chip after you disconnect MISO, MOSI, SCK, RESET.


Title: Re: standalone MEGA 2560
Post by: HH75 on Mar 06, 2013, 09:44 am
So in another word,

I can use the AVR programmer to burn the bootloader and also to download the software code that I have written for the chip?

Title: Re: standalone MEGA 2560
Post by: hiduino on Mar 06, 2013, 01:38 pm
No, not exactly.  If you download a sketch with the AVR programmer it will overwrite the bootloader.  If all you need is to download the sketch then you can skip the bootloader and just use the AVR programmer for downloading sketches.

The bootloader is only needed if you use it along with the FT232 USB and download the sketch via the FT232 USB connection.  Another use of the FT232 USB is for serial communication to the PC using the serial monitor program.

Title: Re: standalone MEGA 2560
Post by: CrossRoads on Mar 06, 2013, 03:08 pm
Burning a bootloader using the IDE's Tools:Burn Bootloader also sets the fuses for correct operation. Do that first before loading any sketch, even if the sketch is to be loaded via File:Upload Using Programmer (after which the sketch starts after any reset, the bootloader is wiped out).
Title: Re: standalone MEGA 2560
Post by: JoeN on Mar 07, 2013, 12:15 am

Burning a bootloader using the IDE's Tools:Burn Bootloader also sets the fuses for correct operation. Do that first before loading any sketch, even if the sketch is to be loaded via File:Upload Using Programmer (after which the sketch starts after any reset, the bootloader is wiped out).


My process for programming standalone Atmel processors so far has been to use the AVR ISP II ($35) with the programming software included in Atmel Studio to do the programming.  This will write the ELF file created by Arduino up to the chip over the programming port, and has a section for setting whatever fuses you want.  In addition, you can use it with the AVR Dragon's ($50) High Voltage programming mode to fix bricked chips.  In addition, if you want to use Atmel Studio to actually write code, either programmer will allow you to debug your code running in-system, which is great.
Title: Re: standalone MEGA 2560
Post by: CrossRoads on Mar 07, 2013, 01:33 am
I used to use Atmel Studio, but got tired of waiting for it to start up and went back to using the IDE.
Burning the bootloader from there kept the fuses consistent with the Arduino boards.
Title: Re: standalone MEGA 2560
Post by: HH75 on Mar 07, 2013, 08:02 am
Hi guys,

I am an amateur and it is difficult for me to understand...

Do I need to burn the bootloader in the first place? Is it just to set the fuses and in case I need to use the FT232? These fuses refer to??

Can I skip that and proceed to download my software into the chip? Will it work?, of course the sketch is a working sketch on the Arduino?

I will only need the FT232 if I need serial communication with the chip else I don't need it?



Title: Re: standalone MEGA 2560
Post by: CrossRoads on Mar 07, 2013, 08:54 am
Browse the data sheet re: the fuses. They do things like determine the clock source, clock speed, etc.
The fuses need be set to use the 2560 as an Arduino Mega.
If you want to use the chip as something else, you could do something as simple as Nothing with the fuses and use the default settings.

If you use an AVR ISP Programmer, you can set the fuses and install a bootloader; this is done via the SPI pins.
You can also download a sketch and not have a bootloader (whether you did anything with the fuses or not) using the AVR ISP Programmer.

If you have a bootloader installed, then you can use a USB/Serial adapter (FT232 chip, CP2102 chip, ATmega16U4 programmed as USB/Serial adapter) to download sketches via the serial interface.

The bootloader installed from the IDE expects the chip to be running at certain speed to sync up with the IDE software on the computer for serial downloads.
The fuses help determine that, along with choice of crystal/resonater for an external clock.

You can of course write your own bootloader to run at different speeds, and make up a matching boards.txt entry for the speeds you are using.

Hope that clarifies things.
Title: Re: standalone MEGA 2560
Post by: hiduino on Mar 07, 2013, 12:40 pm
To clarify a bit further.

Quote
Do I need to burn the bootloader in the first place? Is it just to set the fuses and in case I need to use the FT232? These fuses refer to??


You need to only burn the bootloader once per chip.  Yes to primarily set the fuses, to select the proper clock settings.  The fuses have nothing to do with the FT232, they are not related.

Quote
Can I skip that and proceed to download my software into the chip? Will it work?, of course the sketch is a working sketch on the Arduino?


You can skip the bootloader, if you have done it at least once before(to set the fuses).  You can then download the sketches directly to the chip, using your AVR programmer, as many times as you need for testing.

Quote
I will only need the FT232 if I need serial communication with the chip else I don't need it?


Yes.

Title: Re: standalone MEGA 2560
Post by: HH75 on Mar 07, 2013, 05:11 pm
Thanks guys for the clarification.

It has been most informative.

Title: Re: standalone MEGA 2560
Post by: HH75 on Mar 20, 2013, 08:35 am
Hi,
Do you know if I can use this AVR programmer to download my sketch? It is called Pololu USB AVR Programmer.


Thanks
Title: Re: standalone MEGA 2560
Post by: hiduino on Mar 20, 2013, 11:23 am
Yes, you can.  I was able to use it to program with the Arduino IDE to program some ATtiny84/85/13 chips.

The Pololu USB AVR Programmer driver installs several virtual COM ports.  You need to use the "Pololu USB AVR Programmer Programming Port(COMxx)" port.  Select this COM port in the IDE Tools->Serial Port menu.

You will need to add this Pololu definition to the \arduino-1.0.4\hardware\arduino\programmers.txt file.
(Note: you need to restart your IDE after editing this file)
Code: [Select]

pololu.name=Pololu
pololu.communication=serial
pololu.protocol=stk500v2



Make sure you select the Pololu programmer under Tools->Programmer menu.  And use the Upload Using Programmer.

Title: Re: standalone MEGA 2560
Post by: HH75 on Mar 20, 2013, 05:37 pm
Thanks.

I read this from the pololu user guide, "it does not currently work with Atmel's line of XMega microcontrollers"

Does this means that it cannot be use on the Mega 2560?


Thanks
Title: Re: standalone MEGA 2560
Post by: JoeN on Mar 20, 2013, 07:09 pm

Thanks.

I read this from the pololu user guide, "it does not currently work with Atmel's line of XMega microcontrollers"

Does this means that it cannot be use on the Mega 2560?


Thanks


It will work fine with the MEGA2650, exactly the same as with the 328, just different pin numbers to hook up.  2560 is not an XMEGA chip.

XMEGA is a different line and the X will always be in the chip name.  It's not a placeholder for a number, it's an actual X character.  For example, the ATxmega128A1 is an XMEGA chip.  XMEGAs have the AVR core but significant differences in the way ports are set up.  They usually have other features (they come with a real DAC for example) added and can run at higher clock speeds.  Not too many people  mess with them.  I got a few from Atmel on a sample order (free is my favorite price, especially if I just want to mess with it) and I am going to try them out with my AVR ISP II programmer which supports them.

They are fairly impressive, but I just don't know where they see real world use.  More info:

http://www.atmel.com/products/microcontrollers/avr/xmega_technical_details.aspx
Title: Re: standalone MEGA 2560
Post by: HH75 on Mar 28, 2013, 02:42 pm
I have wired up my mega2560 and try to download the sketch into it using the pololu avr programmer.

I have set up the the programmer to use Pololu and Upload using programmer.

But I am getting error msg "avrdude stk500v2_command() command failed "

There are 2 virtual com port and I have tried both.

Sometimes I get this error "avrdude: usbdev_open(): did not find any USB device "usb""

Title: Re: standalone MEGA 2560
Post by: hiduino on Mar 28, 2013, 03:24 pm
What is your command line for avrdude?

How old is your Pololu AVR programmer?  You might need to update the firmware to v1.0.7 if it's not already at that version.  I think the older version 1.0.1 supported AVRISPV2, not STK500V2.

Title: Re: standalone MEGA 2560
Post by: HH75 on Mar 29, 2013, 02:20 pm
Hi,
I have checked the firmware and it is v1.0.7 (from the device manage - USB\VID_1FFB&PID_0081&REV_0107&MI_04)

I am using the Arduino IDE and I selected Tools->Burn Bootloader and I get this error:

avrdude: stk500v2_command(): command failed
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.

Is it a hardware wiring connection error? Or my procedure is wrong?

Title: Re: standalone MEGA 2560
Post by: JoeN on Mar 29, 2013, 09:02 pm
I have no experience with Pololu's programmer, but I have done standalone 2560s before and did one this week using Atmel programmers.  Just to reiterate the process, bind pin 64 (avcc), 52 (vcc), and 21 (vcc) to 4.5V - 5.5V and pins 63, 53, and 22 to ground.  Reset, pin 20, must be held high through a 10K external resistor in addition to being connected to the programming port - the programming port can overcome this when the 2560 is being programmed but when the 2560 is not being programmed it needs to be high.  Pin 62 (aref) should be connected to ground through a .1uF cap, though this is not strictly necessary.  Have you probed all of these pins to make sure they are connected correctly (aref will be floating but the others should be tied to ground or positive voltage).  Have you ensured continuity between the pins on your programming port and the pins on the 2560?  Are the pins actually in the correct order?  I am betting a hardware issue right now.  You shouldn't need a crystal for the default clock mode but may want to add that too, it shouldn't hurt you as the 2560 will initially use its internal clock.
Title: Re: standalone MEGA 2560
Post by: hiduino on Mar 29, 2013, 09:50 pm
The Pololu programmer does not support powering of the target device.  How are you powering your mega2560?


One word of caution, when burning bootloader from IDE using the Pololu programmer to a mega2560, it tends to hang the IDE.  It appears the Pololu programmer output has very verbose messages that overflows the IDE buffers.  So if the IDE becomes unresponsive then just close the IDE window and reopen it again.

Title: Re: standalone MEGA 2560
Post by: HH75 on Mar 30, 2013, 09:19 am
Thanks for your reply.

I have re-check and probe the wiring again and they are similar to JoeN process. In addition I have 3 x 0.1uF cap connected from AVcc to Gnd. I also have a resonator and a 1K resistor connected across the XTAL1 and XTAL 2. The datasheet of the resonator is attached.

The 6 ISCP pins are also probed from the 2560 up to the Pololu programmer where the 6 pins are indicated as shown.

I am currently powering the 2560 with a 9V battery cell thru a voltage regulator that provides a constant 5V output. The voltage level is sufficient as indicated by the Pololu programmer yellow blinking LED (which means that the programmer has detected the target device, and the voltage on the target VDD line is high).

The Arduino IDE didn't really hang but returns the following error msg when I tried to download bootloader or upload sketch using programmer.

avrdude: stk500v2_command(): command failed
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.

Title: Re: standalone MEGA 2560
Post by: hiduino on Mar 30, 2013, 12:06 pm
Usually those type of errors indicate bad ICSP connections to the target device.  Can you post the full output?

Title: Re: standalone MEGA 2560
Post by: HH75 on Mar 30, 2013, 03:02 pm
Can you explain more on the full output?

I am using the Arduino IDE and the errors I received when burning bootloader and uploading using programmer are the same.

See attached screenshot.

Title: Re: standalone MEGA 2560
Post by: hiduino on Mar 30, 2013, 03:40 pm
From the IDE File->Preferences menu, you can enable "show verbose output during upload".  Then post the results.

The errors you are seeing could be due to no system clock, or bad connections. What kind of prototyping board are you using for your ATmega2560?

Title: Re: standalone MEGA 2560
Post by: HH75 on Mar 30, 2013, 03:49 pm
Thanks.

I have attached the verbose output. Please help me on this, I can't figure out anything from this output.

I am using a Schmart board with TQFP 64 pin for my mega2561. I wired it up as per what I had mentioned in my earlier post.
Title: Re: standalone MEGA 2560
Post by: HH75 on Mar 30, 2013, 03:52 pm
Hi,

I noticed this in the verbose output:
         SCK period      : 1.1 us
         Varef           : 0.0 V
         Oscillator      : 3.686 MHz

Does this imply that my circuit oscillator is 3.686 MHz?
Title: Re: standalone MEGA 2560
Post by: hiduino on Mar 30, 2013, 04:19 pm
No I believe that is the programmers clock speed.

What speed is your resonator?

The output indicates that the programmer cannot communicate to the ATmega2561.

Also the ATmega2561 is not the same as the ATmega2560, so we should change the part number to avrdude.  But this is not why it's failing yet.

How is your reset pin connected up?

Title: Re: standalone MEGA 2560
Post by: HH75 on Mar 30, 2013, 04:25 pm
The speed of the resonator is 16MHz.

The reset pin is currently tied up to 5V thru a 10K resistor.

Title: Re: standalone MEGA 2560
Post by: JoeN on Mar 30, 2013, 06:34 pm

The speed of the resonator is 16MHz.

The reset pin is currently tied up to 5V thru a 10K resistor.




The reset pin sounds fine.  I've never used a resonator, only a crystal.  I don't think it should matter.  Unless you have set the fuse, the 2560 is using it's internal oscillator anyway, and since you cannot connect I assume you have not set that fuse yet.
Title: Re: standalone MEGA 2560
Post by: HH75 on Mar 31, 2013, 05:00 am

You mean the 2560 is not using the resonator that is connected to it now?

I have set no fuse yet at the moment, do I have to set any fuses and how can I do that?
Title: Re: standalone MEGA 2560
Post by: JoeN on Mar 31, 2013, 05:26 am


You mean the 2560 is not using the resonator that is connected to it now?

I have set no fuse yet at the moment, do I have to set any fuses and how can I do that?


According to the datasheet:

10.3.1 Default Clock Source

The device is shipped with internal RC oscillator at 8.0MHz and with the fuse CKDIV8 programmed,
resulting in 1.0MHz system clock. The startup time is set to maximum and time-out
period enabled. (CKSEL = "0010", SUT = "10", CKDIV8 = "0"). The default setting ensures that
all users can make their desired clock source setting using any available programming interface.

This means that this chip, and I think all 8 bit AVRs are this way, is set to use the internal oscillator by default.  This is the safest possible setting because unlike an external resonator, crystal, or clock, that internal oscillator is actually guaranteed to be there.  AVRs are bricked if the clock source is selecting one that doesn't really exist.
Title: Re: standalone MEGA 2560
Post by: Docedison on Mar 31, 2013, 05:48 am
From reply # 23...
Quote
Thanks for your reply.

I have re-check and probe the wiring again and they are similar to JoeN process. In addition I have 3 x 0.1uF cap connected from AVcc to Gnd. I also have a resonator and a 1K resistor connected across the XTAL1 and XTAL 2. The datasheet of the resonator is attached.


Likely the problem, If true...100K to 1M ohm is typical and Arduino uses 1 M

Bob
Title: Re: standalone MEGA 2560
Post by: HH75 on Mar 31, 2013, 06:10 am
Typo error, it is a 1M resistor connected across the resonator.

That means regardless of whether my resonator is working or not, it should work using the internal oscillator? So it is not the resonator problem.

Title: Re: standalone MEGA 2560
Post by: hiduino on Mar 31, 2013, 06:18 am
Ahh, okay.  If it's still at factory default of 1MHz internal clock then you may need to slow down the Pololu programmer's ISP Frequency.  You need to check your Windows Pololu USB AVR Programmer Configuration Utility and see what ISP Frequency it is set to.  If it is 750kHz or above then it's too fast to program 1MHz AVRs.  You will need to set it down to 200kHz or below.



Title: Re: standalone MEGA 2560
Post by: HH75 on Mar 31, 2013, 06:37 am
I have tried setting it down to the lowest of 1.5Khz but I am still getting the same error log.

Just to recheck my step for burning bootloader...

I hooked up pololu programmer to the ISCP pin, power up the mega 2561, run the Arduino IDE, check the correct serial port is used, check the correct programmer is used and click Burn Bootloader.



Title: Re: standalone MEGA 2560
Post by: hiduino on Mar 31, 2013, 06:46 am
The ISP Frequency of 1.5kHz may be too low actually.  My testing showed 200kHz works best for 1MHz AVRs.