B4R Question Is WriteTo2 equivalent to a i2c repeat start?

Discussion in 'B4R Questions' started by fredeady, Oct 11, 2017.

  1. fredeady

    fredeady New Member Licensed User

    HI,
    Need to read some sensors that require a repeat start condition. Can I use WriteTo2 to initiate a repeat start condition? Using a WeMos D1 Mini.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Can you post a C example?
     
  3. fredeady

    fredeady New Member Licensed User

    Here is a C function to read the color registers of a BH1745 RGB sensor.

    //**********************************************************
    //* Read RGBC Registers via I2C
    //**********************************************************
    void readRGBC(void)
    {
    i2c_start();
    i2c_write(BH1745_WR_ADDR); //slave address
    i2c_write(rgbcDataBegin); //register address
    i2c_start(); //repeated start
    i2c_write(BH1745_RD_ADDR); //slave address
    rgbcRaw[0] = i2c_read(1); //register data - ack
    rgbcRaw[1] = i2c_read(1); //register data - ack
    rgbcRaw[2] = i2c_read(1); //register data - ack
    rgbcRaw[3] = i2c_read(1); //register data - ack
    rgbcRaw[4] = i2c_read(1); //register data - ack
    rgbcRaw[5] = i2c_read(1); //register data - ack
    rgbcRaw[6] = i2c_read(1); //register data - ack
    rgbcRaw[7] = i2c_read(0); //register data - nak
    i2c_stop();
    }
     
  4. Erel

    Erel Administrator Staff Member Licensed User

  5. fredeady

    fredeady New Member Licensed User

    Thanks, Erel :cool:
     
Loading...