Configures a pin as a UART-transmit-active indicator
Device (from impOS™ 34)
|pin||An imp pin object||
The imp pin to be used to signal the UART TX state
1 for active-high, 0 for active-low
Optional pre-delay in microseconds (default = 2)
Optional post-delay in microseconds (default = 2)
This method configures an imp GPIO pin to indicate when UART transmission is occurring. If the parameter polarity is 1, the indicated pin will be driven high while bytes are being transmitted by the UART, and then driven low again once the UART goes idle; if polarity is 0, the pin will be driven low while bytes are being transmitted by the UART, and driven high when the UART goes idle.
This facility can be used to drive an external RS485 transceiver, for shared-medium (half-duplex) RS485 communications.
A small delay can be added between the pin getting activated (going logic high, for polarity 1) and the UART actually starting to transmit, and/or between the UART going idle and the pin going low again. These delays are synchronous — the imp stops altogether during the delay — so ought to be kept small, for the sake of the responsiveness of the rest of the system. The default delays of two microseconds (2μs), should be enough for use with most RS485 transceivers.
From impOS™ release 34, the value passed into postdelay is checked against a maximum permitted value of 5000μs (5ms). If the specified value is greater than this, the following error if thrown:
"postdelay > 5ms not allowed in uart.settxactive(pin, polarity, predelay, postdelay)".
This functionality is available on all UARTs, except for imp002’s uartB, which has no transmit capability. In the case of the imp005, the value passed into postdelay must be considered as the minimum delay observable on the pin. The actual delay is usually within 40μs of the parameter value.
The uart.settxactive() call includes the equivalent of
pin.configure(DIGITAL_OUT); so there is no need to configure the pin separately. Should you need to disable the TX activity indicator, call
pin.configure(DIGITAL_IN); on your selected pin to tristate it.
The following code shows the use of uart.settxactive() on an imp003:
const PRE_DELAY = 200; const POST_DELAY = 200; local serial = hardware.uartFG; // Configure UART serial.configure(9600, 8, PARITY_NONE, 1, 0); // Set up pinA is the transmission indicator, signalling active-low serial.settxactive(hardware.pinA, 0, PRE_DELAY, POST_DELAY); // Transmit some data serial.write("Hi");
The code above gives rise to the signals shown in the timing diagram below, with pinF in red and pinA in blue.