WireAvailable is not working (I2C)

Hello,

I am trying to read values from a CDC, using an Arduino, I'm using I2C ofc and I already tested it to read simple stuff.

Now when I try to read output values it gets stuck in the Wire.available, because after the requestfrom, it is not sending any byte, so I get a deadlock.

I do not think it is a connection error as I have already tested the I2C. The sensor is well connected to the CDC (I have used a circuit from the supplier).

Does anyone know where the error might be? Attached below is the code.

I have not written the code (just adjusted it a bit), but I understand how it should work, except from the rconfig1 (do not know why it is needed).

CODE:

#include <Wire.h>

int chip_addr = 0x48; //AD7150 adress

#define ch1_dataH_addr 0x01 //Address to point the Data High of Ch1
#define ch1_dataL_addr 0x02 //Address to point the Data Low of Ch1
#define ch1_SetupR_addr 0x0B //Setup (range) register address for Ch1
#define ConfigR_addr 0x0F //Configuration register (operation mode -threshold-)
#define Ch1_ThHR_addr 0x09 //Ch1 Threshold High Register
#define Ch1_ThLR_addr 0x0A //Ch1 Threshold Low Register

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Wire.begin();
Serial.println("Setup Done");
}

void rconfig1()
{
Wire.beginTransmission(chip_addr);
Wire.write(ch1_SetupR_addr); //Move pointer to the register address
Wire.write(203); //Setup features for range (bx11001011)
Wire.endTransmission();
Serial.println("RConfig1 done");
}

void loop() {
//Get capacitance data
// move the register pointer back to the second register
Serial.println("Starting the loop");
Wire.beginTransmission(chip_addr); // "Hey, AD7150 @ 0x48! Message for you"
Wire.write(1); // "move your register pointer back to 01h"
Wire.endTransmission(); // "Thanks, goodbye..."

// now get the data from the AD7150

Wire.requestFrom(chip_addr, 2); // "Hey - please send me the contents of your first register"

while(Wire.available() == 0); // slave may send less than requested

byte ch1H = Wire.read(); // first received byte stored here
byte ch1L = Wire.read(); // second received byte stored here
Wire.endTransmission();

unsigned int ch1 = ch1H*256 + ch1L; //Concatanates the two bytes into one 16 bit word for capacitor 1.

float Cap1 = (ch1-12288.0)*4/40944.0; // Converts the digital value into capacitance.

//print the data on serial monitor, data that was gotten from the registers that store capacitance values
Serial.print("Ch1=");
Serial.print(ch1, BIN);
Serial.print(" Ch1=");
Serial.print(ch1);
Serial.print(" C1=");
Serial.print(Cap1,2);

delay(700);
}

 while(Wire.available() == 0);    // slave may send less than requested

Certainly sounds like the slave is sending 0 bytes, and you are in an infinite loop waiting for more.

Some real details on what is connected to what, with URLs for those things, would certainly be in order.

Hi,

So I am using an AD7150 (www.analog.com/media/en/technical-documentation/data-sheets/AD7150.pdf) to read values from a capacitor plate, the connections used for the sensor and AD7150 are shown in Fig. 1 of ftp://ftp.analog.com/pub/MicroConverter/CDC/AD7150/CN0095_Final_Approval.pdf.

I am using an Arduino Due.

Then I am connecting SDA to SDA1 and SCL to SCL1 both of them connected to a 3.3V supply with external pull-up resistors of 10k.

I do not know if it matters but the power supply for the slave is the master and for the master is a computer (to program it).

They both share the master's ground.

Thanks again

Do you think houses are built using instructions like "Put a two by four at the end of..."? Or, are they built because there are drawings showing where things go, with dimensions, etc.?

Hand-waving descriptions of electrical circuits are useless. Schematics are useful.

Hi,

Sorry about that PaulS, I'll be more clear next time!

The problem was a soldering issue, now it seems all good!

Thank you either way!