Go Down

Topic: Mega - serial1, 2 und 3 - initialization fails (Read 11486 times) previous topic - next topic

riftware

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.

mmi

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

wicks

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.

Code: [Select]
/*
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);
}

wicks

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?

JAB

I'm having the same issue with my Arduino Mega. I'm running Fedora 12 with the latest avr tools. Has there been any further progress on this issue, or is down-rev'ing the only solution?

Is there any other soft serial libraries that could be used?

gcc 4.3.4 seems to work fine.  And as for the software serial library, I'd try NewSoftSerial - http://arduiniana.org/libraries/NewSoftSerial/

JAB

Yep, I've down-rev'ed: avr-gcc and avr-gcc++ and I can see Hello World on the serial  monitor.

Does NewSoft Serial work on Arduino Mega? And can it be used to take place of existinf serial.print ?

I believe it works, yes - although I haven't yet had time to try it myself.

PeterDewitt

Hi everyone. I just purchased a Arduino Mega and I'm having the same serial problems PLUS problems using a LCD Display. I'm using V18 of the Arduino software on OpenSuse 11.2 my cross-avr-gcc44 version is 4.4.2_20100111-14.1-i586. All the liquidCrystal examples do not work e.g. HelloWorld. The Mega seems to hang, inserting code for a blinking l.e.d. 13 does not blink the on board l.e.d. but run just the blink code and the l.e.d. blinks just fine. I connected the LCD to a Duemilanove and still no luck. However if I use windows XP with V18 of the arduino software everything works fine! I understand I can downgrade my gcc44 but I thought I would add my experience with the LCD library.

australopitecus

Hi.
I´ve the same problem. Serial alone works. 1, 2, 3 don´t.
So if you´ve any ideas...

Curtman

I was also having this problem with gcc 4.4.3 in Linux..  Downgrading to 4.3.4 fixed it for me..

Before I tried that I found that I could comment out all but one Serial port declaration at the bottom of arduino-0018/hardware/arduino/cores/arduino/HardwareSerial.cpp, and that port would work.  It didn't matter which port, but only one could be uncommented.

Eg:
Code: [Select]
#if defined(__AVR_ATmega8__)
HardwareSerial Serial(&rx_buffer, &UBRRH, &UBRRL, &UCSRA, &UCSRB, &UDR, RXEN, TXEN, RXCIE, UDRE, U2X);
#else
// HardwareSerial Serial(&rx_buffer, &UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UDR0, RXEN0, TXEN0, RXCIE0, UDRE0, U2X0);
#endif


#if defined(__AVR_ATmega1280__)
// HardwareSerial Serial1(&rx_buffer1, &UBRR1H, &UBRR1L, &UCSR1A, &UCSR1B, &UDR1, RXEN1, TXEN1, RXCIE1, UDRE1, U2X1);
//HardwareSerial Serial2(&rx_buffer2, &UBRR2H, &UBRR2L, &UCSR2A, &UCSR2B, &UDR2, RXEN2, TXEN2, RXCIE2, UDRE2, U2X2);
HardwareSerial Serial3(&rx_buffer3, &UBRR3H, &UBRR3L, &UCSR3A, &UCSR3B, &UDR3, RXEN3, TXEN3, RXCIE3, UDRE3, U2X3);
#endif


This would allow Serial3 to function.

australopitecus

Ok. Perhaps there´s a problem with the preprocessor-commands?
Because if there´s only one condition after the #if- or #else-command, it seems to work.
But there are arduinos where the serial communication works with all 4 ports. So that can´t be the solution.

stephanschulz

#28
Apr 20, 2010, 10:53 pm Last Edit: Apr 21, 2010, 03:16 pm by stephanschulz Reason: 1
i just got my arduino mega today.

my os is osx 10.5.8
i am using arudino 18

i am trying to get newsoftware serial and/or serial1, serial2, serial3 to work.

but i am getting mixed results.
TX works but RX gives me nothing back.
can someone tell me if they extra serial ports work for them on osx ?

thanks,
stephan.

update:
i did some more tests. just using the regular hardware serial and softserial.
i ran the same code on an arduino duemilanove and it transmits and receives just fine.
i am connecting the softserial (and hopefully serial1) to a TTL to rs485 shifter, which sends and receives 8byte arrays from a trinamic motor controller.

i tried commenting out the lines in hardwareSerial.cpp suggested earlier. but no change.

thx.

stephanschulz

#29
Apr 22, 2010, 03:13 pm Last Edit: Apr 22, 2010, 03:14 pm by stephanschulz Reason: 1
here is some code that tries software serial and hardware Serial1.

this code works great for software serial on a duemilanove but not a mega.

this code sends a 9 byte command to a motor controller via RS485 chip and wants to receive a 9 byte command back from the motor controller. But never receives anything with the Mega.

Code: [Select]
byte MotorSerInStr[32];


#define rxPin 2
#define txPin 3
#include <SoftwareSerial.h>
SoftwareSerial SoftSerial =  SoftwareSerial(rxPin, txPin);


int dirPin = 12;
int module = 1; //module# of motor board, check motor board for number

byte command[9];
byte checksum;

int sensorTimer = 0;
int receiveTimer =0;
int newSpeed = 1;

void setup() {
 pinMode(rxPin, INPUT);
 pinMode(txPin, OUTPUT);

 Serial.begin(9600);
// Serial1.begin(9600);
 SoftSerial.begin(9600);
}

void loop() {
 if(millis()-sensorTimer > 200){
   sensorTimer = millis();
   cmd_setTargetSteps(newSpeed*200);
   send_cmd();
 }


 if(millis() - receiveTimer > 1000){

   receiveTimer = millis();

   cmd_getPosition();
   send_cmd();
   
 // readMotorCommand();  //hardware serial
    readMotorCommand2(); //software serial
 }


 if (Serial.available()) {
   newSpeed = Serial.read();
 }
 
}

//send 8bit command to spinmaster
void send_cmd(){

 checksum = 0;
 for(int i=0; i<8; i++){
   checksum = checksum + command[i];
 }
 command[8]=checksum;

 digitalWrite(dirPin, 1); //direction pin of RS485 chip
 for(int i=0; i<9; i++){
  //Serial1.print(command[i],BYTE);
   SoftSerial.print(command[i],BYTE);
 }
 digitalWrite(dirPin, 0);

}

void readMotorCommand() //hardware serial1
{
 
 Serial.println("readMotorCommand");
 byte str[9];
 digitalWrite(dirPin, 0);  

 if(Serial1.available() ){

  int b = Serial1.read();

   str[0] = b;
   Serial.print(str[0],BYTE);

   for(int i=1; i<9; i++){ //
     str[i] = Serial1.read();       // fill it up
     Serial.print(" + ");
     Serial.print(str[i],BYTE); //echo back to ipod
   }
 }
 Serial.println("---");
 
}

void readMotorCommand2() //software serial
{
 Serial.println("readMotorCommand");
  byte str[9];
 digitalWrite(dirPin, 0);


int b = SoftSerial.read();

 str[0] = b;
 Serial.print(str[0],DEC); //,BYTE);

 for(int i=1; i<9; i++){ //
   str[i] = SoftSerial.read();       // fill it up
   Serial.print(str[i],DEC); //,BYTE); //echo back to ipod
 }

 Serial.println("---");
}




int cmd_setTargetSteps(int temp_value){
 command[0] = module; //module address
 command[1] = 65; // instruction #
 command[2] = 0; // type, changes depending on command
 command[3] = 0; //or 1 motor/bank/axis #
 command[4] = 0; //(temp_value >> 24) & 0xFF; // byte 3
 command[5] = 0; //(temp_value >> 16) & 0xFF; // byte 2
 command[6] = (temp_value >> 8) & 0xFF; // byte 1
 command[7] = temp_value & 0xFF; // byte 0
}

void cmd_getPosition(){
 Serial.println("--cmd_getPosition--"); //<<endl;
 command[0] = module; //module address
 command[1] = 6; // instruction #
 command[2] = 1; // type, changes depending on command
 command[3] = 0; //or 1 motor/bank/axis #
 command[4] = 0; //(temp_value >> 24) & 0xFF; // byte 3
 command[5] = 0; //(temp_value >> 16) & 0xFF; // byte 2
 command[6] = 0; // byte 1
 command[7] = 0; // byte 0
}


Go Up