Go Down

Topic: SimpleModbusSlave primo tentativo (Read 550 times) previous topic - next topic

llluca

Oct 23, 2012, 11:41 am Last Edit: Oct 23, 2012, 11:53 am by llluca Reason: 1
Ciao,
 
Prima prova di Sketch SimpleModbusSlave può funzionare?

Quote

#include <SimpleModbusSlave.h>
#include <OneWire.h>
OneWire  ds(10);  // on pin 10
enum
{      
 TMP1,    
 TOTAL_ERRORS,
 // leave this one
 TOTAL_REGS_SIZE
 
};

unsigned int holdingRegs[TOTAL_REGS_SIZE];

void setup()
{
 modbus_configure(9600, 1, 2, TOTAL_REGS_SIZE);
}

void loop()
{
 float tmp;
 holdingRegs[TOTAL_ERRORS] = modbus_update(holdingRegs);



 holdingRegs[0] = temperatura(tmp);
}


///////////////////////////////////////////////////////////////////////
 //LEGGI Temperatura

float temperatura(float tmp){  
 byte j;
 byte present = 0;
 byte data[12];
 byte addr[8]={16,5,78,183,0,8,0,58};
 float celsius;
ds.reset();
 ds.select(addr);
 ds.write(0x44,1);      
 delay(1000);  

 present = ds.reset();
 ds.select(addr);    
 ds.write(0xBE);      
 for ( j = 0; j< 9; j++) {          
   data [j]  = ds.read();
 }
 

 unsigned int raw = (data[1] <<  8 ) | data[0];
      raw = raw << 3;
raw = (raw & 0xFFF0) + 12 - data[6];
 celsius = (float)raw / 16.0;
 return celsius;

}


Riesco in questo modo a trasmettere la  temperatura float sul registro 0 avente indirizzo 1?


Grazie

Luca

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy