Possible to repurpose a UART pin?

Not sure if this is software or hardware.

I’m using a MaxBotix EV4 to measure distance, and it has a very simple three pin system of +ve, GND and Tx. I’ve configured the Imp to use Uart12 connecting Pin2 (Rx) to the Maxbotix Tx (actually, there an inverter in between). However, I’m desperate for I/O pins and wondered if I could also configure Pin1 as a DIGITAL_IN as I have no need to Tx to anything. Is it possible to only use half a UART ?

Yes… I think you can do that with most of the configurable sets… I do it with uart57, and the SPI busses.

I believe I have configured uart57 first, and then 7 as DIGITAL_OUT… maybe we could get confirmation if there is a preferred method.

You can either configure the whole UART, then reconfigure something over the top of it (as jwehr suggests), or you can configure just half-a-UART in the first place: http://electricimp.com/docs/api/hardware/uart/configure/ (NO_TX or NO_RX flags). Both ways are perfectly valid, but I suppose the second makes your code a bit clearer.

Peter

I’ve also wondered about reconfiguring pins during program execution…back and forth. I haven’t needed to do that yet, and I suppose it would be on a case by case basis, but the Imp wouldn’t have any issues with say, flipping back and forth between spi257, and uart57 would it?

No, that should work too.

Peter, thanks for reference. I like the idea of specifying NO_TX following by another configure () on Pin2 for DIGITAL_IN which as you suggested, will make the code clearer. Thanks to all. Will have a go over the weekend.

The result. It Works.

`DistanceSensor <- hardware.uart12; // Only need RX (Pin2)
MatrixDisplay <- hardware.uart57;
DoorController <- hardware.pin1;

DistanceSensor.configure (9600,8,PARITY_NONE,1,NO_TX,DistanceSensorEvent);
MatrixDisplay.configure (115200,8,PARITY_NONE,1,NO_CTSRTS);
DoorController.configure (DIGITAL_OUT);`