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.

0

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.

  • 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? – user_fs10 Sep 25 '18 at 9:45
  • you have data[j] = node.getResponseBuffer(j); – Juraj Sep 25 '18 at 11:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.