Bi-directional uart - Page 1
Forum section: electronics / beginners

author: piam
author_rank: Newbie
timestamp: January 09, 2020, 11:08:12 am
content: Hi,I have a circuit that I'm trying to implement that is quite old and uses RS232 to communicate bi-directionally over a single pin to an MCU.Here's the circuit:I'd rather not use RS232 and just want to communicate using a rasperry Pi or similar with PTA0, but it both receives and transmits over a single pin. Can someone suggest how I might do this natively on a pi, either by driving a GPIO bi-directionally and doing this in software, or using the native UART and somehow tieing rx and tx together, perhaps with some other chip?

author: Berni
author_rank: Super Contributor
timestamp: January 09, 2020, 11:25:21 am
content: And why not just connect pins 16 and 15 of that MC145407 to the RX and TX pins of a raspberry UART port?

author: piam
author_rank: Newbie
timestamp: January 09, 2020, 11:28:11 am
content: I don't have the MC145407 or MC74HC125 and was hoping to avoid it if I didn't need them.

author: Berni
author_rank: Super Contributor
timestamp: January 09, 2020, 11:40:06 am
content: In that case why not just buy a off the shelf USB to RS232 dongle and use it with a DB9 do DB25 serial adapter.

author: mvs
author_rank: Frequent Contributor
timestamp: January 09, 2020, 11:50:49 am
content: Quote from: piam on January 09, 2020, 11:28:11 amYou do not need RS232 driver (MC145407), but perhaps 3.3v <-> 5v level shifter (RPi has 3.3v IO levels).74hc125 is just cheap Tri-state buffer. You may replace it with a small signal diode (cathode to RPi TX, anode to RPi RX and PTA0 + Pullup R).

author: piam
author_rank: Newbie
timestamp: January 09, 2020, 11:53:48 am
content: I do have a USB to RS232 dongle, but it feels really ugly going from USB to RS232 to TTL to this single pin interface via two chips that I don't (yet) have and that seem superfluous. I was thinking of usinghttp://abyz.me.uk/rpi/pigpio/cif.htmlto do this UART in software. I do have those two chips on order and should get them in a few days. Would be good not to have to use them though.I don't actually need 5v anywhere, that's just because of the RS232.

author: piam
author_rank: Newbie
timestamp: January 09, 2020, 12:00:44 pm
content: Quote from: mvs on January 09, 2020, 11:50:49 amCool, that sounds like a plan. Thanks.

author: Berni
author_rank: Super Contributor
timestamp: January 09, 2020, 12:05:58 pm
content: Ah you want to go the other direction.In that case just use the same 74HC125 circuit and instead of connecting it to the MC145407 you connect it to the TX and RX pin on a raspberry.You can try bitbanging UART but you will have a world of trouble getting it to work at anything higher but the slow snails pace baudrates. Id say paying for a 10 cent 74 series quad buffer IC is cheaper than investing days of work to do it with direct connection to the Raspberry IO pin.

author: piam
author_rank: Newbie
timestamp: January 09, 2020, 01:49:45 pm
content: Quote from: Berni on January 09, 2020, 12:05:58 pmAt the moment, because of the crystal I have (ordered some more), it'll be 13240 baud... I'm not sure of the status of my orders, but if I don't get the stuff I want by tomorrow, I might try the software mechanism in the interim.

author: piam
author_rank: Newbie
timestamp: January 10, 2020, 02:54:02 pm
content: Quote from: mvs on January 09, 2020, 11:50:49 amThis is exactly what I did (I think!). For every byte I write I get it echoed back and then I get the data I'm expecting. I have some anomalies with failed reads after a while but I can just work around those by repeating the command I'm sending.Thanks