0

I'm using python on a Raspberry Pi to test an external device.

The external device requires that the UART Tx line be low during initialization. To accomplish this I configure the UART Tx line as a GPIO output during initialization:

GPIO.setup(14, GPIO.OUT)  
GPIO.output(14, GPIO.LOW)

At a later time, I configure the UART:

serial.Serial(port="/dev/serial0", baudrate=115200)

However, once the port has been configured as a GPIO, the UART does not work (no characters are transmitted) unless the Raspberry Pi is rebooted.
The UART works fine when the GPIO is NOT configured.
Adding GPIO.cleanup() has no effect.
Is there a way to programatically undo the GPIO configuration?

  • You're probably going at this incorrectly (i.e. mucking with pin control after RPi system initialization). If you need the TxD line to be "low during initialization" of the external device, then outputting space instead of mark would accomplish that. I.E. send a BREAK condition – sawdust Jun 6 '17 at 23:27
  • You better be sure that this external device is referring to TTL levels rather than RS-232 levels when you claim that "the external device requires that the UART Tx line be low during initialization'. – sawdust Jun 6 '17 at 23:38
1

You need to put the GPIO back into UART mode, which happens to be mode ALT0 for GPIO 14 and 15.

The pigpio Python module uses the set_mode function to set the mode, e.g. set_mode(14, pigpio.ALT0).

The pigpio pigs module uses the mode command, e.g. pigs m 14 0.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy