B4R Question Is WriteTo2 equivalent to a i2c repeat start?

fredeady

Member
Licensed User
Longtime 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.
 

fredeady

Member
Licensed User
Longtime 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();
}
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…