How can I Send BREAK Signal to USART ?

Board : Arduino DUE

Serial2 connect some device.
I want to send BREAK signal to Serial2.

Following code make hardware break signal to Serial2.
Working good~!

But,

After Send Break Just One Time,
Serial2 Tx Pin can’t send any data.
So, After Send Break, can’t communicate Serial2 device;

What’s wrong this code ?

void SendBreak(int ms);
char c;

//////////////////////////////////////////////////////////////////////////////////////////
void setup() {
    Serial.begin(9600);
    Serial2.begin(9600);
    
    Serial.println("Ready...");
}

//////////////////////////////////////////////////////////////////////////////////////////
void loop() {
    
    SendBreak(500);                       // Send BREAK Signal to Serial2 .. Wake up Serial2 Device 
    
    for ( int i = 0 ; i < 50 ; i++ ) {    // 5 second waiting.. 
        delay(100);                       // Serial2 device reset, and print banner
        while (Serial2.available()) {     // Company, Device Name, Version, etc.. 
            c = Serial2.read();
            Serial.print(c);
        }         
    }
    
    Serial2.write("C?\r",3);              // Request Device status

    for ( int i = 0 ; i < 50 ; i++ ) {    // not responding in 5 second.
        delay(100);    
        while (Serial2.available()) {
            c = Serial2.read();
            Serial.print(c);
        }         
    }     

}

//////////////////////////////////////////////////////////////////////////////////////////
void SendBreak(int ms)
{
    Serial2.end();             // Release Serial Mode 
    
    pinMode(16, OUTPUT);       // Setup Output mode 
    digitalWrite(16, HIGH);    // Send BREAK Signal
    delay(ms);                 // 500 ms
    digitalWrite(16, LOW);     // Set Idle Status 
    
    Serial2.begin(9600);       // Serial Mode Begin 
}

Solved~!

http://forum.arduino.cc/index.php/topic,46426.0.html

The article is too old and wriing_serial.c file is not exist. But other hack introduced..

"The other hack that I've heard of is to lower the bit rate and send a null. Sending a null (all 0's) at 300bps is a good 30x slower than sending at 9600, and the period for which the line stays zero will be quite long enough to appear as a break... "

void SendBreak()
{
Serial2.end();

Serial2.begin(300); // open 300bps
byte x[150];
memset(x, 0x00, 150);
Serial2.write(x, 150); // 500ms null(0) send => effect Send BREAK
Serial2.end();

Serial2.begin(9600); // reopen 9600bps
}

  • Actually..
    Serial Tx Pin(1, 18, 16, 14) never coma back serial pin After you assign GPIO Pin ( pinMode(16, OUTPUT); )
    I think It's DUE bug..

void setup() {
pinMode(16, OUTPUT); // Serial2 Tx Pin => Digital Output Mode
...
Serial2.begin(9600); // not working.. Serial2 Tx Pin never come back Serial Tx Pin... It remain GPIO pin...
..
}