Greetings,
I am having an I2C speed issue. I have a code where my I2C communication is taking 6 milliseconds for 3 communications, pulse 5 milliseconds in delay commands for 11 millisecond in total (per channel). In general, the questions come down to:
-
Is there a better way than delay() to wait for my data? The data sheet states a data setup time of 100ns, but I cannot call for a delay of 0.1ms.
-
Can I just get rid of the delays?
-
I sped up the I2C library clock to 400 kHz in wire.h. Is there a way to check this to make sure it’s working at 400 kHz?
The projects relates to reading the capacitance form a FDC1004 and writing this do a DAC. In total, I would like to get a cycle speed of 100Hz, but I am currently stuck at 20Hz. In general my code is running nicely, but the writing and reading from 4 channels over I2C is taking 45 milliseconds. Of this, 25 milliseconds is delay time, and 20 milliseconds is eaten up with the I2C transfer.
Here is what I have tried;
-
I backed my delays down to 1milliseconds each, if I go to zero the code no longer outputs a voltage at my DAC.
-
I changed the wire.h speed to 400 kHz. However, I am not sure that it is working at this speed as the directions I found on the forums stated I should delete the wire.o files and I could not find any .o files.
Here is the data sheet for the FDC1004:
And the link to the forums I used for changing the I2C clock speed:
http://forum.arduino.cc/index.php?topic=16793.0
Here is part of my code as the code is to long for a post. Notice that the I2C components are called in configure and getdata function found at the bottom of the code.
Thanks in advance for any help.
Code where I call the I2C function, each "block" takes 11 milliseconds in total
Config(Ch1Register,Ch1Byte1,Ch1Byte2);
Config(FDC_CONFIG,RegisterValue1,RegisterValueCh1);
delay(del);
Data1=getdata(0x00);
time2 = millis();
Config(Ch2Register,Ch2Byte1,Ch2Byte2);
Config(FDC_CONFIG,RegisterValue1,RegisterValueCh2);
delay(del);
Data2=getdata(0x02);
Config(Ch3Register,Ch3Byte1,Ch3Byte2);
Config(FDC_CONFIG,RegisterValue1,RegisterValueCh3);
delay(del);
Data3=getdata(0x04);
Config(Ch4Register,Ch4Byte1,Ch4Byte2);
Config(FDC_CONFIG,RegisterValue1,RegisterValueCh4);
delay(del);
Data4=getdata(0x06);
Here are the functions called in the code before.
void Config(byte addresse, byte val1, byte val2)
{
Wire.beginTransmission(FDC);
Wire.write(addresse);
Wire.write(val1);
Wire.write(val2);
Wire.endTransmission();
delay (del);
}
unsigned long getdata(byte pointer)
{
unsigned int a,b;
unsigned long c=0;
a = getinfo(pointer);
delay(del);
b = getinfo(pointer+1);
delay(del);
c=a;
c=c<<16;
c|=b;
// Serial.print(a,HEX);
// Serial.print(b,HEX);
// Serial.print(c,HEX);
return(c);
}