Go Down

Topic: Modbus RTU (Read 143 times) previous topic - next topic

sapieus

Hi there ! I'm sorry, I've no idea if I post this topic in the right section. I'm sure an admin will figure it out...

Anyway, I've troubles using a Modbus RTU device with my Arduino Nano.

Here is my code : (by the way, I'm kind of a new with Modbus and I'm still trying to figure it out so please be indulgent with my terrible coding ^^)

Code: [Select]
#include <ModbusMaster.h>

#define Max485_DE    2
#define Max485_RE_NEG 3

ModbusMaster node;

void preTransmission()
{
  digitalWrite(Max485_RE_NEG, 1);
  digitalWrite(Max485_DE, 1);
}

void postTransmission()
{
  digitalWrite(Max485_RE_NEG, 0);
  digitalWrite(Max485_DE, 0);
}

void setup()
{
  pinMode(Max485_RE_NEG, OUTPUT);
  pinMode(Max485_DE, OUTPUT);

  digitalWrite(Max485_RE_NEG, 0);
  digitalWrite(Max485_DE, 0);

  Serial.begin(9600);
 
  node.begin(10, Serial);

  node.preTransmission(preTransmission);
  node.postTransmission(postTransmission);
}

void loop()
{
  uint8_t resultMain;

  resultMain = node.readInputRegisters(0x0053,1);
  delay(580);
  if (resultMain == node.ku8MBSuccess)
  {
    Serial.println(node.getResponseBuffer(0x53));
  }

  delay(1000);
}


Before we go any further, yes my probe use a 9600 baud-rate, it's ID is 10 and it needs a 580ms delay to send a response.

As you can see, I'm trying to get the data at the address 0x0053 and print it in my serial monitor. This data is a float. (don't know if that can help)

Now, I found that code in a tutorial and it appeared to work just fine with his setup but for me, it only gets the letter "w"...
I just adapted the code to my needs.

Does someone have a solution ?

I have a LOT of infos about the probe and its precise Modbus RTU Protocole. So feel completely free to ask for any further information !

I thank you in advance for taking time to go through this for me. I appreciate that...

Nico

sapieus

PS : I'm using a Max485 module

Go Up