UPDATED: I've made some progress with my original problem. Skip down to my third post for a more simplified question. I'll leave this up for reference to what was going on.
I can't seem to upload sketches or the bootloader through the USB port. But I can burn .hex files written in AVR Studio through AvrDude in a command window.
The hardware I'm working with:
Newer Arduino MEGA 2560 with the 8U2 chip
Sparkfun AVR Pocket Programmer
Windows XP desktop with Arduino 0022 and XP laptop with 0021
AVR Studio 4
I'll start at the beginning with the symptoms. I'm working on a fairly complicated project with tons of sensors and peripherals. To keep the debugging easy I just started with an analog accelerometer and SD card. Everything was working great. Sketches were uploading, sensors were fine, dataloging was writing to the SD, and it was printing to the serial port. Then I uploaded a revised sketch, opened the serial port, it output a few lines and froze. I reset, and the same thing, none of the interrupts were working. I added a Serial.Println were i thought it froze. It uploaded fine, output the new debug line and froze. I uploaded Blink and that worked fine. I tried burning a new bootloader but it wouldn't take. It just sat there, no TX RX LED and the Arduino IDE froze up.
AT this point it's 1AM so i can't really remember everything i tried step by step. A few things I can remember. AT one point when I plugged in the MEGA into the USB, my computer would lag (without uploading a sketch or anything, just plugging it in). The USB mouse and keyboard were barely responsive but Windows media player kept on playing. I moved over to the laptop and it did NOT do it there. This symptom has since stopped. At one point, if it froze during upload and I unplugged it then plugged it back in, the led would blink what appears to be a default error message. ( On for about 300 milliseconds, OFF(100), ON(100), OFF(300) and repeat.
I've reinstalled Arduino 0022 ( I just overwrote all the files without deleting the entire folder. )
I can NOT burn a new bootloader either through USB or USBtinyISP. Error:
avrdude: stk500_getsync(): not in sync: resp=0x00
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x51
I've tried holding the reset button until right before it uploads a bunch of times but that didn't work.
I've also got this error message but i can't remember what i did to get it. It was something about 0xff != 0x00 in memory location 0x0000
As of right now I CAN upload .hex files through AvrDude. I can burn a basic bare minimum AVR-GCC sketch. It doesn't do anything but setup(); for (;;) loop(); return 0;. It's 292 bytes. I believe this should have overwrote the bootloader. I can also burn the following code and it works just fine. It's about 4100 bytes long.
#include "wiring.h"
int main(void)
{
init();
setup();
for (;;)
loop();
return 0;
}
int ledPin = 13;
void setup() {
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(ledPin, OUTPUT);
}
void loop() {
digitalWrite(ledPin, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(ledPin, LOW); // set the LED off
delay(100); // wait for a second
}
Does this code put the bootloader back on the chip or does it just include everything needed for high level code like digitalWrite() and delay()?
When I power up the MEGA either through USB or ICSP it takes about 30 seconds for the led to light up, then it runs fine. If I hit the reset button there is no 30 second delay.
I would try uploading a larger sketch using the AVR Studio/AvrDude method but I was getting a lot of errors after building.
At this point it appears to me that the 8U2 chip is shot. But why was it intermittently working?
Right no only the RX LED blinks every few seconds when i try to upload, and pin13 LED keeps doing what it was doing. It's like it doesn't want to reset, maybe because there's no bootloader? - no error messages, it just keeps working.
Any advice would be much appreciated. Also if anyone knows how to burn the bootloader and [u]only[/u] the bootloader using AvrDude and the Pocket Programmer, I'd like to try that.
avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x3e000
0x0d != 0xff
avrdude: verification error; content mismatch
avrdude: safemode: Fuses OK
avrdude done. Thank you.
Can anyone explain the verification error or why it wrote 262K of data on a 256K chip with a file that's only 23K?
I can upload BareMinimum and Blink fine, they both work. When i try my large sketch the program hangs. "timeout"
Should i manually reset fuses at described here?
http://ntsdt.net/2009/08/22/burning-the-arduino-bootloader/
I don't understand how they work, so I don't want to start playing around with them.
I know the new bootloader works as proven by the bootloader monitor.
CPU statsArduino explorer stk500V2 by MLSCompiled on = Sep 9 2010CPU Type = ATmega2560AVR_ARCH = 6GCC Version = 4.3.3AVR LibC Ver = 1.6.7CPU signature= 1E9801Low fuse = FFHigh fuse = D8Ext fuse = FDLock fuse = FFBootloader>
I can burn small sketches fine. SD datalogger is about 14K and that works. But if i burn my 19k file, it burns a bunch of code then stops. “timeout” error.
Any ideas?
also when i burn a new bootloader with avrdude in the command prompt, it writes 262k to the chip. That exceeds the 256k of flash on the chip correct?
at the end of the bootload process i get:
avrdude: verification error, first mismatch at byte 0x3e000
0x0d != 0xff
avrdude: verification error; content mismatch
There is an optiboot bug that prevents uploading sketches larger than about 30K on a mega328. I have not heard of similar problems with the MEGA, and it has a significantly different bootloader, but it COULD be something along those lines.
when i burn a new bootloader with avrdude in the command prompt, it writes 262k to the chip. That exceeds the 256k of flash on the chip correct?
No; 1K is 1024 bytes, so 256K is a bit more than 262000 bytes. The bootloader load process starts with a full chip erase, so it probably claims to have programmed every last byte.
A verification error after burning the bootloader isn’t good, though…
HA HA HA 2 whole days I've been ripping my hair out. I thought i fried part of the memory (like a bad sector on a hard drive).
// check smoke alarm status
if (digitalRead(smokeSensor) == HIGH) {
Serial.println("FIRE!!!!!!!!");
// open the co2 valve
digitalWrite(co2Valve, HIGH);
delay(10000);
digitalWrite(co2Valve, LOW);
I just learned about the "!!!" command last night.
So, because the bootloader reads all serial commands it caught it and interpreted it as a request for bootloader menu?
THANK YOU!!!
This might save someone's sanity. I too was having trouble with sketched >29K on a mac.
I was also running Parallels Virtual Machine with windows XP.
On a hunch I stopped parallels and no more problems.
DId not really research what the interplay was, but I am sure there was a war over who owned the USB port.
I will be some cleaver lad/lassie know a Paralles parameter or two that would fix it.