• The error message

    Uncaught InternalError: Timeout on I2C Read Receive

    The usual suspect are pull up resistors
    Other causes

    You send a command via I2C that causes the device to require a delay before it is ready to talk I2C again.
    Examples for the BNO055 are reset, change clock between internal and external

    One solution is to use a callback
    Is there a way to throw and catch the error and then try again N times or until the error clears?
    function start(){
    // define the I2C connection
     I2C3.setup({ scl :A8, sda: B4} );
    // define the bus address of the BNO055 chip
     var BusAddress= 0x28;//If ADR pin at 3V 0x29
    //load the BMO055 module  
     W=require("BNO055").connect(I2C3,BusAddr­ess,function(){
    
    // set the BNO055 clock to external using a callback funtion
    W.External_Clk(1,function(){
    
    //the callback code goes here
    });//end set external clock 
     });//end require
    }//end start
    

    The external clock function with callback

    BNO055.prototype.External_Clk=function(a­,callback){
     this.selectPage(0);
     if(a)
     this.WriteByte(this.Page0Regs.SYS_TRIGGE­R,0x80);
     else
     this.WriteByte(this.Page0Regs.SYS_TRIGGE­R,0x00);
    setTimeout(function () {
       callback();
    }, 50);
    };
    
  • If you do:

    try {
      I2C3.readFrom(...);
    } catch (e) {
      console.log("Oops");
    }
    

    then it should work? your inability to catch the error might be because your External_Clk function is itself called from a timeout?

    Worst case you can use uncaughtException, but that's a bit of a hack :) http://www.espruino.com/Reference#l_proc­ess_uncaughtException

  • Thanks @Gordon for the prompt reply.
    I'll try your suggestions later today.
    It may be a bit more complex but that makes it fun. (see snippet)
    Send reset or change clock and then catch the error and retry on a subsequent read of a status register using the snippet.

    /** Readbyte(BusAddress,SubAddress) */
    BNO055.prototype.ReadByte=function(subAd­dress){
     var data=Uint8Array(1);
     this.i2c.writeTo(this.BusAddress, subAddress);
     data=this.i2c.readFrom(this.BusAddress, 1);
     return data[0];
    };//end ReadByte
    
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

I2C error Is there a way to thow and catch this error?

Posted by Avatar for ClearMemory041063 @ClearMemory041063

Actions