How to Interface RS485 Module with STM32

preview_player
Показать описание
________________________________________________________________________________________

________________________________________________________________________________________

******* SUPPORT US BY DONATING******

*******Join the Membership*******

Рекомендации по теме
Комментарии
Автор

I have a few tips about RS485 with STM32:
1) use a bias network in addition to the termination resistor. You can look up "RS485 bias".
Even if the RS485 line drivers have a "safe mode" they can still experience glitches on the receiver with the first byte. Especially if you don't share a GND.
So you may miss or corrupt the first byte!
2) STM32 UART RX doesn't have a hardware buffer. Receiving using interrupt is often too slow and you can miss data. Only DMA receiving works properly IMHO.
3) You can use circular DMA for UART if you don't want to lose any data, but for RS485 this is not really needed. In fact it is best to clear any UART buffer after sending in case data ends up in your RX buffer.
4) Note that when a glitch occurs an RX error will automatically halt DMA reception and you have to manually re-enable it. So enable the appropriate error interrupts (UART and/or DMA) and handle the errors appropriately or you may wait forever for data (though that only applies to an RS485 slave).
5) Add short delays between switching Drive Enable and data transmission (before and after transmission). This makes communication more reliable.
6) Enable Idle line detection interrupt. This is very useful in case you don't know how many bytes you are expecting. You receive an interrupt after receiving the last byte of a message.
7) If you want to use very high Baud rates check the datasheet of your line drivers. They come in different speeds/slope limits.
8) With any UART communication always verify your baudrate. With low clock frequencies you may not be able to get the exact baudrates you want due to rounding errors. Internal oscillators also have limited accuracy. It may work until it doesn't...
9) When you want to connect it to the PC use the FT232R USB serial converter. It has a TXen pin that switches while it is sending. You can connect this pin to the RS485 DE pin. The alternative is to use the DTR or RTS pin, but this can switch too slow as Windows is not real time. Cheap USB-RS485 converters often use DTR and are not always reliable. So check the schematic before buying one.

chrisidema
Автор

hello, thanks for a great explaination, but I have a question. Could we connect the RO and DI pin of the MAX485 chip to RX and TX pin of USART2 instead of USART1 (on STM32L152RE)? because I had a project at school, we implemented the MODBUS RTU protocol, at first we used USART2 for debugging purpose, but after that we had to change to USART1 to deal with RS485 to USB converter, and I didn't know the reason why we had to change.

ThinhLe-utpr
Автор

I got random data and I’m not able to establish communication it seems, I’m using 2 stm32f103 and the rs485 transceiver is MAX485

SamSmartLabs
Автор

Hello, i want to interface a SmartEmbedded screen with an toshiba inverter and read out the inverter frequency on the screen by using RS485 wire with Stm32cubeIde, I would like to know if it´s possible ?

YAKITEMiguel
Автор

Hello great video ! i try your code on 2 H7A3 Nucleo, the TX board is working, but Rx board is not! is there any additional setting at IDE configuration that you miss out in the video? i dun understand the RxData[16] appear all 0 at Live Expression !
can you advise...

woldecosgrove
Автор

Hi, STM32 UARTs include RTS/DE pin functionality, but you're driving the DE pin manually, why? Isn't this be controlled automatically by the UART? So, what's the purpose of such DE pin?

xavierr
Автор

The lecture was awesome. Can you make an RS-485 BUS for two stm32 microcontroller circuits?

abagnale
Автор

We have ASIC display chip, is it possible for you to try it?

DwinTechnologyOfficial
Автор

how to use 2 uarts 2 modules with one stm. I tried to combine codes but It does not work properly

minecetinkaya
Автор

i want to make the communicate 2 stm32f103c8t6 stand-alone with no computer connection if it is possible that I give power both stms from same source and to max485s from stms 5v pn?

Rynxie
Автор

Great explanation. I use different module with auto logic for receive and transmit, so it's only need 2 pins. If possible i need knowledge about CAN J1939 and OBD2 :D

yudhahamdiarzi
Автор

Please make a video on stm32f4 with c11101rf transceiver by spi communication

koteswararaopokuri
Автор

Hi, great tutorial. I have one question - what voltage are You using to power the modules? If the voltage is 5V - do You need any voltage converter for data lines Rx/Tx?

kinomaniak
Автор

What is the link to this software Q ide, please share the link

seimela
Автор

i need code for reccieve interface of rs 485 in interrupt method

phanendrabeella
Автор

Please make a video to explain how to connect my computer stm32 via RS485

ahmedrefaie
Автор

Please is it possible to protect the code from theft?

ahmedrefaie
Автор

I think your explanation of voltage levels is plain wrong. This is a differential pair. Logic '1' is when A is low and B is high, and for '0' A is high, and B is low.
Low and High are the same voltage levels for both lines. There is always a positive or negative difference between the two lines. A voltage difference of 0V as you showed is actually an undefined logical state and must be avoided.
The absolute voltage level of the lines compared to ground is irrelevant as long as the limits are not exceeded. The signal is defined by the voltage difference between the two lines.

kaihorstmann
visit shbcf.ru