0

I'm trying to connect with a 4 channel temperature controller using Arduino Modbus Library.

This is a part of my temperature controller datasheet. It has register for read PV of each channel.

Registers

I have studied example code of the library and now i'm trying to read PV of each channel.

So, I have modified the example code as below,

#include <ModbusMaster.h>
 // instantiate ModbusMaster object
 ModbusMaster node;
 void setup()
 {
 // use Serial (port 0); initialize Modbus communication baud rate
 Serial.begin(19200);
 // communicate with Modbus slave ID 2 over Serial (port 0)
 node.begin(2, Serial);
 }
 void loop()
 {
 static uint32_t i;
 uint8_t j, result;
 uint16_t data[6];
 i++;
 // set word 0 of TX buffer to least-significant word of counter (bits 15..0)
 node.setTransmitBuffer(0, lowWord(i));
 // set word 1 of TX buffer to most-significant word of counter (bits 31..16)
 node.setTransmitBuffer(1, highWord(i));
 // slave: read (4) 16-bit registers starting at register 2 to RX buffer
 result = node.readHoldingRegisters(1, 4);
 // do something with data if read is successful
 if (result == node.ku8MBSuccess)
 {
 for (j = 0; j < 4; j++)
 {
 data[j] = node.getResponseBuffer(j);
 }
 }
 }

My questions are, Explain below lines in the code

 // set word 0 of TX buffer to least-significant word of counter (bits 15..0)
 node.setTransmitBuffer(0, lowWord(i));
 // set word 1 of TX buffer to most-significant word of counter (bits 31..16)
 node.setTransmitBuffer(1, highWord(i));

I didn't pass any request to slave, So, can I get the 4 PV value like this? If not, please explain how can I do it.

asked Sep 25, 2018 at 7:40
0

1 Answer 1

1

The setTransmitBuffer calls are for writeMultipleRegisters, which you removed from the example.

The first parameter of the readHoldingRegisters is the address of the register. The second parameter is the count of registers to read.

Your sketch doesn't show the retrieved data. You have no indication of success or fail.

answered Sep 25, 2018 at 9:16
2
  • As I understood, setTransmitBuffer using for initializing the TX buffer.Am I correct? Retrieved data stored in RX buffer. can't we get data using getResponseBuffer? Commented Sep 25, 2018 at 9:45
  • you have data[j] = node.getResponseBuffer(j); Commented Sep 25, 2018 at 11:48

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.