2015-12-08 03:11 AM
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¤tviews=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.From the description of RTS functionality it seems like it works the way it should for RS485. What do you think? null2015-12-08 03:25 AM
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.2015-12-08 03:53 AM
Yes, most of the rs232->rs485 adapters use this:
Thats why I was wondering either it would work for STM32 as well.2015-12-08 05:05 AM
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.2015-12-08 10:43 AM
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 Peacock2015-12-08 11:53 AM
Thank you for information. To bad RTS cant be used, i will trigger DE manually.
2015-12-08 12:36 PM
FYI
http://www.st.com/web/en/resource/technical/document/application_note/CD00249778.pdf2015-12-09 12:01 AM
Yes, I have seen this document. I used a simmilar solution. Thank you.