Communication to RS485 device via UART

JessPinkman
Posts: 6
Joined: Tue Sep 08, 2020 8:50 am

Communication to RS485 device via UART

Postby JessPinkman » Tue Sep 08, 2020 9:03 am

Hello,

I must start by saying I am a total noob for HW / microcontrollers in general.
My background is web development, so while I have been reading and i am starting to understand a bit about all of this, it is still confusing to me.

I am now trying to learn about ESP32-IDF, with the aim of communication with a Modbus RTU RS485 device (slave), via the UART controller of the ESP32.

My first question is :
Do I need some kind of additional module (MAX485 board) or is it not necessary ? (ESP32 needs to communicate with only one device)

I have read all info concerning UART and RS485 on the esp-idf documentation.
I have the target device modbus RTU communication protocol, with all addresses /registers etc...
My second question is more broad: Can anyone point me to the right direction (big steps), at least to start this journey ?

ESP_Sprite
Posts: 9051
Joined: Thu Nov 26, 2015 4:08 am

Re: Communication to RS485 device via UART

Postby ESP_Sprite » Tue Sep 08, 2020 3:12 pm

Yes, the voltage levels on the GPIO pins of the ESP32 are not physically compatible with RS485. You'd need e.g. a MAX485 to convert.

JessPinkman
Posts: 6
Joined: Tue Sep 08, 2020 8:50 am

Re: Communication to RS485 device via UART

Postby JessPinkman » Wed Sep 09, 2020 11:40 pm

Thank you!

ESP_alisitsyn
Posts: 203
Joined: Fri Feb 01, 2019 4:02 pm
Contact:

Re: Communication to RS485 device via UART

Postby ESP_alisitsyn » Thu Sep 24, 2020 10:22 am

Hello,

The steps are below:
1. Read the device manual and find what interface it supports. For Modbus RTU it is usually the RS485 interface.
2. If the interface is RS485 you need the RS485 hardware to communicate with master and slave. The additional information related to interface connection can be found in the official esp-idf documentation (https://docs.espressif.com/projects/esp ... /uart.html).
3. Please buy or assemble the RS485 adapter boards and properly connect them to ESP32 chip. I would recommend you to buy USB-RS485 adapter and RS485 board:
https://www.ebay.com/itm/MAX485-TTL-Sch ... SwA75fHJG2
4. Start the terminal on your PC and connect to serial port of USB-RS485 adapter. On other side connect the adapter board to ESP32 and start the official echo_ers485 example: examples\peripherals\uart\uart_echo_rs485.
The message sent over the USB_RS485 should be returned back from ESP32 board (Refer to example configuration).
5. Connect Modbus master and slave boards using the RS485 adapter boards above. Start the serial master and slave examples: examples\protocols\modbus\serial\* and make sure they can communicate each other.
6. Configure your master data dictionary in master example according to your device manual to read required data parameters.
examples\protocols\modbus\serial\mb_master\main\master.c::device_parameters[]
Update the data structures in examples\protocols\modbus\mb_example_common\include\device_params.h according to your device map. Update the master_operation_func() to perform the required behavior of your Modbus master device when read and write the device parameters from slave (perform required actions).
7. Connect your master ESP32 device to your slave, start example and see the log of communication.

Please refer to the appropriate documentation in ESP-IDF.
Please let me know if you still have questions.
Attachments
RS485_connection_wo_externals.png
RS485_connection_wo_externals.png (54.01 KiB) Viewed 18409 times

Who is online

Users browsing this forum: Google [Bot] and 246 guests