Hi everyone, I´m trying to read the data from a solar sensor, the solarMems MASS60.
To do it I'm using an arduino Mega and the MAX485 conversor.
I save al the data in a vector that I call au16data[22] , the thing is that when I read for example the model, the reference, ot the elevation I obtain values that seems okey. But on the other hand when reading the radiation (au16data[8]) it always shows 0, and also reading the temperatura it shows randomly 3100 and 64917.
I cant understand why if I read some information right I have problem reading others.
This is the code I´m using:
#include <ModbusRtu.h>
// declaracion de variables
uint16_t au16data[22]; // array de datos
uint8_t u8state; //estado de maquina
uint8_t u8query; //puntero query message
// fin declaracion de variables
// configuracion
/**
* Modbus object declaration
* u8id : node id = 0 for master, = 1..247 for slave
* u8serno : serial port (use 0 for Serial)
* u8txenpin : 0 for RS-232 and USB-FTDI
* or any pin number > 1 for RS-485
*/
Modbus master(0,1,10); //cambio el del medio por1, estaba en 0
//fin configuracion
//this is a structure which contains a query to a slave device
modbus_t telegram;
//fin
unsigned long u32wait; //timer for the modbus
void setup() {
pinMode(SSerialTxcontrol,OUTPUT);
//telegram 0:read registers
telegram.u8id=1; //slave address
telegram.u8fct=3; //function code (registers read)
telegram.u16RegAdd=1; //start address in slave estaba a cero
telegram.u16CoilsNo=22; //number of coils or registers to read
telegram.au16reg=au16data; //pointer to a memory array in the Arduino
master.begin(19200,SERIAL_8N1); //baud-rate at 19200
master.setTimeOut(5000); //if there is no anwers roll over
u32wait=millis()+1000;
u8state=u8query=0;
//comunicacion serie
Serial.begin(19200);
}
void loop() {
switch(u8state) {
case 0:
if(millis()>u32wait) u8state++; //wait state
break;
case 1:
master.query(telegram);//send query only once
u8state++;
break;
case 2:
master.poll(); //check incoming messages
if (master.getState() == COM_IDLE) {
u8state ++;
u32wait=millis()+1000;}
break;
case 3:
u8state=0;
Serial.print("identificador : ");
Serial.println(au16data[0]);
Serial.print("FOV : ");
Serial.println(au16data[1]);
Serial.print("MODELO : ");
Serial.println(au16data[2]);
Serial.print("REF : ");
Serial.println(au16data[3]);
Serial.print("BIT ");
Serial.println(au16data[4]);
Serial.print("PARITY: ");
Serial.println(au16data[5]);
Serial.print("STOP : ");
Serial.println(au16data[6]);
Serial.print("ADITIONAL ");
Serial.println(au16data[7]);
Serial.print("RAD ");
Serial.println(au16data[8]);
Serial.print("TEMP ");
Serial.println(au16data[9]);
Serial.print("AZ : ");
Serial.println(au16data[14]);
Serial.print("ELEV : ");
Serial.println(au16data[15]);
Serial.print("ACEL Z");
Serial.println(au16data[22]);
Serial.println("_____________________");
delay(2000);
break;
}
}
I attach some other information, as the wiring, datasheets or the values from the sensor I read.
Thank you very much, I hope someone can help me.
MASS_Technical_Specifications.pdf (631 KB)