You are reading a single comment by @Frida and its replies. Click here to read the full conversation.
  • I have made clock streching for HTU21D.
    I need to get JsError to work. I've tried different header file, but I get compile errors.
    Any help is welcome.

    I made a git clone from @TVE and made some changes to the file: Espruino / targets / esp8266 / i2c_master.c.

    Here are the file:

    [#define](https://forum.espruino.com/sea­rch/?q=%23define) i2c_master_getDD(void) ((GPIO_REG_READ(GPIO_IN_ADDRESS) >> pinSCL) & 1) // PB
    
    /***************************************­*************************************** PB
     * FunctionName : i2c_master_getDD
     * Description  : Internal used function -
     *                    get i2c SCL bit value
     * Parameters   : NONE
     * Returns      : uint8 - SCL bit value
    ****************************************­***************************************/­
    [#if](https://forum.espruino.com/search/­?q=%23if) 0
    LOCAL uint8 CALLED_FROM_INTERRUPT
    i2c_master_getDD(void)
    {
        return (GPIO_REG_READ(GPIO_IN_ADDRESS) >> pinSCL) & 1;
    }
    [#endif](https://forum.espruino.com/sear­ch/?q=%23endif)
    
    /***************************************­***************************************
    
    /***************************************­***************************************
     * FunctionName : i2c_master_readByte
     * Description  : read Byte from i2c bus
     * Parameters   : NONE
     * Returns      : uint8 - readed value
    ****************************************­***************************************/­
    uint8 ICACHE_FLASH_ATTR
    i2c_master_readByte(void)
    {
        uint8 retVal = 0;
        uint8 i;
    
        i2c_master_wait(2);
        i2c_master_setDC(m_nLastSDA, 0);
        i2c_master_wait(4);	// sda 1, scl 0
    
        for (i = 0; i < 8; i++) {
            i2c_master_setDC(1, 0);
            i2c_master_wait(4);	// sda 1, scl 0
            i2c_master_setDC(1, 1);
            i2c_master_wait(3);	// sda 1, scl 1
            uint8 count = 200; // max 50ms/14bit // PB 50000/1000*4=200
            while (i2c_master_getDD()==0 && count--) { // PB 36000/1000*4=144
              i2c_master_wait(1000); // wait 1000/4=250 usec // PB
            };
    		if(count==0) { // PB
              goto error;
            };
            //retVal = (retVal<<1) | (i2c_master_getDC()&1);
            retVal = (retVal<<1) | (i2c_master_getDC()); // PB
        }
        i2c_master_setDC(1, 0);
        i2c_master_wait(2);	// sda 1, scl 0
    
        return retVal;
    error:
      i2c_master_stop();
    //  jsError("> I2C streching too long\n");
      return -1;
    }
    

    Should I mention it is on a esp8266-01 from my Pico kickstarter set.


    1 Attachment

About

Avatar for Frida @Frida started