debevv/nanoMODBUS logo

debevv/nanoMODBUS

Free

A compact MODBUS RTU/TCP C library for embedded/microcontrollers

FreeFree tier
Type
Open Source

About debevv/nanoMODBUS

nanoMODBUS is a compact C library that implements the Modbus protocol, designed specifically for embedded and resource-constrained systems like microcontrollers. It comprises only ~2000 lines of code, supports both RTU and TCP transports, and can operate as a client or server. The library offers a wide range of Modbus function codes, including read/write coils, registers, file records, and device identification. It is platform-agnostic, requiring only C99 and its standard library, and allows users to implement custom data transport read/write functions and CRC routines. The library avoids dynamic memory allocations and supports broadcast requests and responses. Installation is straightforward: copy the two source files (nanomodbus.c and nanomodbus.h) into the project, or integrate via CMake using FetchContent.

Key Features

Compact size: only ~2000 lines of code
Client and server code can be disabled if not needed
No dynamic memory allocations
Supports RTU and TCP transports
Roles: Client and Server
Implements Modbus function codes: Read Coils, Read Discrete Inputs, Read/Writing Registers, Write Single/Multiple Coils/Registers, Read/Write File Records, Read/Write Multiple Registers, Read Device Identification
Platform-agnostic: requires only C99 and its standard library
User-definable data transport read/write functions
User-definable CRC function for better performance
Broadcast requests and responses support

Pros & Cons

Pros
  • Extremely compact and lightweight (~2000 lines)
  • No dynamic memory allocation makes it suitable for bare-metal systems
  • Platform-agnostic; works with any C99-compatible compiler
  • User-defined transport and CRC provide flexibility for various hardware
  • Supports both RTU and TCP transports
  • Broadcast message support
  • Open-source and free (MIT license implied)
Cons
  • Requires users to implement transport read/write functions (adds integration effort)
  • Only supports RTU and TCP; no Modbus ASCII support
  • Not a full-featured Modbus stack (e.g., no built-in device simulation beyond basic functions)

Best For

Embedded systems and microcontroller-based projectsIndustrial automation and control systemsModbus RTU or TCP communication in resource-constrained environmentsCustom Modbus client or server implementations

FAQ

What is nanoMODBUS?
nanoMODBUS is a compact C library that implements the Modbus protocol, optimized for embedded and microcontroller systems. It supports RTU and TCP transports, client and server roles, and many function codes.
How do I install nanoMODBUS?
You can install it manually by copying `nanomodbus.c` and `nanomodbus.h` into your project, or integrate it using CMake with `FetchContent` by pointing to the GitHub repository.
What Modbus function codes does nanoMODBUS support?
It supports function codes 01 (Read Coils), 02 (Read Discrete Inputs), 03 (Read Holding Registers), 04 (Read Input Registers), 05 (Write Single Coil), 06 (Write Single Register), 15 (Write Multiple Coils), 16 (Write Multiple Registers), 20 (Read File Record), 21 (Write File Record), 23 (Read/Write Multiple Registers), and 43/14 (Read Device Identification).
Is nanoMODBUS suitable for microcontrollers?
Yes, it is specifically designed for embedded and resource-constrained systems. It has a small code footprint, no dynamic memory allocations, and is platform-agnostic.