I2C write error: -1 on i2c89 after power failure


#1

I have an Electric Imp impExplorer Kit and it was running fine until I tried to let it run till failure on batteries to see how long it would last. I’m pulling temperature & humidity from the onboard sensors. Since I plugged it in I now get the following errors:

|2018-05-04 16:08:47 -04:00|[Status]|Device connected| |—|---|—|
|2018-05-04 16:08:48 -04:00|[Device]|ERROR: I2C write error: -1|
|2018-05-04 16:08:48 -04:00|[Device]|ERROR: in _setReg …mp#hts221.device.lib.nut#2.0.1:239|
|2018-05-04 16:08:48 -04:00|[Device]|ERROR: from _getCalibrationVariables …mp#hts221.device.lib.nut#2.0.1:251|
|2018-05-04 16:08:48 -04:00|[Device]|ERROR: from constructor …mp#hts221.device.lib.nut#2.0.1:86|
|2018-05-04 16:08:48 -04:00|[Device]|ERROR: from main device_code:20|
|2018-05-04 16:08:53 -04:00|[Status]|Device disconnected|

Line 20 refers to the I2c initilization:
tempHumid <- HTS221(hardware.i2c89);

Code was running fine and I suspect the power failure caused it. Any toughts on fixing the issue? I’ll try to grab another imp on Monday to validate that the code is not problem.

Here’s the code until the device fails and reboots:
#require “HTS221.device.lib.nut:2.0.1”
#require “LPS22HB.device.lib.nut:2.0.0”
#require “LIS3DH.device.lib.nut:2.0.1”
#require “WS2812.class.nut:3.0.0”

//LED variables
spi <- null;
led <- null;
state <- false;

hardware.i2c89.configure(CLOCK_SPEED_400_KHZ);
server.log(hardware.i2c89.readerror());
//tempHumid <- HTS221(hardware.i2c89, 0xBE);
tempHumid <- HTS221(hardware.i2c89);


#2

Hello,
I had the same problem a few days ago.
I suppose, that with the last update of the libraries, some initialization parameters the sinxtaxis has changed.

https://forums.electricimp.com/t/libraries-failed/5568

I hope I help you in something


#3

I did see your thread, would you mind posting how do you initialize your HTS221? The setmode configuration that was problematic is done after your temphumid declaration.


#4

This is the device code…

#require “HTS221.device.lib.nut:2.0.1”
#require “LPS22HB.device.lib.nut:2.0.0”

data <- {};
data.temp <- 0;
data.humid <- 0;
data.pressure <-0;

hardware.i2c89.configure(CLOCK_SPEED_400_KHZ);

// Temperature and humidity sensor
tempHumid <- HTS221(hardware.i2c89);
local dataRate = tempHumid.setMode(HTS221_MODE.ONE_SHOT);

//pressure sensor
pressureSensor <- LPS22HB(hardware.i2c89);
pressureSensor.softReset();

function mainLoop() {

pressureSensor.read(function(result) {
   data.pressure = result.pressure; 

    tempHumid.read(function(result) {
        
       data.temp = result.temperature;
     data.humid = result.humidity;
        
        agent.send("saveValue", data);
         imp.wakeup(60, mainLoop);
    }); 

});

}

mainLoop();


#5

Thanks, I tried your code and I get the same results. If looks like if I initiate only the pressure sensor it sometimes works but anytime I initiate the temperature sensor I get the error. I read somewhere else that the I2c bus could blocked.


#6

As noted here: https://developer.electricimp.com/resources/i2cerrors , -1 indicates the device cannot start the I2C transaction.

Any bus lock (generally caused by a transaction aborting midway through a byte) would be cleared by a power cycle. The bus is a shared resource, so if it was locked you’d be unable to talk to any peripherals.

Your code at the top of the thread is not, however, going to show any useful errors. Calling readerror() when there have been no transactions on the bus will return bogus data - nothing has happened so there’s no data to return.

Try this, and tell me what it logs:

// Try to talk to HTS221
hardware.i2c89.configure(CLOCK_SPEED_400_KHZ);
server.log(hardware.i2c89.write(0xbe, "");

Note that if you want long battery life (years) you will need to use deep sleep.


#7

When I tried to write to Ic2 using this command line I get a -1 error logged. I also tried writing to 0xBA with the same result


#8

New unit works, I suspect the other one had a manufacturing defect. On top of the I2c issues the readings were weird (68% RH in my house!). This one reads 38% which makes more sense.