Go Down

Topic: Help with ModBus RTU Master-Slave: SimpleModbus [SOLVED] (Read 341607 times) previous topic - next topic

noiasca

... I checked your crosspost - but to be honest
- I don't see your code (with your code I've meant a sketch which compiles, not a snapshot of a function out of the library!)
- I don't see a datasheet to your 1000 register device
DE: Wie man Fragen postet:
1. was hat man (Sketch und Hardware)
2. was SOLL es machen
3. was macht es: IST (Fehlverhalten, Fehlermeldungen, Serial.Output ...)
4. Eine Frage stellen bzw. erklären was man erwartet

Ashokjay

Hi ,
I am using LT+5310 multifunction meter with rs485 and arduino uno micro controller
communication between micro controller and energy meter(multi function meter ) is not happening. i am getting data all zeros
please help where is the problem my source code is posted  below




#include <SimpleModbusMaster.h>



//////////////////// Port information ///////////////////
#define baud 9600
#define timeout 1000
#define polling 500 // the scan rate
#define retry_count 10

// used to toggle the receive/transmit pin on the driver
#define TxEnablePin 2

// The total amount of available memory on the master to store data
#define TOTAL_NO_OF_REGISTERS 2

// This is the easiest way to create new packets
// Add as many as you want. TOTAL_NO_OF_PACKETS
// is automatically updated.
enum
{
  PACKET1,
  TOTAL_NO_OF_PACKETS // leave this last entry
};

// Create an array of Packets to be configured
Packet packets[TOTAL_NO_OF_PACKETS];

// Masters register array
unsigned int regs[TOTAL_NO_OF_REGISTERS];

void setup()
{

 // Initialize each packet
  modbus_construct(&packets[PACKET1], 1, READ_HOLDING_REGISTERS, 40101, 2, 0);
 Serial.begin(9600);
  // Initialize the Modbus Finite State Machine
  modbus_configure(&Serial1, baud, SERIAL_8E2, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS, regs);
 
}

void loop()
{

    modbus_update();
    Serial.print(packets[PACKET1].requests);
    Serial.print(";successful_requests: "); 
    Serial.print(packets[PACKET1].successful_requests);
    Serial.print(";failed_requests: "); 
    Serial.print(packets[PACKET1].failed_requests); 
    Serial.print(";exception_errors: "); 
    Serial.print(packets[PACKET1].exception_errors);
    Serial.println(regs[0]);
    Serial.println(regs[1]);
}



noiasca

please:
- write which target/processor you are using.
- add a link from where you have downloaded the library (there are unfortunatly some variants online - so we need the exact information what you are using)
- put your code in code tags
- copy you serial output to a post with code tags
- provide a link to the datasheet of your slave device you want to read (we do not know why you have choosen READ_HOLDING_REGISTERS and start adress 40101)
- upload a picture wherein we can clearly see you wiring between processor - 485breakout and slave - which pin goes where?
DE: Wie man Fragen postet:
1. was hat man (Sketch und Hardware)
2. was SOLL es machen
3. was macht es: IST (Fehlverhalten, Fehlermeldungen, Serial.Output ...)
4. Eine Frage stellen bzw. erklären was man erwartet

kprakash

Hello all,

I am Nike, working with an energy meter (Schneider Conzerv EM 6436), and trying to read the register values using modbus. I saw the post http://forum.arduino.cc/index.php?topic=176142.15 and went through the entire thread (took nearly 2 days).

I followed the schematic at https://aglasspool.files.wordpress.com/2010/03/diagram1rev3.jpeg. I modified the connections with necessary resistors and Arduino Yun is master and conzerv meter is slave.

I tried with the simpleModbusMaster example with necessary baud rate, slave ID and couldn't get any response. Please help me out. I am here by attaching the manual of energy meter.

Manual : http://www.powertechinternational.in/catalouges/SCHNEIDER-CONZERV-EM-6400.pdf


Thanks in advance
Nike

nehe_bhimaji

Dear All
I am also struggling for Modbus communication between Arduino UNO and Multispan Energy Meter AVH 14N-M1
I am using RS485 Board and UNO hardware serial connection is attached

In manual on page 5  they have given register MAP as 30001  to 30052 as 16 bit and each parameter value occupi 2 16 bit registers

Buad rate set in 9600  and port setting is 8E1  as meter is also in same setting


but as tried to read register 30009 ( r phase voltage  & 30029 Frequency)  on Serial monitor I get only 0,0,0,0 and so on and some garbage characters


I think it may be due to I am using Same Serial port for Serial monitor

and i do not know wheather is it correct to use one serial port for both???


Then I decide to display the value on Nextion display using software serial

I have also tried to convert both register in float and send to Nextion but still result is 0.0 on dispaly
Float conversion




Please suggest


Code is also attached

noiasca

using one serial port for debug messages and for the nextion display will not work.

Use the sample sketch with debug information to the serial and leave away the nextion as long as you can't get information from your device.

If you don't have another option, use soft serial for the modbus and hardware serial for debug messages. But best solution is a microcontroller with more than one hardware serial, i.e. the Arduino Mega.

Check if your device has really device ID 3

Check if you find any information in your manual if its READ_HOLDING_REGISTERS, or READ_INPUT_REGISTERS or any other MODBUS function.

Check if the registers are decimal base or hex in the manual. In the second case use 0x30001 instead.

If you need more specific advices, link to the map / datasheet of your device.

DE: Wie man Fragen postet:
1. was hat man (Sketch und Hardware)
2. was SOLL es machen
3. was macht es: IST (Fehlverhalten, Fehlermeldungen, Serial.Output ...)
4. Eine Frage stellen bzw. erklären was man erwartet

sayali07

I have 3 phase DC1040 pid controller .I want to read pv value of controller through RS485-ttl module using arduino.The meter details is baud rate =38400
                                           pv register=139
this is my code
///////////////////////////////////////////////////////////////

#include <SimpleModbusMaster.h>

//////////////////// Port information ///////////////////
#define baud 38400
#define timeout 1000 
#define polling 300 // the scan rate
#define retry_count 50

// used to toggle the receive/transmit pin on the driver
#define TxEnablePin 2

// The total amount of available memory on the master to store data
#define TOTAL_NO_OF_REGISTERS 13

// This is the easiest way to create new packets
// Add as many as you want. TOTAL_NO_OF_PACKETS
// is automatically updated.
enum
{
  PACKET1,
  PACKET2,
  PACKET3,
  PACKET4,
  TOTAL_NO_OF_PACKETS // leave this last entry
};

// Create an array of Packets to be configured
Packet packets[TOTAL_NO_OF_PACKETS];

// Masters register array
unsigned int regs[TOTAL_NO_OF_REGISTERS];

void setup()
{
  // Initialize each packet
  Serial.begin(38400);
 
  modbus_construct(&packets[PACKET1], 1, READ_INPUT_REGISTERS, 139, 1, 10);
 // modbus_construct(&packets[PACKET2], 1, READ_HOLDING_REGISTERS, 0000, 1, 11);
  //modbus_construct(&packets[PACKET4], 1, READ_HOLDING_REGISTERS, 1, 1, 12);
  //modbus_construct(&packets[PACKET1], 1, PRESET_MULTIPLE_REGISTERS,1, 1,0);
 
  // Initialize the Modbus Finite State Machine
  modbus_configure(&Serial, baud, SERIAL_8N1, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS, regs);
 
 
}

void loop()
{
  modbus_update();
  float pv;
  pv = regs[10];

  delay(1000);
  Serial.print("requests: ");   
  Serial.println(packets[PACKET1].requests);
  Serial.print("successful_requests: "); 
  Serial.println(packets[PACKET1].successful_requests);
  Serial.print("failed_requests: "); 
  Serial.println(packets[PACKET1].failed_requests); 
  Serial.print("exception_errors: "); 
  Serial.println(packets[PACKET1].exception_errors);
  Serial.print("pv: "); 
  Serial.println(regs[10]);                         
}       
//////////////////////////////////////////////////////////////

when i run this code no output is o..
 

noiasca

when i run this code no output is o..
If you wonder, why you haven't got any response so far, rephrase your qestion please.

Be more specific:
-What output do you get (copy-paste the serial monitor output using code tags)
-Write which values you expect instead.
-Provide a link of the datasheet of your device, where we can see the registers and functions of your device



DE: Wie man Fragen postet:
1. was hat man (Sketch und Hardware)
2. was SOLL es machen
3. was macht es: IST (Fehlverhalten, Fehlermeldungen, Serial.Output ...)
4. Eine Frage stellen bzw. erklären was man erwartet

sayali07

Hello,

I want to read data from a DC 1040 PID Controller, with my Arduino and I am using RS485-TTL module .  I'am using a simple modbus master library  it's default communication is :

Protocol: MOdBUS RTU 
Baud Rate: 38400
Parity: ODD
Stop Bits: 1
Data Bits: 8

 I want to read PV Value  which is register 138.


this is my code....

Code: [Select]
#include <SimpleModbusMaster.h>
//////////////////// Port information ///////////////////
#define baud 38400
#define timeout 1000 
#define polling 300 // the scan rate
#define retry_count 50

// used to toggle the receive/transmit pin on the driver
#define TxEnablePin 2

// The total amount of available memory on the master to store data
#define TOTAL_NO_OF_REGISTERS 13

// This is the easiest way to create new packets
// Add as many as you want. TOTAL_NO_OF_PACKETS
// is automatically updated.
enum
{
  PACKET1,
  PACKET2,
  PACKET3,
  PACKET4,
  TOTAL_NO_OF_PACKETS // leave this last entry
};

// Create an array of Packets to be configured
Packet packets[TOTAL_NO_OF_PACKETS];

// Masters register array
unsigned int regs[TOTAL_NO_OF_REGISTERS];

void setup()
{
  // Initialize each packet
  Serial.begin(38400);
 
  modbus_construct(&packets[PACKET1], 1, READ_HOLDING_REGISTERS,138, 1, 10);
 // modbus_construct(&packets[PACKET2], 1, READ_HOLDING_REGISTERS, 0000, 1, 11);
  //modbus_construct(&packets[PACKET4], 1, READ_HOLDING_REGISTERS, 1, 1, 12);
  //modbus_construct(&packets[PACKET1], 1, PRESET_MULTIPLE_REGISTERS,1, 1,0);
 
  // Initialize the Modbus Finite State Machine
  modbus_configure(&Serial, baud, SERIAL_8O1, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS, regs);
 
 
}

void loop()
{
  modbus_update();
  float pv;
  pv = regs[10];

  delay(1000);
  Serial.print("requests: ");   
  Serial.println(packets[PACKET1].requests);
  Serial.print("successful_requests: "); 
  Serial.println(packets[PACKET1].successful_requests);
  Serial.print("failed_requests: "); 
  Serial.println(packets[PACKET1].failed_requests); 
  Serial.print("exception_errors: "); 
  Serial.println(packets[PACKET1].exception_errors);
  Serial.print("pv: "); 
  Serial.println(regs[10]);                         
}       
 

 
The following attachment include connection made, datasheet, comm regs mapping,output

noiasca

just as a quick tipp: in the manual page 27 you find

PV
Process Value
008A 138 03H -1999~9999


on page

03 (03H) Reading multiple registers value from slave controller


in the pdf of the library you will find following information:

Function 4 - READ_INPUT_REGISTERS 4 // Reads the binary contents of input registers (3X references) in
the slave. Not writable.


therefore I guess your modbus_construct is wrong.

DE: Wie man Fragen postet:
1. was hat man (Sketch und Hardware)
2. was SOLL es machen
3. was macht es: IST (Fehlverhalten, Fehlermeldungen, Serial.Output ...)
4. Eine Frage stellen bzw. erklären was man erwartet

sayali07

I change the construct in my code ...

Code: [Select]

#include <SimpleModbusMaster.h>[color=#222222][/color]
//////////////////// Port information ///////////////////[color=#222222][/color]
#define baud 38400[color=#222222][/color]
#define timeout 1000  [color=#222222][/color]
#define polling 300 // the scan rate[color=#222222][/color]
#define retry_count 50[color=#222222][/color]
[color=#222222][/color]
// used to toggle the receive/transmit pin on the driver[color=#222222][/color]
#define TxEnablePin 2 [color=#222222][/color]
[color=#222222][/color]
// The total amount of available memory on the master to store data[color=#222222][/color]
#define TOTAL_NO_OF_REGISTERS 13[color=#222222][/color]
[color=#222222][/color]
// This is the easiest way to create new packets[color=#222222][/color]
// Add as many as you want. TOTAL_NO_OF_PACKETS[color=#222222][/color]
// is automatically updated.[color=#222222][/color]
enum[color=#222222][/color]
{[color=#222222][/color]
  PACKET1,[color=#222222][/color]
  PACKET2,[color=#222222][/color]
  PACKET3,[color=#222222][/color]
  PACKET4,[color=#222222][/color]
  TOTAL_NO_OF_PACKETS // leave this last entry[color=#222222][/color]
};[color=#222222][/color]
[color=#222222][/color]
// Create an array of Packets to be configured[color=#222222][/color]
Packet packets[TOTAL_NO_OF_PACKETS];[color=#222222][/color]
[color=#222222][/color]
// Masters register array[color=#222222][/color]
unsigned int regs[TOTAL_NO_OF_REGISTERS];[color=#222222][/color]
[color=#222222][/color]
void setup()[color=#222222][/color]
{[color=#222222][/color]
  // Initialize each packet[color=#222222][/color]
  Serial.begin(38400);[color=#222222][/color]
  [color=#222222][/color]
  modbus_construct(&packets[PACKET1], 1, READ_MULTIPLE_REGISTERS,138, 1, 10);[color=#222222][/color]
 [color=#222222][/color]
  // Initialize the Modbus Finite State Machine[color=#222222][/color]
  modbus_configure(&Serial, baud, SERIAL_8O1, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS, regs);[color=#222222][/color]
  [color=#222222][/color]
  [color=#222222][/color]
}[color=#222222][/color]
[color=#222222][/color]
void loop()[color=#222222][/color]
{[color=#222222][/color]
  modbus_update();[color=#222222][/color]
  float pv;[color=#222222][/color]
  pv = regs[10];[color=#222222][/color]
[color=#222222][/color]
  delay(1000);[color=#222222][/color]
  Serial.print("requests: ");    [color=#222222][/color]
  Serial.println(packets[PACKET1].requests);[color=#222222][/color]
  Serial.print("successful_requests: ");  [color=#222222][/color]
  Serial.println(packets[PACKET1].successful_requests);[color=#222222][/color]
  Serial.print("failed_requests: ");  [color=#222222][/color]
  Serial.println(packets[PACKET1].failed_requests);  [color=#222222][/color]
  Serial.print("exception_errors: ");  [color=#222222][/color]
  Serial.println(packets[PACKET1].exception_errors); [color=#222222][/color]
  Serial.print("pv: ");  [color=#222222][/color]
  Serial.println(regs[10]);                          [color=#222222][/color]
}       [color=#222222][/color]
 




Still no output.......


please correct me.


noiasca

DE: Wie man Fragen postet:
1. was hat man (Sketch und Hardware)
2. was SOLL es machen
3. was macht es: IST (Fehlverhalten, Fehlermeldungen, Serial.Output ...)
4. Eine Frage stellen bzw. erklären was man erwartet

sayali07

I change my construct in my code..
Code: [Select]
#include <SimpleModbusMaster.h>
//////////////////// Port information ///////////////////
#define baud 38400
#define timeout 1000 
#define polling 300 // the scan rate
#define retry_count 50

// used to toggle the receive/transmit pin on the driver
#define TxEnablePin 2

// The total amount of available memory on the master to store data
#define TOTAL_NO_OF_REGISTERS 13

// This is the easiest way to create new packets
// Add as many as you want. TOTAL_NO_OF_PACKETS
// is automatically updated.
enum
{
  PACKET1,
  PACKET2,
  PACKET3,
  PACKET4,
  TOTAL_NO_OF_PACKETS // leave this last entry
};

// Create an array of Packets to be configured
Packet packets[TOTAL_NO_OF_PACKETS];

// Masters register array
unsigned int regs[TOTAL_NO_OF_REGISTERS];

void setup()
{
  // Initialize each packet
  Serial.begin(38400);
 
  modbus_construct(&packets[PACKET1], 1, READ_MULTIPAL_REGISTERS,138, 1, 10);
 
  // Initialize the Modbus Finite State Machine
  modbus_configure(&Serial, baud, SERIAL_8O1, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS, regs);
 
 
}

void loop()
{
  modbus_update();
  float pv;
  pv = regs[10];

  delay(1000);
  Serial.print("requests: ");   
  Serial.println(packets[PACKET1].requests);
  Serial.print("successful_requests: "); 
  Serial.println(packets[PACKET1].successful_requests);
  Serial.print("failed_requests: "); 
  Serial.println(packets[PACKET1].failed_requests); 
  Serial.print("exception_errors: "); 
  Serial.println(packets[PACKET1].exception_errors);
  Serial.print("pv: "); 
  Serial.println(regs[10]);                         
}       
 


Please correct me if anything else..

Go Up