Pin multiplexing

Hi,

I have a microcontroller with 2 pins for usart rx/tx. I can also set these pins as GPIO.

I want to be able to use both functionalities, but obviously not at the time. When my chip boots up, I want to be able to communicate with the usart, but then after, I want to turn those back to GPIO to drive some LEDS.

From a software point of view, this is really easy. But from a hardware point of view, I’m a little challenged.

If I hook up an LED from the rx pin GND, then the rx pin will be driven low at all time. So my circuit will make the usart impossible to use. I don’t mind the LEDs being turned on or off when the usart is in use, but I want to make sure that the LEDs circuit will not affect the usart.

The only way I can think of getting around that is with a complicated set of transistors and additional GPIO. Is there an “easy” way to do this?

I hope I’m explaining this right.

+-----+                                +-----+                                        
|     |                                |     |                                            
|   tx|--------------------+-----------|rx   |                                            
|     |                    |           |     |                                            
|   rx|------+-------------------------|tx   |                                      
|     |      |             |           |     |                                      
+-----+      +--|>--(GND)  +--|>--GND  +-----+

You will need something complicated in between I’m afraid. The usart is idle high on both RX and TX and data pulses are only of a limited duration in the low state. At the most 9 serial bits (start+8 data bits) long. So if there was a circuit or device that takes the RX or TX as input and times how long the RX and TX are low then it could activate some other device/circuit when a certain duration is passed. Every transition to high of RX/TX the timer would need to reset itself. I don’t know how to do this, but I wouldn’t be surprised if someone invented a low-pulse timer solution involving a 555 timer.

That still only gives you a toggle signal though. An indicator when the LEDstrip needs to change state. A pulse/frequency divider would be needed to turn this into a on/of state. And with that amount of hardware you might consider adding a small (8 pin) microcontroller instead to do the same.

Another solution I have been thinking about for my self, but haven’t found the time to try it in practice yet is to sense the current through the wire between TX, and RX (of the opposite UART). TX is normally an actively set output or pulled up with a resistor to Vcc, thus able to supply some current if it is high. And RX is an input (floating to the whims of TX and any noise on the line) so no significant current should flow towards RX, as it is a very high resistance input. If you put a resistor in the wire between TX and RX then you would get a voltage drop across a resistor when RX is changed to a GPIO and outputting a low (since current will be rushing into it). Using a comparator you could sense the direction of current through this resistor because of the voltage drop. Or the mid-level of the voltagedivider that the in-series resistor created with the pull-up resistor. But this can only work when TX is not actively outputting a low. So it may not work all the time or flicker if the other UART decides to send something. And each device that sets the RX to output low can only activate one led-strip. So they would have to work in unison to operate them.

The resistor could have limiting effects on the baudrate though.

pdumais:

If I hook up an LED from the rx pin GND, then the rx pin will be driven low at all time. So my circuit will make the usart impossible to use. I don’t mind the LEDs being turned on or off when the usart is in use, but I want to make sure that the LEDs circuit will not affect the usart.

Here is me thinking complicated again. It’s much simpler. Flip those LEDs around and tie those LEDs to Vcc with their anode instead. When both sides of the led are at a high level, or equal to Vcc (either because of TX output high, or resistor pulling up) then there is no voltages difference to light them up. If anything they will be close to being reverse biased. When however TX goes low to send a bit then there is a path from Vcc through the LED (and a resistor!) to TX which is at GND. So they light up. And RX should follow TX to low anyway so the UART function is preserved. Capisce? That is basically how TX- and RX-traffic leds work. The current limiting resistor of the led should be high enough so the current rushing into TX isn’t burning up the port.

Inserting a resistor in the wire would prevent a short circuit if at any time both TX and RX are set as output but opposite levels. You didn’t state which side should operate the leds so if both try to output to different levels you can get hot and smelly UARTS.

Thanks for all the info. I’ve been digesting that…

I’m not sure what I’m gonna do yet. But thanks.