Author Topic: RS-485, half-duplex and STMF4xx  (Read 1053 times)

0 Members and 1 Guest are viewing this topic.

Offline phil from seattleTopic starter

  • Super Contributor
  • ***
  • Posts: 1029
  • Country: us
RS-485, half-duplex and STMF4xx
« on: January 11, 2021, 06:26:00 pm »
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.
 

Offline Alti

  • Frequent Contributor
  • **
  • Posts: 404
  • Country: 00
Re: RS-485, half-duplex and STMF4xx
« Reply #1 on: January 11, 2021, 09:21:43 pm »
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.
You could emulate the DE in software of course but many STM32 have this feature built-in. Like STM32F030, not sure about STM32F4xx family.
 

Offline phil from seattleTopic starter

  • Super Contributor
  • ***
  • Posts: 1029
  • Country: us
Re: RS-485, half-duplex and STMF4xx
« Reply #2 on: January 11, 2021, 10:15:58 pm »
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.

[edit] went back and looked - DE is not on RX so I'll have to do it in SW.
« Last Edit: January 11, 2021, 10:32:04 pm by phil from seattle »
 

Online dmendesf

  • Frequent Contributor
  • **
  • Posts: 320
  • Country: br
Re: RS-485, half-duplex and STMF4xx
« Reply #3 on: January 11, 2021, 11:34:30 pm »
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.
 

Offline Renate

  • Super Contributor
  • ***
  • Posts: 1460
  • Country: us
Re: RS-485, half-duplex and STMF4xx
« Reply #4 on: January 12, 2021, 07:43:59 pm »
So you can drive the 485 only when you want to transmit a 0.
Sorry, 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 and keep the lines in a 1 state.
 

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3387
  • Country: nl
Re: RS-485, half-duplex and STMF4xx
« Reply #5 on: January 13, 2021, 06:55:26 pm »
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".
 

Offline poorchava

  • Super Contributor
  • ***
  • Posts: 1672
  • Country: pl
  • Troll Cave Electronics!
Re: RS-485, half-duplex and STMF4xx
« Reply #6 on: January 13, 2021, 07:34:01 pm »
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.
I love the smell of FR4 in the morning!
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf