Serial1 doesn't restart

Hi,

As part of our serial protocol, we need to send this pulse from time to time:

...
      Serial1.end();
      pinMode(18, OUTPUT);
      digitalWrite(18, LOW);
      delay(500);
      digitalWrite(18, HIGH);
      delay(500);
      Serial1.begin(9600);
...

(Sending a pulse over the Tx1 pin)

It seems like that with the Due (It worked great with the Mega), once we call Serial1.begin again - it doesn't reset the TX1 pin status and we can no longer send anything over the serial1 port (receiving data still works).

I tried lowering the pin to LOW before calling Serial1.begin, and also changing the pinMode to different states (INPUT, INPUT_PULLUP) - but still can't send data over the serial lines.

Once I reset the board - we get back full serial functionality.

Any help will be greatly appreciated!

Whenever you want the PIO takes control of TX1 (PA11) instead of the peripheral (USART0 for Serial1), write this line :

//Enable the PIO to control the corresponding pin 
//(disables peripheral control of the pin). Sam3x datasheet, page 633

PIOA->PIO_PER |= PIO_PER_P11;

Whenever you want the peripheral takes control of TX1:

//Disables the PIO from controlling the corresponding pin (enables peripheral control of the pin).
PIOA->PIO_PDR |= PIO_PDR_P11;
//Assigns the I/O line to the Peripheral A function
PIOA->PIO_ABSR &= ~PIO_ABSR_P11;  //TX1 = TXD0=PA11 peripheral type A

Brilliant! Thank you so much.

To be sure, is this right for the rest of the UARTs:

  // Serial1 - TXD0, PA11, PIOA, Peripheral A
  PIOA->PIO_PDR |= PIO_PDR_P11;
  PIOA->PIO_ABSR &= ~PIO_ABSR_P11;

  // Serial2 - TXD1, PA13, PIOA, Peripheral A
  PIOA->PIO_PDR |= PIO_PDR_P13;
  PIOA->PIO_ABSR &= ~PIO_ABSR_P13;

  // Serial3 - TXD3, PD4, PIOD, Peripheral B
  PIOD->PIO_PDR |= PIO_PDR_P4;
  PIOD->PIO_ABSR |= PIO_ABSR_P4;

  // Serial4 - TXD2, PB20, PIOB, Peripheral A
  PIOB->PIO_PDR |= PIO_PDR_P20;
  PIOB->PIO_ABSR &= ~PIO_ABSR_P20;

Thanks again!

That's OK.

To be sure, it's OK for Serial4 too provided you have added the necessary lines of code to declare Serial4.

Of course.

Thanks!

Whenever you want the PIO takes control of TX1 (PA11) instead of the peripheral (USART0 for Serial1), write this line :
Whenever you want the peripheral takes control of TX1:

Shouldn't Serial.begin() and Serial.end() be doing those for you?