F fredeady Member Licensed User Longtime User Oct 11, 2017 #1 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.
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.
Erel B4X founder Staff member Licensed User Longtime User Oct 12, 2017 #2 Can you post a C example? Upvote 0
F fredeady Member Licensed User Longtime User Oct 12, 2017 #3 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
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(); }
Erel B4X founder Staff member Licensed User Longtime User Oct 13, 2017 #4 I think that it will work. You need to set SendStop parameter to False for the first write. Relevant discussion: https://forum.arduino.cc/index.php?topic=385377.0 Upvote 0
I think that it will work. You need to set SendStop parameter to False for the first write. Relevant discussion: https://forum.arduino.cc/index.php?topic=385377.0