how to select a serial port in arduino due

Hi,

I have my arduino due connected to an atmega through tx0/rx0. i need to transmit data to the atmega from arduino. my question is:

  1. can i do it using the normal serial.write command?

  2. do i need to select the particular serial port? if yes. how do i do that?

I have been using the following code:

Atmega:

char c;
void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly: 
  if(Serial.available()>0);
  {
    c=Serial.read();   
  }
  if(c=='a')
  {
    digitalWrite(2, HIGH) ;
  }
  else
  {
    digitalWrite(2, LOW);
  }
   
  
}

Arduino due:

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly: 

  Serial.write('a');
}

I am just a novice. Please spare any errors and help me out :?

The due has several hardware serial ports. There is Serial, for communication through the programming USB port. But also 3 additional on specific pairs of GPIO pins. You address them as Serial# where the hash is a number 1,2 or 3. Check halve-way the next link for Due information on the Serial command and it’s ports:

http://arduino.cc/en/Reference/Serial