Arduino DUE I2C code not working

Hello all. I am designing a Gan Bias network and have a Switch (ADG715) that I'm using the I2C capabilities for on the Due. I can not see to get a response from the system, despite my efforts over the last 8 hours. I'm better at hardware and would like to mature as a software guy, but I do need some help with the code.

#include <Arduino.h>
#include <Wire.h>

//Outputs - Digital -> designed for the Arduino DUE, pinout will need to be updated for different models.
//SCL must go high then SDA goes high to low for data transfer

//int TPLadd = 0x57; // device address for the TPL0102
//#define TPLwiperreg 0x00 // wiper address 'A' for TPL0102
//#define TPLgenreg 0x02 // general register address for TPL0102

int ADGadd = 1001011; // device address for the ADG715 -----> looks like this guy takes a binary input 0x4B in hex-> 1001011 in binary
int analogPin = A0;
int analogPin2 = A1;
int val = 0;
int val2 = 0;

int UserInput; // this stores the user input int for the selected device - either 1, 2, or 3.
int stepsize; // this stores the users desired step, corresponding to the resistance table in the datasheet for the dig pot (TPL0102). 0-255 steps.
int step; // this stores the users desried step, corresponding to the table in the datasheet for the ADG715

void setup()
{
Wire.begin();
Serial.begin(9600); //...begin(baud rate) aka the rate at which 2 devices comm over serial. baud rate in serial begin and serial monitor must match

/*pinMode(21, OUTPUT); // Serial Clock Output
pinMode(20, OUTPUT); // Serial Data Output
pinMode(23, OUTPUT); // this is the Gate(g) Digital pot(d) analog(a) Address Bit 0(0), bit 1
pinMode(25, OUTPUT); // this is the Gate(g) Digital pot(d) analog(a) Address Bit 1(1), bit 2
pinMode(27, OUTPUT); // this is the Gate(g) Digital pot(d) analog(a) Address Bit 2(2), bit 3
pinMode(29, OUTPUT); // this is the Gate(g) Digital pot(d) serial data input/output(sda)

*/
//May not need this grayed out area

}

void loop()
{
Serial.print("-----------------------");
Serial.print("--- Bias Controller ---");
Serial.print("-----------------------");
Serial.println(); // Carriage return

Serial.print("What do you wish to change: 1, 2, or 3?");
Serial.println();

Serial.print("1. Digital Switch -> Gate Controlled -> ADG715");
Serial.println(); // Carriage return
Serial.print("2. Digital Potentiometer -> Gate Controlled -> TPL0102");
Serial.println(); // Carriage return
Serial.print("3. Digital Power Monitor -> Drain Controlled -> LTC2945");
Serial.println(); // Carriage return

while (Serial.available() == 0)
{
// Wait for User to Input Data
}
UserInput = Serial.parseInt();

if(UserInput == 1)
{
//Serial.print("Input binary command");
//while (Serial.available() == 0)
//{
// Wait for User to Input Data
//}
val = analogRead(analogPin); // read the input pin
Serial.println(val); // debug value
val2 = analogRead(analogPin2); // read the input pin
Serial.println(val2); // debug value
step = 8;
Serial.println(); // Carriage return
Wire.beginTransmission(ADGadd);
val = analogRead(analogPin); // read the input pin
Serial.println(val); // debug value
val2 = analogRead(analogPin2); // read the input pin
Serial.println(val2); // debug value
Wire.write(step);
val = analogRead(analogPin); // read the input pin
Serial.println(val); // debug value
val2 = analogRead(analogPin2); // read the input pin
Serial.println(val2); // debug value
//Wire.requestFrom(ADGadd, 1);
// int secs = Wire.read();
Wire.endTransmission(); //ends connection
val = analogRead(analogPin); // read the input pin
Serial.println(val); // debug value
val2 = analogRead(analogPin2); // read the input pin
Serial.println(val2); // debug value
}

When I read the analog pins A0 and A1, they return 0 every time in each line. I am completely out of ideas. I have also measured the voltage on the SCL and SDA lines and it does not vary at all, so I know the arduino isn't even sending on the commands. Does anyone have some insight into what I'm doing incorrectly?

Please present code using Code Tags </>

That's decimal not binary 0b1001011;

How? Using a scope or logic analyzer?

Don't touch the I2C pins yourself, the Wire library is responsible for that!

How does that relate to the I2C?

I guess you used a multimeter for that. Believe me, it will never read a voltage even if your sketch is working as expected.

You forgot a very important information: the wiring diagram. You might not know it yet but the software can only work if it complies with the hardware. You probably know every detail about your hardware but we know nothing (almost) about it.

1 Like

While you are posting a schematic as pylon asked for also include links to technical information on the hardware devices. Also have you run the I2C scanner? if so what were the results.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.