Sending a Control Break using SoftwareSerial

At power up, I want to send a Control Break sequence so the receiver I am talking to will respond with it’s settings at 9600. If I declare pin 8 as the software serial TX pin but I have not used .begin yet, can I still use pin 8 for digital control until I issue the .begin?

#include <SoftwareSerial.h>
SoftwareSerial mySerial2(9, 8); // RX, TX

int cnt = 0;
int resp = 0;
String ggain;

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

  pinMode(8, OUTPUT);
  digitalWrite(8, HIGH);   // 
  delay(1000);
  digitalWrite(8, LOW);    // send Ctrl Break
  delay(500); 
  digitalWrite(8, HIGH);   // 
  mySerial2.begin(9600);
  mySerial2.listen();
  while(!mySerial2.available());
  ggain = mySerial2.readStringUntil('\n');
  Serial.println(ggain);
  
  mySerial2.begin(38400);
  
}

I don't know, you tell us, did it work?

Should be fine though.

Oops sorry, no the code above did not work…

This did :slight_smile:

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

  digitalWrite(8, HIGH);   // 
  delay(1000);
  digitalWrite(8, LOW);    // send Ctrl Break
  //PRODUCT,BD970;PORT,1,38400,38400,8,1,N,F;PORTSTATUS,ADJ;VERSION,4.22,2/9/11,,;COMM,DCOL,NMEA;SERIAL,1126400030;ETHIP,0.0.0.0
  mySerial2.begin(9600);
  mySerial2.listen();
  while(!mySerial2.available());
  mySerial2.setTimeout(500);
  
  ggain = mySerial2.readStringUntil('\n');
  for (int p = 0; p < ggain.length();p++){
    if (ggain.startsWith("PRODUCT,")){
        Serial.println(ggain);
        break;
    }
    else{
      ggain.remove(0,1);//drop a character at start of string
    }
    
  }
  //Serial.println(ggain);
  mySerial2.begin(38400);
  Serial.println("done");

Ctrl Break may mean something somewhere, but there is no such thing as Ctrl Break on the wire. The code that I see sends a Break on the wire.