1 Communication protocol
1.1 Physical layer protocol
Physical layer use UART to TTL communication interface
Baud rate is 9600, 8 data bits, 1 stop bit, no parity
1.2 Application layer protocol
The application layer use the Modbus-RTU protocol to communicate. At present, it only supports function codes such as 0x03 (Read Holding Register), 0x04 (Read Input Register), 0x06 (Write Single Register), 0x41 (Calibration), 0x42 (Reset energy).etc.
0x41 function code is only for internal use (address can be only 0xF8), used for factory calibration and return to factory maintenance occasions, after the function code to increase 16-bit password, the default password is 0x3721
The address range of the slave is 0x01 ~ 0xF7. The address 0x00 is used as the broadcast address, the slave does not need to reply the master. The address 0xF8 is used as the general address, this address can be only used in single-slave environment and can be used for calibration etc.operation.
1.3 Read the measurement result
The command format of the master reads the measurement result is(total of 8 bytes):
Slave Address + 0x04 + Register Address High Byte + Register Address Low Byte + Number of Registers High Byte + Number of Registers Low Byte + CRC Check High Byte + CRC Check Low Byte.
The command format of the reply from the slave is divided into two kinds:
Correct Reply: Slave Address + 0x04 + Number of Bytes + Register 1 Data High Byte + Register 1 Data Low Byte + ... + CRC Check High Byte + CRC Check Low Byte
Error Reply: Slave address + 0x84 + Abnormal code + CRC check high byte + CRC check low byte
Abnormal code analyzed as following (the same below)
l 0x01,Illegal function
l 0x02,Illegal address
l 0x03,Illegal data
l 0x04,Slave error
The register of the measurement results is arranged as the following table
Register address |
Description |
Resolution |
0x0000 |
Voltage value |
1LSB correspond to 0.1V |
0x0001 |
Current value low 16 bits |
1LSB correspond to 0.001A |
0x0002 |
Current value high 16 bits |
0x0003 |
Power value low 16 bits |
1LSB correspond to 0.1W |
0x0004 |
Power value high 16 bits |
0x0005 |
Energy value low 16 bits |
1LSB correspond to 1Wh |
0x0006 |
Energy value high 16 bits |
0x0007 |
Frequency value |
1LSB correspond to 0.1Hz |
0x0008 |
Power factor value |
1LSB correspond to 0.01 |
0x0009 |
Alarm status |
0xFFFF is alarm£¬0x0000is not alarm |
For example, the master sends the following command (CRC check code is replaced by 0xHH and 0xLL, the same below)
0x01 + 0x04 + 0x00 + 0x00 + 0x00 + 0x0A + 0xHH + 0xLL
Indicates that the master needs to read 10 registers with slave address 0x01 and the start address of the register is 0x0000
The correct reply from the slave is as following:
0x01 + 0x04 + 0x14 + 0x08 + 0x98 + 0x03 + 0xE8+0x00 + 0x00 +0x08 + 0x98+ 0x00 + 0x00 + 0x00 + 0x00 + 0x00 + 0x00 + 0x01 + 0xF4 + 0x00 + 0x64 + 0x00 + 0x00 + 0xHH + 0xLL
The above data shows
l Voltage is 0x0898, converted to decimal is 2200, display 220.0V
l Current is 0x000003E8, converted to decimal is 1000, display 1.000A
l Power is 0x00000898, converted to decimal is 2200, display 220.0W
l Energy is 0x00000000, converted to decimal is 0, display 0Wh
l Frequency is 0x01F4, converted to decimal is 500, display 50.0Hz
l Power factor is 0x0064, converted to decimal is 100, display 1.00
l Alarm status is 0x0000, indicates that the current power is lower than the alarm power threshold