Hi guys, I am new to i2c and is practicing my skill with a XP power supply that is capable of I2C communication.
According to manufacturer, from 0x00 to 0x16, there are 16 byte of info on manufacturer.
I wrote my program with a "for" loop that uses delay(1000) each cycle. And within each loop, it calls out a function to read and print those 16 bytes.
I used wire.beginTransmission (i2c address)
wire.write (0x00)
wire.end transmission
and then wire.requestFrom(i2c address, 16)
while loop with wire.available and wire.read.
My expectation is that Arduino would hold and grab 16 bytes, print it, and then moves on to increment the for loop.
However, my program prints out the complete data, which is "XP Power LTD" only every 3 or 4 loop cycle.
The loop seems to increment at 1 second interval no matter what. I am really confused because the program IS finding the right address, IS reading from correct register. Everything is working, but whole thing is just very slow.
While I am not sure what chip is on the PS. But I would expect a $500 PS from a name brand should have a decent hardware that can handle reading couple text.
CODE:
void setup()
{
Serial.begin(9600);
while (!Serial);
Wire.begin();
Wire.setClock(100000);
}
void loop()
{
for (int i = 0; i <= 50; i++)
{
Serial.print("This is cycle #");
Serial.print(i);
Serial.print("\n");
readManuf (psAddress);
delay (1000);
}
}
void readManuf (byte i2cAdd)
{ // Function to read manufacturer info from register 0x00 to 0x0F
Wire.beginTransmission(i2cAdd);
Wire.write(0x00);
Wire.endTransmission();
delay (20);
Wire.requestFrom (i2cAdd, 16);
while (Wire.available())
{
char c = Wire.read();
Serial.print(c);
}
delay (100);
}