Pages: 1 [2] 3   Go Down
Author Topic: Mega - serial1, 2 und 3 - initialization fails  (Read 5689 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Bavaria Germany
Offline Offline
Full Member
***
Karma: 0
Posts: 121
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
/*
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);
}
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 1
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 21
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 21
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 27
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: April 21, 2010, 08:16:48 am by stephanschulz » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 27
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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
}
« Last Edit: April 22, 2010, 08:14:42 am by stephanschulz » Logged

Pages: 1 [2] 3   Go Up
Jump to: