Connecting a PLC to an energy meter? It sounds quite sophisticated, but it’s similar to connecting a Bluetooth headset to a phone; it’s just two devices communicating with each other. Modbus is the “language” they use to chat, which simply means sending and receiving data in a specific format. The S7-200 SMART is a compact PLC from Siemens, suitable for beginners and not too expensive. Today, we will connect it to an energy meter and see how these two devices “talk”.
Hardware Preparation and Wiring
First, gather the necessary equipment:
- S7-200 SMART PLC main unit (CPU SR20 or higher with RS485 model)
- Energy meter (supports Modbus-RTU protocol)
- RS485 communication cable
- 24V DC power supply
- Programming cable
The wiring is simple, just three wires: A to A, B to B, GND to GND. The communication port of the PLC is located at the bottom right corner of the CPU, usually labeled “PORT1”. On the energy meter, find the RS485 interface, sometimes labeled “RS485+” and “RS485-“; remember that “+” corresponds to A and “-” corresponds to B.
Tip: It is best to turn off the power while wiring! Otherwise, if connected incorrectly, it may damage the communication chip. Also, do not reverse A and B; if reversed, communication will be problematic.
Communication Parameter Settings
The PLC and the energy meter must be set to the same communication parameters; otherwise, it’s like you speaking Chinese while the other speaks English, and they won’t understand each other.
Open the TIA Portal software, create a new project, and add the PLC. Find “Device Configuration”, click on the CPU, and look for “Communication Port” in the properties:
- Baud Rate: 9600 (generally used, set the meter to the same)
- Data Bits: 8
- Stop Bits: 1
- Parity: Even
- Communication Protocol: Freeport
// Communication port configuration code in TIA Portal
SMB30 = 16#09; // Baud rate 9600
SMB31 = 16#02; // Data format: 8 data bits, 1 stop bit, even parity
On the energy meter side, it is usually set on the panel; enter the communication parameter menu and adjust to the same values using the buttons. Some meters cannot be changed on the panel and must be configured using their proprietary software.
Writing the Modbus Communication Program
Now we will start writing the communication program. The S7-200 SMART does not have built-in Modbus instructions, so we need to implement it ourselves. It sounds difficult, but it’s just about assembling data packets according to the format.
// Example of reading data from the energy meter (assuming meter address is 1, reading 2 registers starting from 40001)
NETWORK 1 // Assemble and send data
// Station number
VB100 := 16#01;
// Function code (03 means read holding registers)
VB101 := 16#03;
// Starting address high byte
VB102 := 16#00;
// Starting address low byte
VB103 := 16#00;
// Register count high byte
VB104 := 16#00;
// Register count low byte
VB105 := 16#02;
// Calculate CRC check (simplified version)
CALL CRC_CALC(
pData := &VB100,
Len := 6,
CRC_L := VB106,
CRC_H := VB107
);
NETWORK 2 // Send data
XMT(
PORT := 0,
TBL := &VB100,
CNT := 8
);
After sending the command, the energy meter will return data. Now we will write the receiving program:
NETWORK 3 // Receive data
RCV(
PORT := 0,
TBL := &VB200,
CNT := VW10
);
NETWORK 4 // Process data
LD SM0.0
MOVD VD202, VD300 // Move the received data to VD300
The format of the data returned by the energy meter is: station number + function code + byte count + data + CRC check. The actual data starts from VD202 and can be stored in variables for use.
Troubleshooting Communication Issues
When dealing with communication, it’s common for things not to work on the first try. Don’t worry, this is normal; let’s troubleshoot:
- Check if the wiring is correct, especially if A and B are not reversed.
- Are the communication port parameters the same? The baud rate must match.
- Is the energy meter station number set correctly? The default may be 1.
- Have you verified the energy meter register addresses? Some meters start from 0, while others start from 1.
It’s best to use an oscilloscope to check the signal; if normal, there should be a square wave signal on the communication line. If there is no signal, it means the PLC did not send it out; if there is a signal but no response, it means the energy meter did not receive it or does not recognize the command you sent.
Most issues arise from these areas: either the wiring is wrong, the parameters do not match, or the address is incorrect.
Application Scenario Expansion
Once you have established this communication, what can you do? Collect electricity data for energy consumption monitoring, observe power trends on the production line, set up over-limit alarms, and automatically calculate electricity bills every month. All these devices in the factory rely on this type of communication.
If you can communicate with the energy meter, you can also connect fans, pumps, variable frequency drives, etc.; the idea is the same as long as they support the Modbus protocol.
Using the S7-200 SMART with the energy meter, creating a small energy monitoring system is a breeze, and it’s cost-effective compared to buying a ready-made system.
Conclusion
This time we clarified the core of Modbus communication, including hardware wiring, parameter configuration, and program writing. Although the example is with an energy meter, any device that supports Modbus follows this pattern. Mastering this, you can connect to 90% of industrial control devices, which is a solid skill to have.