Hi to all, i am a newbie for modbus protocol and i want use it for read data from ducati energia smart piu' (it's a enrgy monitoring)
i want use a arduino uno and a max485 chip,
now i use a SimpleModbusMaster version 11, and i write this:
enum
{
PACKET1,
TOTAL_NO_OF_PACKETS // leave this last entry
};
packetPointer packet1 = &packets[PACKET1];
void setup()
{
// 0x13 is the address of data, 2 is the word, the word i 16 bit, this value i read from manual of Ducati Energia
modbus_construct(packet1, 1, READ_HOLDING_REGISTERS, 0x13, 2, readRegs);
modbus_configure(&Serial, baud, SERIAL_8N2, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS);
}
void loop()
{
modbus_update();
lcd.print("requests:");
lcd.print(packet1->requests);
lcd.print("successful_requests: ");
lcd.print(packet1->successful_requests);
lcd.print("failed_requests: ");
lcd.print(packet1->failed_requests);
lcd.print("exception_errors: ");
lcd.print(packet1->exception_errors);
lcd.print("Active energy: ");
lcd.print(readRegs[0]);
delay(2000);
}
but don't work and i have this result
requests: 9
successful_requests: 0
failed_requests: 10
exception_errors:0
Active energy:0
i don't know where is the problem, can you help me?
Best reagrds
J.
#include <SimpleModbusMaster.h>
#include <LiquidCrystal.h>
//////////////////// Port information ///////////////////
#define baud 9600
#define timeout 1000
#define polling 200 // the scan rate
// If the packets internal retry register matches
// the set retry count then communication is stopped
// on that packet. To re-enable the packet you must
// set the "connection" variable to true.
#define retry_count 10
// used to toggle the receive/transmit pin on the driver
#define TxEnablePin 2
//#define LED 9
#define LED 3
// 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,
TOTAL_NO_OF_PACKETS // leave this last entry
};
// Create an array of Packets to be configured
Packet packets[TOTAL_NO_OF_PACKETS];
// Create a packetPointer to access each packet
// individually. This is not required you can access
// the array explicitly. E.g. packets[PACKET1].id = 2;
// This does become tedious though...
packetPointer packet1 = &packets[PACKET1];
//packetPointer packet2 = &packets[PACKET2];
// Data read from the arduino slave will be stored in this array
// if the array is initialized to the packet.
unsigned int readRegs[1];
// Data to be written to the arduino slave
//unsigned int writeRegs[1];
LiquidCrystal lcd(12, 11, 9, 8, 7, 6); // LCD configuration
void setup()
{
// read 1 register starting at address 0
// 0x13 is the address of data, 2 is the word, the word i 16 bit, this value i read from manual of Ducati Energia
modbus_construct(packet1, 1, READ_HOLDING_REGISTERS, 0x13, 2, readRegs);
// configuration
modbus_configure(&Serial, baud, SERIAL_8N2, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS);
pinMode(LED, OUTPUT);
}
void loop()
{
modbus_update();
lcd.print("requests:");
lcd.print(packet1->requests);
lcd.print("successful_requests: ");
lcd.print(packet1->successful_requests);
lcd.print("failed_requests: ");
lcd.print(packet1->failed_requests);
lcd.print("exception_errors: ");
lcd.print(packet1->exception_errors);
lcd.print("Active energy: ");
lcd.print(readRegs[0]);
delay(2000);
}
What about providing the necessary information? A link to the library used, the hardware on the other side (datasheet) and a diagram or photo of the wiring would be a good starting point.
Do you really think that configuring the ModBus library after you already used it (that's how you do it in setup()) makes sense?
in this link MassaBUS incontra Arduino - Massari Electronics you can read
the scematic,
i connect whit a tisted wire the A connector of shiled and A connector of Energy monitoring and the B connector of shiled with B connector of Energy monitoring.
The energy monitor is work well because i use a "TCP/IP Ethernet to Serial RS232 RS485 RS422 Converter" for comunicat with it,
i use this program: modpoll
modpoll -1 -f -m enc $IP -p $PORT -a $ADDR -c $CARD -r $PARAM
this is my configuration: