# SDM01 Combo (ESP8685)

## Custom Firmware Development Guide: SDM01 Combo (ESP8685)

{% hint style="info" %}
&#x20;**Applies to:** SDM01 Combo | **Hardware Revision:** V1.0+ | **Last Updated:** 2026-04-25
{% endhint %}

> 🛑 **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

![](https://acnmd2zc649i.feishu.cn/space/api/box/stream/download/asynccode/?code=ZDg1NzAzYTZiZTY1NzM5ZjYxZDlkZjdmZjFmM2MzY2FfT2RHMkdmSVJHbXlodldpV0d6VlFTdG9QTVZQdWNLdXRfVG9rZW46VnE1M2JSWWFRbzZUMjl4MlBDY2MydXVsbkpoXzE3NzYxNzMxMjk6MTc3NjE3NjcyOV9WNA)

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:

* **Wireless Communication SoC** (ESP32-8685, [WiFi Module ESP8685-WROOM-01](https://documentation.espressif.com/esp8685-wroom-01_datasheet_en.pdf))
* **Base Meter MCU** (Handles calibration, metering, and RS485 functions)

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.
*

<figure><img src="/files/xBeBE8fp0TOH3EfVG3vo" alt=""><figcaption></figcaption></figure>

***

### 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.

{% columns %}
{% column %}

<figure><img src="/files/air5OckU69ck3Gf5MJeB" alt=""><figcaption></figcaption></figure>
{% endcolumn %}

{% column %}

<figure><img src="/files/CNouf5SfPD8ZQIaCryW0" alt=""><figcaption></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

<table><thead><tr><th width="104">Number</th><th width="106">Name</th><th width="111">Type</th><th width="359">Function / Connection Guide</th></tr></thead><tbody><tr><td><strong>1</strong></td><td>NC</td><td>NC</td><td>Not Connected</td></tr><tr><td><strong>2</strong></td><td><strong>IO9</strong></td><td>I/O/T</td><td><strong>Boot Mode Selection:</strong><br>• High/Floating: Normal Operating Mode<br>• <strong>Low (GND): Burning/Flashing Mode</strong></td></tr><tr><td><strong>3</strong></td><td>GND</td><td>P</td><td>Ground</td></tr><tr><td><strong>4</strong></td><td><strong>RXD</strong></td><td>I/O/T</td><td>GPIO20, U0RXD <em>(Connect to <strong>TX</strong> of your USB-TTL adapter)</em></td></tr><tr><td><strong>5</strong></td><td><strong>TXD</strong></td><td>I/O/T</td><td>GPIO21, U0TXD <em>(Connect to <strong>RX</strong> of your USB-TTL adapter)</em></td></tr><tr><td><strong>6</strong></td><td>GND</td><td>P</td><td>Ground</td></tr><tr><td><strong>7</strong></td><td><strong>3V3</strong></td><td>P</td><td>3.3V Power Supply <em>(Connect to <strong>3V3</strong> of your USB-TTL adapter)</em></td></tr></tbody></table>

#### 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

<table><thead><tr><th>Binary File</th><th width="228">Write Address</th><th>Description</th></tr></thead><tbody><tr><td><code>bootloader.bin</code></td><td><strong>0x0000</strong></td><td>ESP32 Bootloader</td></tr><tr><td><code>partitions.bin</code></td><td><strong>0x8000</strong></td><td>Partition Table</td></tr><tr><td><code>app.bin</code></td><td><strong>0x10000</strong></td><td>Your Custom Application Firmware</td></tr><tr><td><code>spiffs.bin</code></td><td><strong>0x3D0000</strong></td><td>SPIFFS File System (Optional)</td></tr></tbody></table>

#### 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:

```bash
Copypython spiffsgen.py 0x20000 yourspiffs spiffs.bin
```

**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:** `9600 bps` (Default)
* **Data Bits:** `8`
* **Parity:** `None` (N81)
* **Stop Bits:** `1`
* **Default Modbus Slave Address:** `247` (0xF7)

*(Note: These parameters can be modified by writing to registers `6000`, `6001`, and `6002` if needed).*

#### 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**

<table><thead><tr><th width="108.11114501953125">Address (DEC)</th><th width="89.77777099609375">Address (HEX)</th><th width="128">Description</th><th width="117.3333740234375">Func Code</th><th width="85.3331298828125">R/W</th><th width="92.0001220703125">Words</th><th width="255.111083984375">Value Mapping / Remarks</th></tr></thead><tbody><tr><td>62000</td><td><code>0xF230</code></td><td>LED indication control</td><td>03, 04, 06</td><td>R/W</td><td>2</td><td><code>0x0000</code> = Flashing at 0.5Hz<br><code>0x0001</code> = Solid ON<br><code>0x0002</code> = Flashing at 0.25Hz<br><code>0x0003</code> = Flashing at 2Hz<br><code>0x0004</code> = Flashing at 5Hz<br><code>0x0005</code> = Flashing at 1Hz</td></tr><tr><td>62001</td><td><code>0xF231</code></td><td>Button status</td><td>03, 04</td><td>R/W</td><td>2</td><td><code>0x0000</code> = Idle / No action<br><code>0x0055</code> = Button long-pressed (> 5 seconds). Value auto-resets to <code>0x0000</code> upon button release.</td></tr></tbody></table>

> 📚 **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](https://app.gitbook.com/o/aiS2FTYMQgap4pTEB6BW/s/TmsWivaZjkubbVKrCezC/device-api/modbus-rtu-register-map/sdm01-comb-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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.bituo-technik.com/custom-firmware/sdm01-combo-esp8685.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
