Pages: [1]   Go Down
Author Topic: i2c bugs.  (Read 368 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi guys. A couple of months back I made an enquiry around these parts describing the connection of an AD7747 to an arduino, I got some good advice and constructed a simple code that simply polled the register sof the device and stuck them on the serial port:

Code:
#include <wire.h>
#define SLAVEWRT 0x48
#define SLAVERD 0x48
void setup()
{
Wire.begin();
Serial.begin(115200);
Wire.beginTransmission(SLAVEWRT);
Wire.send(0x07);
Wire.send(0xA0);
Wire.endTransmission();
delay(4);
Wire.beginTransmission(SLAVEWRT);
Wire.send(0x08);
Wire.send(0x00);
Wire.endTransmission();
delay(4);
Wire.beginTransmission(SLAVEWRT);
Wire.send(0x09);
Wire.send(0x0E);
Wire.endTransmission();
delay(4);
Wire.beginTransmission(SLAVEWRT);
Wire.send(0x0A);
Wire.send(0xB9);
Wire.endTransmission();
delay(4);
Wire.beginTransmission(SLAVEWRT);
Wire.send(0x0B);
Wire.send(0x3F);
Wire.endTransmission();
delay(4);
void loop()
{
Wire.beginTransmission(SLAVERD)
Wire.send(0x00);
Wire.endTransmission();
Wire.requestFrom(SLAVERD,12);
while(Wire.available()){
char c = Wire.receive();
Serial.print(c, DEC);
Serial.print(",");
}
}
Serial.println();
}

Now that works, it sets up all the internal registers to allow the device to run free and spits out values for the serial interface. I came back to thsi quite recently with the intention of changing some of the code, and I discovered that, within the void loop() - after I begin transmission to the device, when I try to change the address of the register that I intend to read from, the device ignores this and simply startd form the first pointer adress, 0x00.

I find this odd, since in the void setup, the code has no problem adressing different internal registers in order to write data to them.

Anyone shed any light on this?

Also, I was hoping to be able to modify the code so that instead of constantly polling the AD7747, that rather when the first status register changes value (to indicate a completed conversion) that this is the only time the device will read data.

I tried writing one read loop in to check for a change in value in this register, followed by an if statement that would check to see if the test case (a change in value) had come true, at which point I'd initiate a second read loop to get the data. However since the whole thing seems to be exhibiting the strnage behaviour I described above it's not working.

Any help guys, sorry if it sounds dumb.
Logged

Pages: [1]   Go Up
Jump to: