• Currently I'm developing an Espruino module for MLX90614 - an infra red thermometer I2C sensor.
    https://learn.adafruit.com/using-melexis-mlx90614-non-contact-sensors/overview
    It's nearly complete but I have strange problems with the initialisation. I figured out that the sensor always works when the power supply will be switched on after I2C1.setup(..)-call. So I have connected Vin of the sensor with B3 to simulate switching on/off programmatically.
    The following code works without any problems:

    I2C1.setup( { scl: B6, sda: B7 } );
    digitalWrite( B3, 1 ); // Power on after I2C1.setup(..)
    
    function start() {
      I2C1.writeTo( { address: 0x5a, stop: false }, 0x06 ); // repeated start I2C requests
      var d = I2C1.readFrom( 0x5a, 3 );
    
      var temp = ((d[1] << 8) + d[0]) * 0.02 - 273.15; // formula from datasheet
      console.log( "Temperature = " + temp + "°C" );
    }
    
    setTimeout( start, 250 ); // Sensor available 1/4 sec after POR
    

    But now strange things happen. The following code works only one or two times after connecting the USB cable and then never again.

    digitalWrite( B3, 1 ); // Power on before I2C1.setup(..)
    I2C1.setup( { scl: B6, sda: B7 } );
    
    function start() {
      I2C1.writeTo( { address: 0x5a, stop: false }, 0x06 );
      var d = I2C1.readFrom( 0x5a, 3 );
    
      var temp = ((d[1] << 8) + d[0]) * 0.02 - 273.15; // formula from datasheet
      console.log( "Temperature = " + temp + "°C" );
    }
    
    setTimeout( start, 250 ); // Sensor available 1/4 sec after POR
    

    Instead of Temperature = 22.37°C an exception is thrown:

    Uncaught InternalError: Timeout on I2C Write BUSY
     at line 14 col 51
    i2c.writeTo( { address: 0x5a, stop: false }, 0x06 );
                                                      ^
    in function called from system
    

    I have no ideas anymore how to find the cause. I don't have a memory oscilloscope and can't say what happens during "I2C1.setup(..)".
    Does anybody have an idea how I could continue...?

About

Avatar for luwar @luwar started