[MODBUS] SDM120 Modbus Energy Meter - decoding output

Hi all,

I have an SDM120 modbus energy meter. I’m using the modbus library provided by the Particle IDE (Particle Build), which can be found here:

Modbus-Master: GitHub - lithiumhead/ModbusMaster

Some documentation on my device:

http://docs-europe.electrocomponents.com/webdocs/1584/0900766b81584bd7.pdf (high level)

http://www.flanesi.it/blog/download/sdm120c/SDM120-Modbus_protocol_V2.1.pdf?dl=0 (the protocol)

I’m struggling to decode the modbus response into something helpful.

See below the sketch I am using:

#include "ModbusMaster.h"

// instantiate ModbusMaster object as slave ID 1
ModbusMaster node(1);

void setup() {
	// initialize Modbus communication baud rate

	node.enableTXpin(A1); //A1 is the pin used to control the TX enable pin of RS485 driver
	//node.enableDebug();  //Print TX and RX frames out on Serial. Beware, enabling this messes up the timings for RS485 Transactions, causing them to fail.

	Serial.println("Starting Modbus Transaction:");

void loop() {
	static uint32_t i;
	uint8_t j, result;
	uint16_t data[10];


	result = node.readInputRegisters(0x0000,2);


	// do something with data if read is successful
	if (result == node.ku8MBSuccess) {
		Serial.print("Success, Received data: ");
		for (j = 0; j < 2; j++) {
			data[j] = node.getResponseBuffer(j);
			Serial.print(data[j], HEX);
			Serial.print(" ");
	} else {
		Serial.print("Failed, Response Code: ");
		Serial.print(result, HEX);
		delay(5000); //if failed, wait for bit longer, before retrying!

With the most important section of the codebase being result = node.readInputRegisters(0x0000,n);

with n set to 1:
Success, Received data: 4371 0

with n set to 2:
Success, Received data: 4371 6666

Setting n to anything higher just yields the same result as n=2.

Reading the register 0x0000 yields the Voltage, which should be around 240V (I can confirm this by reading the value on the meter).

I’m aware that a couple of resources already exist, but these are tailored to the SDM, whereas I’m after an implementation that uses the modbus library, as I plan to add other modbus devices. Some resources:

Would appreciate some guidance on reading this properly. This is my first (scary!) venture into Modbus.

The output you receive is in the form of IEEE-754 hex. You can use the link to convert it to standard decimals.
So, 4371 6666 converts to 241.4 Volts. Hope this helps.

1 Like