For the complete documentation index, see llms.txt. This page is also available as Markdown.

SDM01 Combo (ESP8685)

Custom Firmware Development Guide: SDM01 Combo (ESP8685)

Applies to: SDM01 Combo | Hardware Revision: V1.0+ | Last Updated: 2026-04-25

🛑 DANGER: LETHAL VOLTAGE & CRITICAL SAFETY WARNING

1. Safe Flashing (No AC Required): The 7-pin external UART port provides a 3V3 power pin. You can and should flash the device using only the 3.3V power from your USB-TTL adapter, with the meter COMPLETELY DISCONNECTED from AC mains.

2. Live-Power Debugging (AC Connected): Debugging the device while it is connected to live AC mains exposes you to LETHAL VOLTAGES.

  • RCD & Isolation Transformer are MANDATORY: Your AC test bench must be protected by an RCD/GFCI (Residual Current Device) feeding into an Isolation Transformer. You must power the meter via this isolation transformer. An opto-isolated USB-to-TTL adapter ONLY protects your computer; it DOES NOT protect you from fatal electric shocks.

  • ⚠️ The "Safety Illusion" Warning: An isolation transformer only protects against line-to-ground shocks. If you touch both the Live and Neutral wires on the isolated secondary side simultaneously, the transformer will treat your body as a normal load. The primary-side RCD will NOT detect this and WILL NOT trip, resulting in a lethal shock across your heart.

  • The "One-Hand Rule": Always keep one hand in your pocket or behind your back when probing live circuits. Never touch the PCBA with both hands while it is powered.

  • Qualified Personnel Only: Live AC debugging must ONLY be performed by certified professionals in compliance with local electrical safety regulations.

⚖️ DISCLAIMER OF LIABILITY: Working with AC mains is inherently dangerous. By choosing to flash, debug, or modify this device, you acknowledge and accept all associated risks. The manufacturer assumes NO RESPONSIBILITY or LIABILITY for any personal injury, death, equipment damage, or property loss caused by improper handling, lack of safety precautions, or unauthorized modifications.


1. Product Overview

1.1 Introduction

The SDM01-EWM-* is a compact 18mm-wide DIN-rail smart energy meter designed for real-time monitoring of three-phase systems or multiple single-phase branches. It features a dual-MCU architecture, separating the:

This architecture allows developers to flash their own custom firmware on the SoC without affecting the core metering accuracy or calibration data.

1.2 Hardware Architecture

  • Wireless SoC (Master): Handles Wi-Fi / BLE / MQTT / HTTP / Custom Logic. It communicates with the meter MCU via internal Modbus-over-UART.

  • Base Meter MCU (Slave): Handles metering, calibration, and RS485 Modbus RTU. Stores all measurement parameters independently.


2. Hardware Flashing Guide (External UART)

🛑 DANGER: HIGH VOLTAGE & CRITICAL SAFETY WARNING

1. Safe Flashing (No AC Required): The 7-pin external UART port provides a 3V3 power pin. You can and should flash the device using only the 3.3V power from your USB-TTL adapter, with the meter COMPLETELY DISCONNECTED from AC mains.

2. Live-Power Debugging (AC Connected): If you must debug the device while it is connected to live AC power (e.g., to verify real-time metering data), YOU MUST USE AN ISOLATION TRANSFORMER to power the meter, OR use a strictly opto-isolated USB-to-TTL adapter. Connecting a standard, non-isolated computer to a mains-powered meter creates a direct ground loop that WILL destroy your computer's motherboard and poses a LETHAL electric shock hazard!

💡 Hardware Version Notice & Ordering Instruction: Starting from May 2026, the standard production of SDM01-EWM (Open WiFi+RS485) meters is transitioning to the External UART Flashing Version. This version allows developers to perform UART flashing and debugging directly through the 7-pin programming holes on the enclosure, without opening the device.

⚠️ Please note that older versions featuring the External JTAG Port may still be circulating in the market or present in our existing inventory. If your development specifically requires the External UART port version, please explicitly state "Require External UART Port Version" when placing your order.

2.1 Pinout Definition

The external programming port provides all necessary pins, including a 3.3V power supply, making it completely safe to flash without connecting the meter to AC mains.

Number
Name
Type
Function / Connection Guide

1

NC

NC

Not Connected

2

IO9

I/O/T

Boot Mode Selection: • High/Floating: Normal Operating Mode • Low (GND): Burning/Flashing Mode

3

GND

P

Ground

4

RXD

I/O/T

GPIO20, U0RXD (Connect to TX of your USB-TTL adapter)

5

TXD

I/O/T

GPIO21, U0TXD (Connect to RX of your USB-TTL adapter)

6

GND

P

Ground

7

3V3

P

3.3V Power Supply (Connect to 3V3 of your USB-TTL adapter)

2.2 How to Enter Flashing Mode (Standard Espressif Sequence)

To flash the ESP8685 SoC, you must force it into "Download Mode" using the IO9 pin during boot.

Step-by-step Flashing Procedure:

  1. Disconnect AC Power: Ensure the meter is completely disconnected from any high-voltage AC mains.

  2. Wire the Adapter: Connect RXD, TXD, GND, and 3V3 from the meter to your 3.3V USB-to-TTL serial adapter.

  3. Pull IO9 to GND: Use a jumper wire to connect Pin 2 (IO9) to Pin 3 (GND).

  4. Power Up: Plug your USB-TTL adapter into your computer (this supplies 3.3V to the meter). Because IO9 is grounded during power-up, the ESP8685 will boot into Download Mode.

  5. Flash Firmware: Run your flashing tool (ESP-IDF, PlatformIO, or esptool).

  6. Reboot to Normal Mode: Once flashing is complete, disconnect the USB adapter (power off), remove the jumper between IO9 and GND, and power it back on. The device will now boot your custom firmware.


3. Firmware Flashing Details & Partition Tables

When compiling and flashing your custom firmware, ensure your partition table matches the device's flash layout. The default configuration is designed for a 4MB Flash (1.9MB App, 1.9MB OTA, 190KB SPIFFS).

3.1 Memory Addresses

Binary File
Write Address
Description

bootloader.bin

0x0000

ESP32 Bootloader

partitions.bin

0x8000

Partition Table

app.bin

0x10000

Your Custom Application Firmware

spiffs.bin

0x3D0000

SPIFFS File System (Optional)

3.2 Generating and Flashing SPIFFS (ESP-IDF)

If your firmware requires a SPIFFS file system (e.g., for web server HTML/CSS files), you can generate and flash it using the following ESP-IDF command:

Command Explanation:

  • spiffsgen.py: The ESP-IDF script (if not found in your PATH, replace with the actual absolute address).

  • 0x20000: Binary code size. Make sure the size you set matches the partition size you configured in your partitions.csv.

  • yourspiffs: The folder address that needs to be converted. The script will convert all files in this folder into a .bin file, which will be automatically parsed when uploaded to the device.

  • spiffs.bin: The address and name of the file after successful conversion.


4. Internal Modbus-over-UART Communication

Once your custom firmware is running on the ESP8685, it needs to communicate with the Base Meter MCU to read energy data. This is done via Modbus RTU over the internal UART.

4.1 Communication Parameters

Your ESP8685 firmware should configure its UART (acting as Modbus Master) with the following default parameters to talk to the Meter MCU (Slave):

  • Baud Rate: 19200 bps (Default)

  • Data Bits: 8

  • Parity: None (N81)

  • Stop Bits: 1

  • Default Modbus Slave Address: 247 (0xF7)

4.2 Key Modbus Registers Quick Reference

The Meter MCU exposes all measurements via standard Modbus Holding Registers (Function Code 0x03 / 0x04). Data is stored in FLOAT32 format (Word Order: AB CD).

Here is a quick cheat sheet of the most commonly used registers to get you started:

Basic Metering Data (Read Only - 0x03/0x04):

Register (DEC)
Register (HEX)
Description
Data Type
Unit

1000

0x03E8

Voltage A-N

FLOAT32 (4 bytes)

V

1006

0x03EE

Current A

FLOAT32 (4 bytes)

A

1012

0x03F4

Active power A

FLOAT32 (4 bytes)

kW

1030

0x0406

Power factor A

FLOAT32 (4 bytes)

-1 ~ 1

1044

0x0414

Total active power

FLOAT32 (4 bytes)

kW

1052

0x041C

Frequency

FLOAT32 (4 bytes)

Hz

1058

0x0422

Total Import & Export active energy

FLOAT32 (4 bytes)

kWh

Device Control & Commands (Write Only - 0x06):

Register (DEC)
Register (HEX)
Description
Command Value

10000

0x2710

Device locating (LED blinking)

Write 0x5055

10001

0x2711

Reset Energy Data

Write 0x51AA

Button & LED Control

Address (DEC)
Address (HEX)
Description
Func Code
R/W
Words
Value Mapping / Remarks

62000

0xF230

LED indication control

03, 04, 06

R/W

2

0x0000 = Flashing at 0.5Hz 0x0001 = Solid ON 0x0002 = Flashing at 0.25Hz 0x0003 = Flashing at 2Hz 0x0004 = Flashing at 5Hz 0x0005 = Flashing at 1Hz

62001

0xF231

Button status

03, 04

R/W

2

0x0000 = Idle / No action 0x0055 = Button long-pressed (> 5 seconds). Value auto-resets to 0x0000 upon button release.

📚 Full Register Map: For the complete list of registers (including Phase B/C, Reactive Power, Apparent Power, and Manufacturer Info), please refer to the official document: SDM01 Combo Modbus RTU API.


5. Reference & Resources

5.1 Community Open-Source Reference (Tasmota)

If you are looking for a code template, a known open-source reference is Tasmota. We provide a bundled project package that includes an SDM01 integration module contributed by a community enthusiast.

Please note: The core Tasmota framework remains completely unchanged; we simply added the SDM01 driver file. Although this integration is functionally operational and its usage is generally the same as other Tasmota-based smart energy meters, it has not yet been submitted to the official Tasmota repository. Furthermore, it has not undergone the rigorous reliability testing of our official factory firmware. We highly recommend using its Modbus driver primarily as a reference or template for your custom development.

[📥 Download Tasmota Package with SDM01 Driver (.zip)]

  • Path example inside the package: platformio_tasmota/tasmota/tasmota_xnrg_energy/xnrg_34_sdm01.ino

5.2 FAQ

Q: Will reflashing the ESP8685 affect the measurement accuracy? No. All metrology, calibration, and measurement logic are strictly handled by the isolated base MCU.

Q: Can I use the ESP32-C3 toolchain for the ESP8685? Yes. The ESP8685 is essentially an ESP32-C3 die in a different package. You can safely compile your firmware using board = esp32-c3 in PlatformIO or ESP-IDF. Q3: Can I modify the Modbus RTU parameters (such as baud rate and parity) in the base MCU?Yes. You can modify these parameters either by customizing the SoC firmware code or by sending specific Modbus write commands, depending on your specific implementation needs.

最后更新于