function setConfiguration(refreshRate){
server.log(“Configuration”);
local Hz_LSB;;
switch (refreshRate){
case 0:
Hz_LSB=0x3f;
break;
case 1:
Hz_LSB=0x3e;
break;
case 2:
Hz_LSB=0x3d;
break;
case 4:
Hz_LSB=0x3c;
break;
case 8:
Hz_LSB=0x3b;
break;
case 16:
Hz_LSB=0x3a;
break;
case 32:
Hz_LSB=0x39;
break;
default:
Hz_LSB=0x3e;
}
local defaultConfig_H = 0x46;
local confCheck = 0x55;
local cmd = blob();
local Hz_data = Hz_LSB - 0x55;
local dc_data = defaultConfig_H - 0x55;
//cmd.writen(0x03, 'b');
cmd.writen(Hz_data, 'b');
cmd.writen(Hz_LSB, 'b');
cmd.writen(dc_data, 'b');
cmd.writen(defaultConfig_H, 'b');
ex_en.configure(DIGITAL_OUT, ENABLE);
imp.sleep(0.05);
server.log("Sending:");
server.log(cmd.tostring());
local resp = i2c.write(0x60 << 1, "\x03"+"\x46\xf1\x3a\xe5");
//local resp1 = i2c.read(0x60 << 1, "\x04",1);
server.log("Sending response------------------------------ "+resp);
//resolution = i2c.read >> 4;
server.log("sensor initialized!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
imp.sleep(0.5);
ex_en.configure(DIGITAL_OUT, DISABLE);
}
setConfiguration(16);
ex_en is the a pin in imp that enables I2C
I have to write 4 bytes of data
I receive error
Sending response------------------------------ -3
When I replace the write line with
local resp = i2c.write(0x60 << 1, “”+"");
i get response
Sending response------------------------------ 0
local resp = i2c.write(0x60 << 1, “\x03”+"");
give sresponse
Sending response------------------------------ 0 first time
running again gives Sending response------------------------------ -4 but I did not made any changes in code
and 0 and -4 response keep alternating
I have made all iteration for writing data. nothing worked.
Thanks for the help