Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ModbusMaster.h>
- ModbusMaster node;
- static uint8_t pzemSlaveAddr = 3;
- #define RXD1 32
- #define TXD1 25
- unsigned cur_time, old_time;
- #define MAX485_RE_NEG 33
- #define MAX485_DE 33
- void preTransmission()
- {
- digitalWrite(MAX485_RE_NEG, 1);
- digitalWrite(MAX485_DE, 1);
- }
- void postTransmission()
- {
- digitalWrite(MAX485_RE_NEG, 0);
- digitalWrite(MAX485_DE, 0);
- }
- void setup() {
- // put your setup code here, to run once:
- digitalWrite(MAX485_RE_NEG, 0);
- digitalWrite(MAX485_DE, 0);
- Serial.begin(115200);
- Serial1.begin(9600, SERIAL_8N1, RXD1, TXD1);
- node.begin(pzemSlaveAddr, Serial1);
- node.preTransmission(preTransmission);
- node.postTransmission(postTransmission);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- cur_time = millis();
- if (cur_time - old_time >= 3000) {
- uint8_t result;
- uint32_t tempdouble;
- result = node.readHoldingRegisters(171, 2);
- if (result == node.ku8MBSuccess)
- {
- Serial.println("success read modbus1");
- }
- else {
- Serial.println("failed read modbus1");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement