cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 RS485 and RTS pin

Posted on December 08, 2015 at 12:11

Hello there,

I need to implement rs485 communication using STM32F407. I am using MAX487 chip which has a direction pin. I have searched the forums for a hardware solution to this, and found a topic which says that it is not possible:

/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https%3a//my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/HowTo%20UART%20with%20RS485%20direction-signal&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=462

But on the other hand, I was wondering isnt it possible to use USART with RTS pin enabled and use that RTS pin as direction control? In that way i would not need to wait for interrupts to manually toggle DE pin.

0690X00000605K1QAI.png

From the description of RTS functionality it seems like it works the way it should for RS485. What do you think?

null
7 REPLIES 7
AvaTar
Lead
Posted on December 08, 2015 at 12:25

If I remember correctly, some commercial half-duplex RS232-RS485  converters use this method for directional control.

Can't remember any specific one, and they are probably not STM32 based, though.

Posted on December 08, 2015 at 12:53

Yes, most of the rs232->rs485 adapters use this:

https://images.duckduckgo.com/iu/?u=http://aquaticus.info/sites/default/files/styles/adaptive/public/more_images/RS485%2520to%2520RS232%2520Converter%2520Schematic.png&f=1

Thats why I was wondering either it would work for STM32 as well.

Posted on December 08, 2015 at 14:05

I have just tested the functionality. I think there is some kind of a bug in HAL library or I am doing something wrong- I am using cubeMX to generate the code. For configured usarts i can use functions HAL_UART_GetState and HAL_UART_Transmit_DMA. I cannot use however HAL_USART_GetState and HAL_USART_Transmit_DMA, even though I am including file ''stm32f4xx_hal_uart.h''. It says that there is undefined refference to those functions. If I use UART functions instead of USART, RTS pin is not toggled. 

I would apreciate all help here.

Ps: I also noticed that there are no cubeMX examples for usart, only for uart.
jpeacock
Associate II
Posted on December 08, 2015 at 19:43

Using RTS in flow control mode to switch DE (TX enable on transceiver) won't work.  DE has to be asserted for the entire length of the outgoing message (I assume you have a half duplex bus), before first bit is shifted out until after last bit is shifted out.  And no other transmitter can be enabled at the same time.

You will have to disable RE* to make sure no data arrives while sending, but the difficulty is in receiving a message from a remote node.  RTS asserts when you read the data register and clear RXNE, that's the pulse at the end of a frame in your diagram.  That pulse enables the transmitter, sending whatever the state of the TxD pin is at (usually a SPACE).

But what happens is after reading the first byte you turn on the transmitter while the second byte is arriving, jamming the bus with multiple transmitters.  Your incoming data is unreliable.

Yes the RTS pin is used by RS-232 to RS-485 half duplex adapters, but the requirement is RTS is asserted for the entire transmit message, not pulsed for flow control.  That's how the original half duplex Bell 201 modem worked (the reason the RTS/CTS pins are on the RS-232 connector).  Many UARTs have a different RTS mode to support half duplex transceivers like RS-485 or infrared.

  Jack Peacock
Posted on December 08, 2015 at 20:53

Thank you for information. To bad RTS cant be used, i will trigger DE manually.

stm32forum
Associate II
Posted on December 09, 2015 at 09:01

Yes, I have seen this document. I used a simmilar solution. Thank you.