Mega + GE 863 Quad, Serial data corrupt

I've got a Mega and a GSM Playground (GE863 Quad) from HWKitchen. I've bent out the GSM shield serial pins and instead moved them to Serial1 such that it doesn't interfere with uploading to the Mega.

The problem I am having is that the serial data is unreliable. If I connect directly to the GSM module and connect to the serial port, the returned data from commands such as 'AT' are fine, all rx perfectly.

When using the Mega, the GSM module connected to Serial1, the characters seem to get corrupted because the module is unpredictable and when I read them from Serial1 and print them to Serial0 I can see the responses are corrupt. I've also increased the hardware serial buffer to 256 bytes, no real reason, but I'm lost for ideas.

What is the reason for this? Thanks for any advice you can give.

// str - the string to send to the serial port
// charDelay - the delay between sending each character
// rxDelay - the delay after sending the command, allows for data to be received
void sendCommand(char* str, int charDelay, int rxDelay){
  Serial.print("Sending:");
  Serial.println(str);

  for (int i = 0; str[i] != '\0'; i++){
    Serial1.print(str[i]);
    delay(charDelay);
  }
  delay(charDelay);
  Serial1.print("\r\n");
  delay(rxDelay);
}

void setup(){
  delay(2000);
  // initialization of serial line
  Serial.begin(115200);
  Serial.println("Serial0 online");
  Serial1.begin(115200);

  // turn on GSM module
  digitalWrite(GSM_ON, HIGH);
  delay(1200);
  digitalWrite(GSM_ON, LOW);
  delay(1200);

  Serial1.flush();
  Serial.flush();

  // Set speed of the serial interface
  sendCommand("AT+IPR=115200",10,30);
  // set serial interface to auto detect connection settings
  sendCommand("AT+ICF=0,0",10,30);
  // disable echo
  sendCommand("ATE0",10,300);
  // send some AT's to let the module sync the connection settings
  for (int i = 0; i < 5; i++){
     sendCommand("AT",10,30);
  }

  // Reset both serial buffers
  Serial1.flush();
  Serial.flush();
  delay(1000);
  int cmdDelay = 300;
  int charDelay = 5;
  sendCommand("AT",charDelay,cmdDelay);
  sendCommand("AT",charDelay,cmdDelay);
  sendCommand("AT",charDelay,cmdDelay);
  sendCommand("AT",charDelay,cmdDelay);
  sendCommand("AT",charDelay,cmdDelay);
  sendCommand("AT",charDelay,cmdDelay);

// Expect 6 x OK's to be RX'd , hardware serial buffer is 256bytes
  while (Serial1.available()){
    char c = (char)Serial1.read();
    Serial.print(c);
    if (c == '\0'){
      Serial.println();
      break;
    }
  }
}

void loop(){
}

Output from serial (this is quite a good run, OK was actually RX'd a few times!):

Serial0 online

Sending:AT+IPR=115200

Sending:AT+ICF=0,0

Sending:ATE0

Sending:AT

Sending:AT

Sending:AT

Sending:AT

Sending:AT

Sending:AT

Sending:AT

Sending:AT

Sending:AT

Sending:AT

Sending:AT



OK




K








OK



OK



OK

Incase anyone is interested, I've reduced the serial speed to 38400, a 5ms delay between sending each character to the ge863 and a 300ms delay between successive commands.

So far this seems to give a more reliable result although every so often a response from the GE863 goes missing.

FWIW, I didn't have any problems interfacing the GE863 to a small PIC, using assembly language. I used 38,400 baud and didn't need any delays apart from the ones in the manual.

I've had a certain amount of trouble with serial communications on the GSM Playground shield, and I think it's due to the effect of the 1K resistors that connect the FTDI chip to the AVR chip. They act as pull-up resistors on the serial data lines, when the FTDI chip is not being used to re-program the Arduino. If you've moved the serial in/out to other pins on the Mega, then the pull-up effect will not be present. I've had comms trouble when running in a similar setup with an Arduino-like board with an external FTDI chip.

And speaking of the GSM Playground, has anyone made an SMS receiving/sending sketch? If so, was it reliable, or did it occasionally need to be reset?

http://code.google.com/p/arduino/issues/detail?id=131

may be the issue.

I'm using the GSM Playgound with an Duemilanove and have also come across the data corruption issue :frowning:

From what I can determine, it only occurs when the GE863 sends large (>40 chars) responses at high speed.. the Duemilanove serial port gets out of step with the GE863 and hence corruption.
Note that there is NO hardware flow control mechanism between the GE863 and the Duemilanove/Mega/Uno (only TX/RX is connected :o) and as far as I can tell, the bog standard serial software doesn't provide xon/xoff either!

In the end.. I had to communicate at 9600 baud for a reliable error free link.

Anyone else had any luck at faster speeds?