Report
1 week, 1 day ago.

Using Serial TX pin as DigitalOutput

Hi, Question, There is a way to use the TX of the serial port as Digital output?, i need to implement a square pulse before the serial command.

Once the TX pin is declared as part of the Serial Port its goes UP , and its no loger driveable.

There is a way to solve this problem?

Thanks in advanced, Ignacio

Comment on this question

2 Answers

1 week, 1 day ago.

So you need to control the pin directly and then switch it over to being a UART pin?

Yes this is doable but not in a cross platform way.

Configure the pin to be a UART as normal, that will let the mbed library configure everything how it wants.

And then directly change the pin Mux and GPIO registers of the processor to set that pin to be GPIO output with the value you want.

Once you're done with your direct control set the registers back to their previous values and the UART will take over again.

The exact details of which registers to change and what values to use will depend on the processor used and the pin you are changing but details will be in the appropriate parts user manual.

Thanks Andy, your reply was very useful

posted by Ignacio Carballeda 10 Oct 2018
1 week ago.

Hello Ignacio,

Another option is to let the UART to generate the pulse by transmitting a specific pattern. But that has some limitations. Since the start bit pulls the UART's output LOW for one UART clock period and the stop bit brings it back to HIGH then by sending for example a 0xF0 over the UART will result in a LOW pulse wich is five UART clock periods long. Then you can start to send your real data over the UART after a five UART clock periods long HIGH pulse. However, the shortest (LOW) pulse which you can generate this way is one UART clock period long (a start bit - by sending a 0x00).
By sending one of the following bytes will generate a pulse at the UART TX pin:

bytepulse length (UART clock periods)
0x001
0x802
0xC03
0xE04
0xF05
0xF86
0xFC7
0xFE8
0xFF9


To post an answer, please log in.