Skip to content

Sourabh362/linux-rs485-stack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

linux-rs485-stack

Linux ↔ ESP32 RS485 communication stack using ESP-IDF and Linux userspace UART programming.


Overview

This project demonstrates bidirectional RS485 communication between:

  • Linux userspace UART application
  • ESP32 firmware using ESP-IDF
  • RS485 transceiver modules

The project focuses on low-level serial communication concepts including:

  • UART configuration
  • RS485 transport
  • packet-based communication
  • Linux serial programming with termios
  • ESP-IDF UART driver usage
  • communication debugging and testing

System Architecture

Linux UART Application
          ↕
USB ↔ RS485 Adapter
          ↕
RS485 Bus
          ↕
ESP32 UART + RS485 Module

Repository Structure

linux-rs485-stack/
│
├── esp_rs485_driver/
│   ├── main/
│   ├── CMakeLists.txt
│   └── sdkconfig
│
├── linux_uart_app/
│   └── uart_app.c
│
├── README.md
├── .gitignore
└── .gitattributes

Features

Linux Side

  • POSIX UART serial programming
  • UART configuration using termios
  • Blocking UART RX/TX
  • Raw byte stream handling
  • Graceful application shutdown using signal handling
  • Continuous UART receive loop

ESP32 Side

  • ESP-IDF UART driver
  • RS485 packet transmission
  • Packet checksum generation
  • UART RX/TX debugging
  • Continuous packet transmission testing

UART Configuration

Parameter Value
Baudrate 115200
Data Bits 8
Stop Bits 1
Parity None
Flow Control Disabled

Example Packet

AA 55 01 56
Byte Description
AA Start Byte
55 Command
01 Data
56 Checksum

Linux Build

Compile:

gcc uart_app.c -o uart_app

Run:

sudo ./uart_app

ESP32 Build

Build firmware:

idf.py build

Flash firmware:

idf.py flash

Open serial monitor:

idf.py monitor

Hardware Used

  • ESP32 Development Board
  • RS485 UART Module
  • USB ↔ RS485 Adapter
  • Linux Host Machine / VM

Current Status

  • UART communication verified
  • RS485 transmission verified
  • Linux UART RX/TX verified
  • ESP32 UART TX verified
  • Packet transmission verified

Future Improvements

  • CRC16 packet validation
  • Packet parser state machine
  • Timeout handling
  • Retry mechanism
  • Non-blocking UART
  • Multithreaded Linux UART handling
  • Modbus RTU support
  • Packet framing improvements

Technologies Used

  • C
  • ESP-IDF
  • FreeRTOS
  • POSIX Serial Programming
  • UART
  • RS485
  • Linux

About

This work implemets linux rs485 driver stack development

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors