Sync Break on Serial Line - Due

Hi Everyone,

I need to transmit a synchronization pulse on Serial1 and Serial2 of Arduino Due. I have had no issues in the past when I used the following code in a library I created, however right now, it is not functioning.

(Here I include all the code in one spot)

unsigned long t1,t2;
///////////////////////////////////////////////////////////////////////////////////////////////
void setup()
{
  Serial1.begin(9600);
  Serial2.begin(9600);

  t1 = millis();
  t2 = t1;
}
///////////////////////////////////////////////////////////////////////////////////////////////
void loop()
{
  t1 = millis();

  if(((t1-t2) >= 500) || (t2>t1))
  {
    TxSyncBreakDue(1,104);
    Serial1.write(0x12);
    Serial1.write(0x23);
    t2 = t1;
  }
}
///////////////////////////////////////////////////////////////////////////////////////////////
int TxSyncBreakDue(int SerCh,unsigned long Period_us)
{

  unsigned int del = Period_us * 13; // delay for number of bits in microseconds, depends on period

  if(SerCh == 2)
  {
    PIOA->PIO_PER = PIO_PA13; // enable PIO register
    PIOA->PIO_OER = PIO_PA13; // enable PA13 as output
    PIOA->PIO_CODR = PIO_PA13; // clear PA13
    delayMicroseconds(del); // delay
    PIOA->PIO_SODR = PIO_PA13; // set pin high
    delayMicroseconds(Period_us);
    PIOA->PIO_PDR = PIO_PA13; // clear configuration for PIO, needs to be done because Serial wont work with it
  }
  else if(SerCh == 1)
  {
    PIOA->PIO_PER = PIO_PA11; // enable PIO register
    PIOA->PIO_OER = PIO_PA11; // enable PA11 as output
    PIOA->PIO_CODR = PIO_PA11; // clear PA11
    delayMicroseconds(del); // delay
    PIOA->PIO_SODR = PIO_PA11; // set pin high
    delayMicroseconds(Period_us);
    PIOA->PIO_PDR = PIO_PA11; // clear configuration for PIO, needs to be done because Serial wont work with it
  }
  else
  {
    return -1;
  }

  return SerCh;

}

Does anyone have any idea what settings I may have accidentally changed that would cause this?

I search the Due files in C:users\xxxxxxx\Arduino15\packages\arduino\hardware for any files that were modified in the past few days, and it nothing appears to have been modified.

Yesterday, I tried viewing some of the Timer-Counter registers, however I highly doubt that a mere read of the registers would set some setting preventing me from transmitting my Sync Pulse.

Thanks!

Are you using exactly the same Arduino board as the last time it worked properly?

Paul

Hi Paul,

Yes, hardware setup is exactly the same.

Thank You!

For reference, I am copying what you see at line 255 here:

Hi Everyone,

Problem Solved!

Turns out, a function that I was using to call

int TxSyncBreakDue(int SerCh,unsigned long Period_us)

Was feeding the 2nd argument a zero for the delay time.

When I manually trigger the function, all seems to work correctly.

My apologies wasting anyone's time.

No apologies needed. In the real world when people are stumped by something, it ALWAYS works best to tell them the narrative relating to your problem and answer their questions. Was introduced to this by an ex-Boeing employee. They even did this when there was no problem, just be sure all bases were covered.

Paul