mobus protcol Addess

Dear all.

I have attached my code below . I have few question here.

http://arduino.cc/en/Reference/WordCast

question are:

  1. I have value latitude 13.08. Here 13 should put in lower byte of word and 08 into higher order of byte address. How to assign it

2)i have analog sensor which read analog voltage 0-5v . that being converted from +75 deg to -75 degree.

from 0-75 degree i can read value properly on QMODBUS, But 0 to -75 master varying with 65561 value.How to covert it to -ve value.

  1. IS it possible to assign our own slave address in below code
#define ID   1
Modbus slave(ID, 0, 0);
boolean led;
int8_t state = 0;
unsigned long tempus;
// data array for modbus network sharing
uint16_t au16data[9];

float latitude=13.08;
static int Sensor_Value;
float Yvoltage;
static float ARDUINO_ANALOG_SCALING = 0.00488758;
static float Ydegree;


void setup() {
  // define i/o
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  pinMode(4, INPUT);
  pinMode(5, INPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(13, OUTPUT);

  digitalWrite(6, LOW );
  digitalWrite(7, LOW );
  digitalWrite(8, LOW );
  digitalWrite(9, LOW );
  digitalWrite(13, HIGH );
  

  // start communication
  slave.begin( 9600 );

  tempus = millis() + 100;
  digitalWrite(13, HIGH );
}


void loop() {
  // poll messages
  // blink led pin on each valid message
  state = slave.poll( au16data, 9 );
  if (state > 4) {
    tempus = millis() + 50;
    digitalWrite(13, HIGH);
  }
  if (millis() > tempus) digitalWrite(13, LOW );

  
  // read analog inputs
  
   Sensor_Value=analogRead(A0); 
  Yvoltage = Sensor_Value * ARDUINO_ANALOG_SCALING;
   Ydegree=(30*Yvoltage)-75;
/*  mySerial.println(Ydegree);
  delay(1000);*/
  au16data[0] = Ydegree;
 //  au16data[1]=latitude;
word(au16data[1],latitude);
//word(au16data[1]);
  // diagnose communication
  au16data[6] = slave.getInCnt();
  au16data[7] = slave.getOutCnt();
  au16data[8] = slave.getErrCnt();
}

Part 1:

#include <math.h>

int main(void)
{
	double fLat = 13.08;
	uint16_t latitude = 0;
	double whole = 0;
	uint8_t frac = 0;
        // Split into integer and fraction parts
	frac= (uint8_t)(modf(fLat, &whole) * 100);
        // Recombine
	latitude = (uint8_t)whole  + (uint8_t)(frac*100 * 256);

	return 0;
}

Don’t understand parts 2&3

lyndon:
Don’t understand parts 2&3

Nobody understands it...

part 2 says. I have analog sensor which read value from 0-5v , -75 deg to 75 degreee.

0v means -75 deg

5v means 75 degree

here 2.5v to 5v it reads properly it reads 0-75 degree

in between 0-2.5v it modbus reading which are -ve 65512 values. How to make it readable format

My guess from what you have cryptically stated here is that your analog sensor is being read by a 16-bit A/D converter outputting data in 2’s complement format. Therefore, the numbers above 32767 represent negative values. Is this correct?

If so, using a signed instead of an unsigned integer variable (au16data) should solve your problem.

AJITnayak:
part 2 says. I have analog sensor which read value from 0-5v , -75 deg to 75 degreee.

0v means -75 deg

5v means 75 degree

here 2.5v to 5v it reads properly it reads 0-75 degree

in between 0-2.5v it modbus reading which are -ve 65512 values. How to make it readable format