<solved>Modbus Lib example Compile error

Dear all,
I have Below code Downloaded From library function below. I am getting Below error.
https://code.google.com/p/simple-modbus/downloads/detail?name=SimpleModbusSlaveV7.zip&can=2&q=

#include <SimpleModbusSlave.h>

/* This example code will receive the adc ch0 value from the arduino master. 
   It will then use this value to adjust the brightness of the led on pin 9.
   The value received from the master will be stored in address 1 in its own
   address space namely holdingRegs[].
   
   In addition to this the slaves own adc ch0 value will be stored in 
   address 0 in its own address space holdingRegs[] for the master to
   be read. The master will use this value to alter the brightness of its
   own led connected to pin 9.
   
   The modbus_update() method updates the holdingRegs register array and checks
   communication.

   Note:  
   The Arduino serial ring buffer is 128 bytes or 64 registers.
   Most of the time you will connect the arduino to a master via serial
   using a MAX485 or similar.
 
   In a function 3 request the master will attempt to read from your
   slave and since 5 bytes is already used for ID, FUNCTION, NO OF BYTES
   and two BYTES CRC the master can only request 122 bytes or 61 registers.
 
   In a function 16 request the master will attempt to write to your 
   slave and since a 9 bytes is already used for ID, FUNCTION, ADDRESS, 
   NO OF REGISTERS, NO OF BYTES and two BYTES CRC the master can only write
   118 bytes or 59 registers.
 
   Using a USB to Serial converter the maximum bytes you can send is 
   limited to its internal buffer which differs between manufactures. 
*/

#define  LED 9  

// Using the enum instruction allows for an easy method for adding and 
// removing registers. Doing it this way saves you #defining the size 
// of your slaves register array each time you want to add more registers
// and at a glimpse informs you of your slaves register layout.

//////////////// registers of your slave ///////////////////
enum 
{     
  // just add or remove registers and your good to go...
  // The first register starts at address 0
  ADC_VAL,     
  PWM_VAL,        
  HOLDING_REGS_SIZE // leave this one
  // total number of registers for function 3 and 16 share the same register array
  // i.e. the same address space
};

unsigned int holdingRegs[HOLDING_REGS_SIZE]; // function 3 and 16 register array
////////////////////////////////////////////////////////////

void setup()
{
  /* parameters(HardwareSerial* SerialPort,
                long baudrate, 
		unsigned char byteFormat,
                unsigned char ID, 
                unsigned char transmit enable pin, 
                unsigned int holding registers size,
                unsigned int* holding register array)
  */
  
  /* Valid modbus byte formats are:
     SERIAL_8N2: 1 start bit, 8 data bits, 2 stop bits
     SERIAL_8E1: 1 start bit, 8 data bits, 1 Even parity bit, 1 stop bit
     SERIAL_8O1: 1 start bit, 8 data bits, 1 Odd parity bit, 1 stop bit
     
     You can obviously use SERIAL_8N1 but this does not adhere to the
     Modbus specifications. That said, I have tested the SERIAL_8N1 option 
     on various commercial masters and slaves that were suppose to adhere
     to this specification and was always able to communicate... Go figure.
     
     These byte formats are already defined in the Arduino global name space. 
  */
	
  modbus_configure(&Serial, 9600, SERIAL_8N2, 1, 2, HOLDING_REGS_SIZE, holdingRegs);    
  
  pinMode(LED, OUTPUT);
}

void loop()
{
  // modbus_update() is the only method used in loop(). It returns the total error
  // count since the slave started. You don't have to use it but it's useful
  // for fault finding by the modbus master.
  
  modbus_update();
  
  holdingRegs[ADC_VAL] = analogRead(A0); // update data to be read by the master to adjust the PWM
  
  analogWrite(LED, holdingRegs[PWM_VAL]>>2); // constrain adc value from the arduino master to 255
  
  /* Note:
     The use of the enum instruction is not needed. You could set a maximum allowable
     size for holdinRegs[] by defining HOLDING_REGS_SIZE using a constant and then access 
     holdingRegs[] by "Index" addressing. 
     I.e.
     holdingRegs[0] = analogRead(A0);
     analogWrite(LED, holdingRegs[1]/4);
  */
  
}

Use a newer IDE (current is 1.0.5). As far as I remember the serial bit options weren't available before around version 1.0.4.

I don't understand what you're asking. What output do you want to check?

I have Rs485 to rs232 Device

So your PC runs the Modbus master?

or below data i could able to receive data

What data, you just posted an example sketch. BTW, you didn't provide links to the libraries you used.

What kind of Modbus software are you running on the PC?

Maybe the more important question: what do you want to achieve? What's the goal of your project?

modbus_configure(&Serial, 9600, SERIAL_8N2, 1, 2, HOLDING_REGS_SIZE, holdingRegs);

You configure your Arduino to communicate with 9600 baud but in the software on your PC you configure 38400 baud. Do you really expect that they understand each other?

I have also downloaded

Google Code Archive - Long-term storage for Google Code Project Hosting.. It compile ,and downloaded , But i am getting any values recorded in my software.

AMPS-N:
Error message

SimpleModbusSlaveArduino.cpp: In function 'void setup()':

SimpleModbusSlaveArduino:79: error: 'SERIAL_8N2' was not declared in this scope

I told you earlier that you should install the new IDE version but you seem to ignore almost anything I write. Do you want to get help or do you just want to complain a bit?

i have installed new version of IDE v1.0.5

by changing library function. I uploaded to board. But i am not getting any response from slave

Have you changed the parameters so that the values on the PC and the Arduino match? Post the sketch you uploaded (exactly as you did, so not an external link) and new screenshots if you changed the parameters in the PC software.

Excuse me but your posts sound a bit like: "I connected my computer with a wall-socket but I don't get Internet".

ModBus is not (yet) a plug-and-play technology so you have dig a bit into the technology, read at least the basic documents and know the basics of the terminology. I'm definitely no expert in ModBus, I not even used one myself yet, but just from the readings I've done to evaluate a bus system for another project I seem to know much more about it than you who is using it.

Your sketch does not compile because Modbus is not defined. There is no include of a ModBus library nor is the code contained in the sketch. If you use a library tell us which one you use (if you already provided a link to it) or post the link if it's not yet in this topic.

I have compile successfully on v1.0.5. Here i am attaching code again. It five CRC error check error . But it implemented code. @ aend

au16data[6] = slave.getInCnt();
  au16data[7] = slave.getOutCnt();
  au16data[8] = slave.getErrCnt();] au16data[6] = slave.getInCnt();
  au16data[7] = slave.getOutCnt();
  au16data[8] = slave.getErrCnt()

being used to check CRC code. But when i try to aquire data by q modbus . it is found that CRC section is missing in master Request

modbus.rar (5.81 KB)

Do you have access to a logic analyzer? If not, do you have an Arduino with more than one (virtual) serial interface (Mega, Leonardo, etc.)?
You PC program seems to only receive zeros from the ModBus. This is either a hardware problem (wrong wiring, defective adapter, etc.) or the sketch is not really running on the Arduino and the PC is interpreting that incorrectly.

I am planning to purchase below product from sparkfun . Since i found the Lot of issue building modbus circuit. Is there any library associated with below product.

RS485 Shield - DEV-11959 - SparkFun Electronics

AMPS-N:
I am planning to purchase below product from sparkfun . Since i found the Lot of issue building modbus circuit. Is there any library associated with below product.

RS485 Shield - DEV-11959 - SparkFun Electronics

No, because you don't need a specific library for this product. Even the read/write switch is implemented automatically, so you don't have to use pin 3 handling in your current code.

i have current setup

rs485 - Arduino as modbus master with MAX485 doesn't get any response - Electrical Engineering Stack Exchange

Please post a picture of the setup where all wiring is visible.

Intially i tried with chip it didn’t worked . SO i have now RS485 shield like sparkfun. IT stack on Arduino uno board. I am thinking here dont require schematic. You can also refer schematic in link provided itself.

I am getting Error for Every code i tried from forum. Every code successfully compile .
Error i have got as below:

  1. could not able to receive data from slave
  2. Slave through exception, improper CRC is implemented.

Here i am attaching all trial code which compile successfully. But above error.i think there no hardware issue i am using this shield. I am using Qmodbus software which acts as Master.

I have setup with below software
1)http://www.ebay.com/bhp/usb-to-rs485-adapter from PC to MODBUS DEVICE
2)[https://www.sparkfun.com/products/11959]https://www.sparkfun.com/products/11959]https://www.sparkfun.com/products/11959](https://www.sparkfun.com/products/11959)for modbus communication
3)http://qmodbus.sourceforge.net/ software to view data. My PC acts as Master.

MODBUS CODE.rar (10.2 KB)

SO i have now RS485 shield like sparkfun.

Is it like the one from Sparkfun or is it the one from Sparkfun? If it's not from Sparkfun, provide schematics for it.

  1. could not able to receive data from slave

I thought the Arduino should be the slave, so if you got this error on the Arduino, you loaded master code, which isn't expected to work here. If I misinterpreted you here, please be more specific about what you've done and what the result was. Most of the your previous posts gave me the impression that you want to hide some information from us and you're just complaining about a setup not working. If you don't give us the necessary information we cannot help you.
In the previous posts you never had a setup described that really matched the other side. For example, if you have different baud rates on the two sides of the communication you'll never get any real data through.

  1. Slave through exception, improper CRC is implemented.

Did it really return a CRC or just zeros, in which case the transmission failed and not the CRC calculation.

1)Shop by Category | eBay from PC to MODBUS DEVICE

That's a whole category of devices, not a specific one.

I'm still waiting for you to post a photograph of your setup (with all wiring visible). The make a screenshot of the Qmodbus software as you're trying with. And post the code you uploaded to the Arduino for the tests. This information has to show your setup and not a setup that you think you made your's a duplicate of.

Is it like the one from Sparkfun or is it the one from Sparkfun? If it's not from Sparkfun, provide schematics for it.

It is from Sparkfun only.

I thought the Arduino should be the slave, so if you got this error on the Arduino, you loaded master code, which isn't expected to work here. If I misinterpreted you here, please be more specific about what you've done and what the result was. Most of the your previous posts gave me the impression that you want to hide some information from us and you're just complaining about a setup not working. If you don't give us the necessary information we cannot help you.
In the previous posts you never had a setup described that really matched the other side. For example, if you have different baud rates on the two sides of the communication you'll never get any real data through.

I have uploaded the code of slave downloaded from various website. So i am trying to any one slave library(modified ) to get it worked on Arduino. Those files are attached in Previous
Posted on: April 07, 2014, 10:47:22 pm on this site.

Did it really return a CRC or just zeros, in which case the transmission failed and not the CRC calculation.

yes i am getting all zero . the images also attached in previous threads.

I'm still waiting for you to post a photograph of your setup (with all wiring visible). The make a screenshot of the Qmodbus software as you're trying with. And post the code you uploaded to the Arduino for the tests. This information has to show your setup and not a setup that you think you made your's a duplicate of.

These information already provided. Please refer previous thread in image. Previously tried with IC and it circuit attached in previous threads . Now instead of testing with IC i am using shield here. SO no point of posting picture.

Please refer previous thread in image. Previously tried with IC and it circuit attached in previous threads . Now instead of testing with IC i am using shield here. SO no point of posting picture

You posted a diagram of how you think you wired it. Where humans work errors happen and as I suppose you are a human being...
We never saw a photograph of how you wired it. Experience shows that wiring problems are often seen so I usually cross check. I apologize if you are perfect and never fail.

time hh/mm/sec and date: dd/mm/ss format as follow. these are coming out in form DS1307

They are coming out in bits and bytes from the chip. If you are using a library you never told us which one and this information is relevant because there are dozens of libraries for this chip.

I have floating value like latitude=13.08 , i can read only 13 here .from master.

uint16_t au16data[9];

You defined the registers to be integers so why do you expect the master to read anything else?

i have connected analog device to port 0 , if tried to vary reading refelcted in master. one weird problem is if analog output is not change then also values being get updated in modbus. I have used simple potentiometer network.

I don't understand what the problem is. Do you mean that the read value changes although you didn't turn the potentiometer? How much does the value change? What circuit is connected (diagram or photo)?

They are coming out in bits and bytes from the chip. If you are using a library you never told us which one and this information is relevant because there are dozens of libraries for this chip.

i converted into decimal format.

You defined the registers to be integers so why do you expect the master to read anything else?

that s reason i am trying to convert float value to integer parameter

Potentiometer working fine. it doesn't changes that much as it has offset of +1 v . initially it is +2v difference