From: VaibhavGhadiok <vai...@gm...> - 2011-01-21 04:57:57
|
Hi Dave, It's Working!!!! Thank you very much for your help, it allowed me to figure out the problem. The only difference I could see between the Arduino traces and the Gumstix, were at the read part, after the write of the register (from which to read from). This is where the Gumstix does a repeated start. But if you look at the Arduino trace at this point, it actually sends a stop bit first, and then a start bit again before sending the address with the read command. Repeated Start of Gumstix before sending second 0x58 address: http://dl.dropbox.com/u/16369427/Gumstix%20Read%20Part%202%20-%200x37.JPG Arduino sends stop then sends start before second 0x58 address: http://dl.dropbox.com/u/16369427/Arduino%20Read%20pt%201%20-%200x58%200x36%200x00%200xFF%200xFF%200xFF.JPG So instead of using the repeated start of the rdwr code (1 big message, so makes a repeated start between the write and read), I send the two bytes to write (0x58 0x36) as one message (so there's a stop bit) then I send the read command (0x58 with read) so there's a start again. Gumstix Successful Read with Stop and Start between write and read: http://dl.dropbox.com/u/16369427/Gumstix%20Read%20Success%20pt%201%20-%200x58%200x36%200x58%200x00%200xFF%200xFF%200xFF.JPG http://dl.dropbox.com/u/16369427/Gumstix%20Read%20Success%20pt%202%20-%200x58%200x36%200x58%200x00%200xFF%200xFF%200xFF.JPG There is an 80usec delay between the two ioctl messages as opposed to almost nothing with the repeated start and about 12usec with the Arduino, but at least it works. Not sure why the camera, which works with i2c, won't recognize a repeated start. Do you have an idea why? The code is below: int I2cReadRegisterCamera ( int i2cDev, ///< Handle to i2c-dev file uint16_t DeviceAddress, //0x58 char wrData, //Register Address uint8_t *rdData, uint8_t rdLen // How much data to expect back ) { struct i2c_msg msgs[1]; struct i2c_rdwr_ioctl_data rdwr; msgs[0].addr = DeviceAddress; msgs[0].flags = 0; msgs[0].buf = &wrData; msgs[0].len = 1; rdwr.msgs = msgs; rdwr.nmsgs = 1; ioctl( i2cDev, I2C_RDWR, &rdwr ); msgs[0].addr = DeviceAddress; msgs[0].flags = I2C_M_RD; msgs[0].buf = (char *)rdData; msgs[0].len = rdLen; rdwr.msgs = msgs; rdwr.nmsgs = 1; if(ioctl( i2cDev, I2C_RDWR, &rdwr ) < 0) {printf("Howl error\n");} return 0; } //I2cReadRegisterCamera I had scoped the camera when it was attached to the Wii Controller Board and it was working at 400 Khz. Thanks very much again, Vaibhav Dave Hylands wrote: > > Hi Vaibhav, > > On Wed, Jan 19, 2011 at 9:51 PM, VaibhavGhadiok > <vai...@gm...> wrote: >> >> Why are there only 8 clock highs in that last sending? i.e. only 8 >> opportunities to read bits on the SDA. >> http://dl.dropbox.com/u/16369427/Gumstix%20Read%20Part%202%20-%200x37.JPG > > The level of the clock doesn't matter, it's the rising edge that > counts. The data line isn't allowed to change while the clock is high, > so the value at the rising edge is typically what's used. For multiple > master arbitration, the gumstix knew it wrote a 1 but read a zero, so > it stopped assuming that the other master was driving the bus. If you > detect a difference (which can only happen when you write a 1 and > detect a zero), then you're supposed to back off and wait for the > other master to finish (when you detect the STOP condition). > > Since there was no other master, this effectively hangs the bus. (see > page 21 of smbus20.pdf titled "Arbitration"). > > Dave Hylands > > -- View this message in context: http://old.nabble.com/I2C-read-fails%2C-but-write-works-tp30676129p30725816.html Sent from the Gumstix mailing list archive at Nabble.com. |