I'm trying to interface the OMRON D6F-PH0025AD2, BME280, and a 2004 Display (with an I2C driver) with an ESP32.
Without the D6F on the I2C lines, the others peripherals work perfectly.
Following the datasheet and the application note/manual, I've soldered up the sensor wires to the ESP32 directly (to keep the distance short) for debugging. I used 2 kΩ pullups (these are the ones I had at hand) to 3.3 V.
What I'm observing using CRO is that (only) the SCL is always pulled low at around 0.9 V. The sensor is not getting hot nor is it drawing too much current.
I've added a few println
statements and set the clock to 100 kHz to the demo code given by OMRON. What I'm seeing is wire.available()
is always zero in the i2c_read_reg8
although I should be getting two bytes.
#include <Wire.h>
/* defines */
#define D6F_ADDR 0x6C // D6F-PH I2C client address at 7bit expression
uint8_t conv16_u8_h(int16_t a) {
return (uint8_t)(a >> 8);
}
uint8_t conv16_u8_l(int16_t a) {
return (uint8_t)(a & 0xFF);
}
uint16_t conv8us_u16_be(uint8_t* buf) {
return (uint16_t)(((uint32_t)buf[0] << 8) | (uint32_t)buf[1]);
}
/** <!-- i2c_write_reg16 {{{1 --> I2C write bytes with a 16bit register.
*/
bool i2c_write_reg16(uint8_t slave_addr, uint16_t register_addr,
uint8_t *write_buff, uint8_t len) {
Wire.setClock(100000);
Wire.beginTransmission(slave_addr);
Wire.write(conv16_u8_h(register_addr));
Wire.write(conv16_u8_l(register_addr));
if (len != 0) {
for (uint8_t i = 0; i < len; i++) {
Wire.write(write_buff[i]);
}
}
Wire.endTransmission();
return false;
}
/** <!-- i2c_read_reg8 {{{1 --> I2C read bytes with a 8bit register.
*/
bool i2c_read_reg8(uint8_t slave_addr, uint8_t register_addr,
uint8_t *read_buff, uint8_t len) {
Serial.println("step i2c read reg8 started");
Wire.setClock(100000);
Wire.beginTransmission(slave_addr);
Wire.write(register_addr);
Wire.endTransmission();
Serial.println("now requesting data");
Wire.requestFrom(slave_addr, len);
while (Wire.available() != len) {
Serial.println("Wire.avail != len");
Serial.println(Wire.available(), DEC);
// return true;
}
for (uint16_t i = 0; i < len; i++) {
read_buff[i] = Wire.read();
}
return false;
}
/** <!-- setup {{{1 -->
1. initialize a Serial port for output.
2. initialize an I2C peripheral.
3. setup sensor settings.
*/
void setup() {
Serial.begin(115200);
Serial.println("peripherals: I2C");
Wire.begin(); // i2c master
Serial.println("sensor: Differential pressure Sensor");
delay(32);
// 1. Initialize sensor (0Bh, 00h)
i2c_write_reg16(D6F_ADDR, 0x0B00, NULL, 0);
Serial.println("step 1 done");
}
/** <!-- loop - Differential pressure sensor {{{1 -->
1. read and convert sensor.
2. output results, format is: [Pa]
*/
void loop() {
delay(900);
Serial.println("Entered loop");
// 2. Trigger getting data (00h, D0h, 40h, 18h, 06h)
uint8_t send0[] = {0x40, 0x18, 0x06};
i2c_write_reg16(D6F_ADDR, 0x00D0, send0, 3);
delay(50); // wait 50ms
Serial.println("step 2 done");
// 3. Read data (00h, D0h, 51h, 2Ch) (07h)
uint8_t send1[] = {0x51, 0x2C};
i2c_write_reg16(D6F_ADDR, 0x00D0, send1, 2);
uint8_t rbuf[2];
if (i2c_read_reg8(D6F_ADDR, 0x07, rbuf, 2)) { // read from [07h]
return;
}
uint16_t rd_flow = conv8us_u16_be(rbuf);
float flow_rate;
Serial.println("step 3 done");
// calculation for 0-250[Pa] range
flow_rate = ((float)rd_flow - 1024.0) * 250 / 60000.0;
Serial.print(flow_rate, 2); // print converted flow rate
Serial.println(" [Pa]");
}
I assumed that the sensor was faulty, so I replaced it with a brand new sensor. It has no effect. Both sensors are brand new and I bought them just a few months back from Mouser.
Update
Thanks to everyone helping me till now and sorry for the delay.
To isolate the problem and transferred the sensor and microcontroller to a new protoboard. I soldered the connector directly to the PCB added and added new 2 kΩ pullups. I've replaced the MCU from the ESP32 with an ESP8266 (Wemos D1 Mini). Rest everything remains the same. The wire length is reduced to 100 mm (~4") I've two soldered two pin headers on SDA, SCL, and GND for easy measurement.
For while I got the same waveform, on both SDA and SCL even they were not short. Today I cleaned everthing again, and I'm getting the following waveforms.
The SDA waveform seems to me like normal. The SCL seems off. Although, earlier it was it didn't have spikes. It was continuously at 0.9 V.
A Picture of my new wiring setup.
A top-down picture to understand the placement of components.
noch ein Update
I was following the pinout given in the manual. Apparently, different header versions have different pinouts. Thanks to @DamienD correct pointing it out!