Mega - serial1, 2 und 3 - initialization fails

Hi,
I just got the Arduino Mega - works perfectly, but not the serial communication.
As long as i reference the serial communication package, the sketch does not run after uploading.
Note that the Mega has 4 serial interfaces and ATmega1280.
I downloaded the latest software 0017, but the same result.
Luckily after commenting out the initialization of serial1, 2 and 3 in hardware/core/arduino/HardwareSerial.cpp lines 216 to 218 (version 0017), it worked at least with first Serial port.
Seems the initialization of serial1,2 and 3 crashes.

Till now i would use only one serial, but it would be good to have the rest also working.

And some info:
running openSUSE 11.1 (i586)

SUN jre:
Java(TM) SE Runtime Environment (build 1.6.0_15-b03)
Java HotSpot(TM) Server VM (build 14.1-b02, mixed mode)

AVR:
avr-libc-1.6.7-4.1
cross-avr-gcc44-4.4.1_20090722-19.1
cross-avr-binutils-2.19.51-15.2
avrdude-5.5-137.6

Regards,
Kompi

Hi,

Anyone having the arduino mega with successfully initialized serial interface?
Or should i better return it as deffect?
I still hope it is software issue.

Regards,
Kompi

Working great here.

You should post your code and we can have a look at what is going on.

b

Hi,

Which OS are you running? I can try with the same version as yours.
I will also try the windowz version tomorrow.

Actually there is no real code, even this hangs:
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.println("Hello world!");
delay(1000);
}

I know this may sound silly (like "make sure it's plugged in" kinda silly), but are you sure you've selected the right board in the IDE?

Tools->Board->Arduino Mega

Don't shoot me for asking. I've made the mistake myself a few times.

b

sure, i have selected the right board,
when commenting out the serial1,2,3 object initialization (HardwareSerial.cpp), the first serial works fine alone

are you running your IDE on Windows?

Running version 17 and windows xp sp3. I tested my mega with a simple sketch that outputs on serial port and one other of the three remaining mega serial ports (serial2,3,4, there is no serial1 port, it's just called serial in software).

I was able to get a simple sketch to stream data out two serial ports at a time and tested that all three of the extra serial ports worked. I used the IDE serial monitor to watch the serial port and used a TTL/RS232 convertor module to monitor the additional active serial(x) port using a PC terminal program on a comm port. Everything seems to work fine.

Lefty

Running XPSP3 and also Vista 64 and Win7 (7100) and haven't tried more than three Serial's in 0017(Serial, Serial2-3) yet, but under 0016 I had all 4 running (Serial, Serial1-3)

No problems here.

Hi,

I just tried it under windows and it runs fine.
So it seems it is a linux problem - i have the latest versions of avr* .
I will invest some time looking for differences and comparing versions.

Just noticed:
The windows version has: gcc version 4.3.2 (WinAVR 20081205)
and i have the 4.4.1 under linux.

Is it worthy to check the latest avr-gcc under windows?

What OS are using the Arduino team for development and testing?
Think it is better to use the same or?

Cheers

just downgraded to gcc 4.1.3 and the serial seems to work now.
Versions:
cross-avr-gcc-4.1.3_20080612-26.5
cross-avr-binutils-2.19-9.1
avr-libc-1.6.1-1.15
avrdude-5.5-111.33

Strange.

I got your PM, and I've uploaded a compiled version of the ASCIITable example:

under Compiled Examples

Can you provide a listing for the .elf file from the 4.4.1 avr-gcc compile? Or just send the .elf file. Either way.

To create a listing file: avr-objdump.exe -h -S filename.elf

b

major difference:
working version: the constructor is a function
non-woking: the constructor is expanded 4 times - inlined

@bhagman: you have the dump as PM

Has somebody a solution in the meanwhile?

I have same issue in Linux on a seeeduino mega.

Thanks for any hints,
mmi

The solution for the moment is actually 2 or 3 responses up - I had same issue under 64bit linux. It turns out to be a problem if you take too new a version of the avr compiler software from your distro - downgrade to the version mentioned a couple posts up and it will magically start working for you :slight_smile:

clarification its actually 5 or 6 posts up - anyhow I can vouch that you can have a newer version of gcc - I'm running like 4.4 its the avr compilers that need to be the older version.

Thanks riftware,
i have read that downgrading is a solution but i thought there is an upgrade or patch somewhere in the meanwhile. :slight_smile:
Seems to be more an avr issue and not an arduino one.
Thanks,
mmi

I'm having a similar problem running Arduino 0017 on Mac OSX 10.6. I can communicate through Serial, but not through Serial1, Serial2, Serial3 on my Arduino Mega.

How can I downgrade (or otherwise adjust) the compiler version used by Arduino 0017 to make it match your specs? Is there some other possible approach to make this work; some way of setting compiler flags?

Meanwhile, I'm going to try compiling this on a PC to see if that gets it working.

/*
Quick test of all serial ports.
Attempt to write the same byte to all serial ports on the Mega.
Currently, only Serial is written to.
Tested by using an MP3Trigger connected to the various RX/TX pairs.
*/

void setup(){
  Serial.begin(38400);
  Serial1.begin(38400);
  Serial2.begin(38400);
  Serial3.begin(38400);
}

void loop() {
  Serial1.write('O');  //does nothing
  Serial2.write('O');  //does nothing
  Serial3.write('O');  //does nothing
  Serial.write('O');  //works
  delay(1000);
}

Turned out I was making a noob mistake. For Serial, you can just connect RX/TX. For Serial1, etc. to work, you need to connect the RX/TX and also connect the device ground to the Mega ground. Not sure why this is, but it makes stuff work.

phew.

I'm seeing the same problem on Solaris with avr-gcc 4.4.2 - my code just calls Serial.begin() in setup(), that works fine on a Duemilanove but hangs on a Seeeduino Mega. I put code in to flash LED13 before the call to Serial.begin() which works fine without the call to Serial.begin() and doesn't work at all when the Serial.begin() call is added, even though it is clearly never reached,

Is there a patch for this, or is the recommended fix still just to use an earlier version of gcc? If so, which is the newest release that still works?