[SOLVED] how to switch between Hardware serial and digital IO

So I have this function where I am passing the hardware serial object to:

void func(HardwareSerial &refSer)
{
   refSer.print("ref to ser");
}

So far so good.

What I would like to achive now is to Serial.end, use the IOs as digital OUTPUTs and then Serial.begin again.

Reason to do that is that I need to generate a Serial break for a pre-defined period.

my question is:
Is it possible to know the IOs (pins) being used by the Serial object that was passed to the function?

Have a look at the 'Conceptinetics' dmx library, there a break is generated by changing the BAUD rate.

Is it possible to know the IOs (pins) being used by the Serial object that was passed to the function?

Apparently not. At least, not in the AVR or SAM core. It looks like the SAMD code could do it...

Is it possible to know the IOs (pins) being used by the Serial object that was passed to the function?

Which Arduino board are you using ?
Whichever it is then you will know which pins that the Serial object is using so why not pass them to the function explicitly ?

UKHeliBob:
Which Arduino board are you using ?
Whichever it is then you will know which pins that the Serial object is using so why not pass them to the function explicitly ?

Yeah could do that but not so interesting then.... :slight_smile:

Deva_Rishi:
Have a look at the 'Conceptinetics' dmx library, there a break is generated by changing the BAUD rate.

Liked this idea and wrote this up (and it works!):

void func(HardwareSerial &refSer, unsigned long baud, uint8_t  brkbits)
{
unsigned long brk_baud;
       
   //breakfield mode
   brk_baud = 9*(baud/brkbits);
   refSer.end();
   refSer.begin(brk_baud);
   refSer.write(0x00);
   refSer.end();
 
   //normal mode
   refSer.begin(baud);   
   refSer.print("break transmitted!");
}

Yeah could do that but not so interesting then...

But a lot more work, not so easy to understand and possibly not portable