RS-485, half-duplex and STMF4xx - Page 1
Forum section: electronics / projects

author: phil from seattle
author_rank: Super Contributor
timestamp: January 11, 2021, 06:26:00 pm
content: I am designing a Modbus adapter card that will attach to an existing async port (TX, RX pins only). The RS-485 transceivers all have pins to control direction (for half-duplex operation). The data sheet and appnotes show circuits that route TX and RX separately from a microcontroller to the transceiver with an extra pin (or two) to control direction. While I am prototyping with the MAX485, there are numerous other transceivers available and their datasheets are similar to the MAX485 datasheet.In looking at the STM32F datasheets, the USART has a half-duplex mode that only uses TX and leaves RX available as a GPIO pin. Because the ASYNC port is already defined (and in use on at least one shipping product), it looks like I could use RX as the DE/RE (direction) pin. It requires driver support to know when the transmission is done to make sure the transceiver is in Receive mode but that looks pretty easy.This all makes sense on paper though one result is that the Data In (DI) and Receiver Out (RO) pins are tied together. This seems obvious but I have not seen an example in the datasheets, appnotes or general internet describing that configuration. I will be prototyping it when I get the parts but am hoping for some input/advice ahead of that. I've attached my preliminary circuit. Comments appreciated.

author: Alti
author_rank: Frequent Contributor
timestamp: January 11, 2021, 09:21:43 pm
content: Quote from: phil from seattle on January 11, 2021, 06:26:00 pmYou could emulate the DE in software of course but many STM32 have this feature built-in. Like STM32F030, not sure about STM32F4xx family.

author: phil from seattle
author_rank: Super Contributor
timestamp: January 11, 2021, 10:15:58 pm
content: Thanks. Yes, I saw that DE can be generated. What I didn't see was what pin it goes out on. Since I will be using Half-Duplex, I'd like to avoid using some pin other than the (now unused) RX pin. The async port already is defined for other applications so I would have find a 3rd pin for DE otherwise.DE generation isn't my reason for the post, though. I would like to know if there are any problems/issues with the pin configuration I posted. went back and looked - DE is not on RX so I'll have to do it in SW.

author: dmendesf
author_rank: Frequent Contributor
timestamp: January 11, 2021, 11:34:30 pm
content: There's another way. Notice the RS485 differential bus only has 2 valid states: 0 and 1. When the line is idle it's a 1, so you can drive the 485 only when you want to transmit a 0. Hardwire data input of 485 transceiver to zero and connect TX from microcontroller inverted to both enables. Put pull up/pull down at 485 lines and be happy.

author: Renate
author_rank: Super Contributor
timestamp: January 12, 2021, 07:43:59 pm
content: Quote from: dmendesf on January 11, 2021, 11:34:30 pmSorry, that's a poor idea.The lines can be very capacitive and the whole idea of RS-485 is active driving in both directions.When you're done with a transmission and you've already driven the lines to a 1 state, you can go offline and have the bias resistors do their job andkeepthe lines in a 1 state.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: January 13, 2021, 06:55:26 pm
content: This is a bad idea.You may get it to work on your bench but that does not mean it will also work reliably in the field.Just do it as normal folks do: Use an I/O pin to switch the direction.If you want to continue on this path, then look into CAN transceivers. These normally work with the signals you are trying to make.There's a very good application note out there with the title: "10 ways to bulletproof RS485".

author: poorchava
author_rank: Super Contributor
timestamp: January 13, 2021, 07:34:01 pm
content: I once bought a chaepo RS485 to USB adapter that did just that.It worked with some devices on the bus, but some would refuse to receive anything (that's what got me to take it apart).Not a good idea.