cancel
Showing results for 
Search instead for 
Did you mean: 

Problem using RS485 on STM32F030R8T6

gaetanbusson
Associate II
Posted on October 02, 2014 at 17:27

Hello,

I am trying to initiate a RS485 communication with the STM32F0308DISCOVERY kit. My code is based on the ''UART_TwoBoards_ComIT'' example that I found in the STM32Cube repository (\STM32Cube\Repository\STM32Cube_FW_F0_V1.0.0\Projects\STM32F072B-Discovery\Examples\UART\UART_TwoBoards_ComIT). In this code, I added the following block after UART initialization block to use the DE pin (PA12):

1.
if
(HAL_RS485Ex_Init(&UartHandle, UART_DE_POLARITY_LOW, 0, 0) != HAL_OK)
2.
{
3.
Error_Handler();
4.
}

I didn’t connected the STM32F0308DISCOVERY kit to another STM32F0308DISCOVERY kit but I connected it to a computer through a RS485 transceiver and then to a RS485 to USB adapter. On the computer, I have a terminal that is supposed to send an echo. When I press the ''USER'' button, The terminal displays “****UART_TwoBoards_ComIT**** ****UART_TwoBoards_ComIT****�? and send back it to the STM32F0308DISCOVERY kit. This echo is never received by the MCU because the program is stuck at the following line:

1.
/*##-5- Wait for the end of the transfer ###################################*/
2.
while
(UartReady != SET)
3.
{
4.
}

When I put a scope on the PA12 pin, the line is still high but it should be low to make the RS485 transceiver connect the RS485 line to the RX pin of the MCU. I thought that the DE line was automatically toggled when using the “HAL_UART_Transmit_IT�? or the “HAL_UART_Receive_IT�? function. Is it true? Am I supposed to use another function to toggle this pin before reading or writing? #rs485-uart-stm32f030-discovery
5 REPLIES 5
frankmeyer9
Associate II
Posted on October 06, 2014 at 14:07

My code is based on the ''UART_TwoBoards_ComIT'' example that I found in the STM32Cube repository (\STM32Cube\Repository\STM32Cube_FW_F0_V1.0.0\...

 

I don't know the Cube code, and I won't touch it.

However, note that RS485 is a multiuser bus (not point-to-point as RS232), and supports only half-duplex operation (except you have a 4-wire configuration). You cannot send and receive at the same time.

gaetanbusson
Associate II
Posted on October 08, 2014 at 09:50

Yes: it's impossible to send and receive at the same time with RS485. That's why there is a DE pin on the ST32F030R8T6 that make my transceiver switch between emission and reception. My problem is that I can’t find any function or structure in the STM32F0 firmware that make this pin toggle. Do you know how can I use this pin?

frankmeyer9
Associate II
Posted on October 08, 2014 at 15:48

I didn't try this on a STM32, so I can't tell from experience.

If there is nothing in the Cube software, you can try to follow the Ref.Manual, which describes the required configuration register settings. Alternatively, the StdPeriphLib definitely has an interface to manage RS485/DE functionality.

BTW, since RTS is used as DE, you need to use an Usart that has associated RTS/CTS pins.

Posted on October 08, 2014 at 17:20

In the Standard Peripheral Library

void USART_DECmd(USART_TypeDef* USARTx, FunctionalState NewState);

void USART_DEPolarityConfig(USART_TypeDef* USARTx, uint32_t USART_DEPolarity);

void USART_SetDEAssertionTime(USART_TypeDef* USARTx, uint32_t USART_DEAssertionTime);

void USART_SetDEDeassertionTime(USART_TypeDef* USARTx, uint32_t USART_DEDeassertionTime);

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on October 09, 2014 at 10:34

Hi Gates,

Concerning the RS485 communication, the only required API is HAL_RS485Ex_Init() which initializes the USART peripheral in the RS485 mode (this API configures the UART parameters, DE Polarity, DE Assertion Time and DE Deassertion Time),  with no need to call the HAL_UART_Init() before.

To use the DE pin,  please follow the same configuration approach for TX and RX pins through the HAL_UART_MspInit() API.

Hope that can help you.

Cheers,

Heisenberg.