Uno and 2560 Mega compatability

Hi,

I wrote a program that runs well on an Uno. I have an LCD display and a few buttons. I tried to load it on the Mega 2560 board and it doesn't run, nothing shows on the display or nor do the buttons work. I reloaded the Blink program to be sure that my uploads were working and the Blink light program ran on the Mega 2560 ok. I have looked for compatibility issues and I can't find any. Does any one out there have any ideas why it doesn't work on the Mega 2560.

StanK

There should be no reason for software that runs on a Uno would not run on a mega board. However on the hardware side there are differences, mainly what pins support the I2C hardware. So tell us more about the LCD display (a link would work well) and perhaps post your sketch, It shouldn't be too hard to figure out what is going on.

Lefty

Hi again,

Well, I used the <LiquidCrystal.h> and <MsTimer2.h> libraries. On the LCD I/O, I moved the two pins from pins 11 and 12 to pins 6 and 7 because I want to use 10, 11 and 12 for and SD card interface. Other than that I haven't changed much.

I built an interface shield that has the buttons on it and the LCD interface. I also use pins 8, 9 and 10 for off board I/O, and 2 analog pins for button inputs.

I don't know how the code would affect anything other than maybe the Timer interrupt?

Stan K

I want to use 10, 11 and 12 for and SD card interface.

Probably unrelated to the problem, but doesn't the SD Card require the SPI pins? (Which aren't 10-12 on the Mega.)

Have you added serial.print()s to see how far the code is getting?

StanK:
Hi again,

Well, I used the <LiquidCrystal.h> and <MsTimer2.h> libraries. On the LCD I/O, I moved the two pins from pins 11 and 12 to pins 6 and 7 because I want to use 10, 11 and 12 for and SD card interface. Other than that I haven't changed much.

I built an interface shield that has the buttons on it and the LCD interface. I also use pins 8, 9 and 10 for off board I/O, and 2 analog pins for button inputs.

I don't know how the code would affect anything other than maybe the Timer interrupt?

Stan K

I've used MsTimer2 library on both 328 and mega boards with no problem or changes required. I use a serial based LCD display so haven't had the need to play with LiquidCrystal library but I don't think there is any fundemental difference using it on a 328 Vs mega board.

So I guess other then wiring errors or LCD software parameter errors when changing pin assignments for the LCD, I can't think of any reason why you can't get the sketch to run on your mega board.

Lefty

I think I have narrowed it down to the MsTimer2. I went back to some earlier sketches and I can get it to work when there is no MsTimer2 interrupt. I also noticed in the MsTimer2 library, it says it has been updated for the 328 but no mention of the Mega 2560. Could this be the problem?
Is the any other Interrupt libraries or functions available for the Mega.

StanK

StanK:
I think I have narrowed it down to the MsTimer2. I went back to some earlier sketches and I can get it to work when there is no MsTimer2 interrupt. I also noticed in the MsTimer2 library, it says it has been updated for the 328 but no mention of the Mega 2560. Could this be the problem?
Is the any other Interrupt libraries or functions available for the Mega.

StanK

As I said before I've used MsTimer2 on both my 328 and my mega1280 board with no problem, however I don't have a mega2560 board so I looked in my MsTimer2 library folder and noticed there is a patch file called MsTimer2.cpp.patch which I've included below. It looks like it defines the newer mega2560 chip, so is probably something you require. The problem is I can't tell you how to include the patch into the MsTimer2.cpp file, but perhaps someone here can?

--- MsTimer2.cpp.orig	2011-02-13 16:44:59.000000000 -0700
+++ MsTimer2.cpp	2011-02-13 16:42:35.000000000 -0700
@@ -39,7 +39,7 @@
 void MsTimer2::set(unsigned long ms, void (*f)()) {
 	float prescaler = 0.0;
 	
-#if defined (__AVR_ATmega168__) || defined (__AVR_ATmega48__) || defined (__AVR_ATmega88__) || defined (__AVR_ATmega328P__) || (__AVR_ATmega1280__)
+#if defined (__AVR_ATmega168__) || defined (__AVR_ATmega48__) || defined (__AVR_ATmega88__) || defined (__AVR_ATmega328P__) || (__AVR_ATmega1280__) || (__AVR_ATmega2560__)
 	TIMSK2 &= ~(1<<TOIE2);
 	TCCR2A &= ~((1<<WGM21) | (1<<WGM20));
 	TCCR2B &= ~(1<<WGM22);
@@ -111,7 +111,7 @@
 void MsTimer2::start() {
 	count = 0;
 	overflowing = 0;
-#if defined (__AVR_ATmega168__) || defined (__AVR_ATmega48__) || defined (__AVR_ATmega88__) || defined (__AVR_ATmega328P__) || (__AVR_ATmega1280__)
+#if defined (__AVR_ATmega168__) || defined (__AVR_ATmega48__) || defined (__AVR_ATmega88__) || defined (__AVR_ATmega328P__) || (__AVR_ATmega1280__) || (__AVR_ATmega2560__)
 	TCNT2 = tcnt2;
 	TIMSK2 |= (1<<TOIE2);
 #elif defined (__AVR_ATmega128__)
@@ -124,7 +124,7 @@
 }
 
 void MsTimer2::stop() {
-#if defined (__AVR_ATmega168__) || defined (__AVR_ATmega48__) || defined (__AVR_ATmega88__) || defined (__AVR_ATmega328P__) || (__AVR_ATmega1280__)
+#if defined (__AVR_ATmega168__) || defined (__AVR_ATmega48__) || defined (__AVR_ATmega88__) || defined (__AVR_ATmega328P__) || (__AVR_ATmega1280__) || (__AVR_ATmega2560__)
 	TIMSK2 &= ~(1<<TOIE2);
 #elif defined (__AVR_ATmega128__)
 	TIMSK &= ~(1<<TOIE2);
@@ -145,7 +145,7 @@
 }
 
 ISR(TIMER2_OVF_vect) {
-#if defined (__AVR_ATmega168__) || defined (__AVR_ATmega48__) || defined (__AVR_ATmega88__) || defined (__AVR_ATmega328P__) || (__AVR_ATmega1280__)
+#if defined (__AVR_ATmega168__) || defined (__AVR_ATmega48__) || defined (__AVR_ATmega88__) || defined (__AVR_ATmega328P__) || (__AVR_ATmega1280__) || (__AVR_ATmega2560__)
 	TCNT2 = MsTimer2::tcnt2;
 #elif defined (__AVR_ATmega128__)
 	TCNT2 = MsTimer2::tcnt2;

Thanks for the info Lefty. I kinda figured it was a set up issue. I guess now I'll have to patch the timer cpp file. I am not sure how to do that but I started another topic more focused on that. I think the lines in the patch that have a minus in front of them are removed and the lines with the + in front are added, but I don't know.

StanK

I want to let anybody who cares that I solved this problem by updating the MsTimer2 library CPP file by adding
|| (AVR_ATmega2560) to each of the four lines with the processor definitions.

Thanks for the help

StanK