D21G Modbus Master

Hi,

I tried to get value from power meter. but nothing is working.

All jumpers are installed.

here the code, someone can help ?

regards

 

#include <Wire.h>
#include <UC1701.h>
#include <Indio.h>
#include <SimpleModbusMaster.h>

/* LCD */
static UC1701 lcd;
const short LCD_BACKLIGHT_PIN = 13;
const short LCD_BACKLIGHT = 4;

/* Slave information */
#define SLAVE_ADDR 5 // slave address
#define SLAVE_BAUD_RATE 9600 // slave speed
#define SLAVE_TIMEOUT 600 // the reply timeout
#define SLAVE_POLLING 1000 // the scan rate
#define SLAVE_RETRY_COUNT 10 // how many times master should retry to send a packet in case of failure
#define RS485_ENABLE_PIN 9 // used to toggle the receive/transmit pin on the driver

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

enum
{
  TYPE,
  TOTAL_NO_OF_PACKETS // automatically updated
};

Packet packets[TOTAL_NO_OF_PACKETS];
unsigned int regs[TOTAL_NO_OF_REGISTERS];

void setup()
{
  // Init LCD
  pinMode(LCD_BACKLIGHT_PIN, OUTPUT); //set backlight pin to output
  analogWrite(LCD_BACKLIGHT_PIN, (map(LCD_BACKLIGHT, 0, 5, 255, 0))); //convert backlight intesity from a value of 0-5 to a value of 0-255 for PWM.
  lcd.begin();
  
  // Initialize each packet
  modbus_construct(&packets[TYPE], SLAVE_ADDR, READ_HOLDING_REGISTERS, 0x8E00, 1, 0);
  
  // Initialize the Modbus Finite State Machine
  modbus_configure(&Serial, SLAVE_BAUD_RATE, SERIAL_8N1, SLAVE_TIMEOUT, SLAVE_POLLING, SLAVE_RETRY_COUNT, RS485_ENABLE_PIN, packets, TOTAL_NO_OF_PACKETS, regs);
  
  }

void loop()
{
  modbus_update();

  lcd.setCursor(0, 1); lcd.print("Active: "); lcd.print(regs[0], DEC);
  lcd.setCursor(0, 2); lcd.print("RQ: "); lcd.print(packets[0].requests, DEC);
  lcd.setCursor(0, 3); lcd.print("RQ success: "); lcd.print(packets[0].successful_requests, DEC);
  lcd.setCursor(0, 4); lcd.print("RQ failed: "); lcd.print(packets[0].failed_requests, DEC);
  lcd.setCursor(0, 5); lcd.print("Exeptions: "); lcd.print(packets[0].exception_errors, DEC);
  lcd.setCursor(0, 6); lcd.print("TOTAL NB Packets: "); lcd.print(TOTAL_NO_OF_PACKETS, DEC);
    
  delay(4000);
}

Armand Fumal
Armand Fumal
12
| 3 1 2
Asked on 10/11/18, 7:35 PM
0
vote
2172 Views

Hi,

You are reading slave register address 0x8e00 = 36352 - are you sure this is the right address? As far as my experience goes, the registers for READ_HOLDING_REGISTERS (function 03) have an offset of 40001, so if you're trying to read e.g. register 40101, the slave index would be 100.

Also SERIAL_8N1 is not conform to Modbus specs, can you double check if your slave requires this.

Can you share the datasheet of the modbus slave so we can have a look.

PS: the LCD backlight pin is 26 on D21G

Tom
Tom
5675
| 1 1 3
Answered on 10/11/18, 11:49 PM
0
vote

Hi Tom, thanks for answer. here is table of Socomec Diris A10(slave) https://www.socomec.com/files/live/sites/systemsite/files/SCP/6_gestion_energie/diris/diris_a10/DIRIS-A-10_COMMUNICATION-TABLE_2018-01_DCG01013_MULTI.html In the table I tried to read 36352 but after your comment about offset I found the same data at 57344. Now I try with 57344 and 17343(minus offset) same result. Parity 8N1 is on both side. thanks

Armand Fumal
on 10/12/18, 6:31 AM

Hi, for testing i suggest you try to read the registers of the first section in that data sheet, product identification. 50004 should correspond to 10003 50005 to 10004 and so on those registers are 16-bit unsigned integers so can be read easily by the library if you want to read other data types you will have to combine them in your code, check out our tips at https://industruino.com/blog/our-news-1/post/modbus-tips-for-industruino-26

Tom
on 10/13/18, 3:23 AM

Thanks.

Armand Fumal
on 10/13/18, 10:31 AM

Hi,

I have found.

First of all, the power is mandatory, I apply +12v on board and now it is working.

and register is 57344, no offset apply in the lib function.

 

thanks

Armand Fumal
Armand Fumal
12
| 3 1 2
Answered on 10/12/18, 6:29 AM
0
vote

Your answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

Ask a Question

Keep Informed

About This Forum

This community is for professionals and enthusiasts of our products and services.

Read Guidelines

Question tools

48 follower(s)

Stats

Asked: 10/11/18, 7:35 PM
Seen: 2172 times
Last updated: 10/12/18, 7:16 AM