2008-04-03 20:33:16     i2c.c bug?

Document created by Aaronwu Employee on Sep 17, 2013
Version 1Show Document
  • View in full screen mode

2008-04-03 20:33:16     i2c.c bug?

Frank Shew (UNITED STATES)

Message: 53625   

 

We have a custom BF537 board with an I2C RTC chip (DS3231, similar to DS1337).  In uClinux everything runs fine, but under u-boot-1.1.6 we are not accessing it correctly.  The hard i2c option is selected so i2c.c is linked in.

 

In i2c.c, function i2c_reg_write(...) calls i2c_write(chip, reg, 0, &val, 1), and function i2c_reg_read(...) calls i2c_read(chip, reg, 0, &val, 1).  I believe they should be i2c_write(chip, reg, 1, &val, 1) and i2c_read(chip, reg, 1, &val, 1) respectively.  Otherwise, the address of the selected rtc register as specified by 'reg' will not be sent to the device.  Making this change fixed the read function, but...

 

In function i2c_reg_write(...), there are two calls to i2c_transfer(...).   While the 1st call will select the register of the RTC, the 2nd call is also interpreted as selecting the address register by the chip, rather than data to be written to the device.  I don't know about other I2C devices, but for the Maxim/Dallas RTC chips the register selection address and the data to be written need to be sent together in a single transfer.

 

Frank

QuoteReplyEditDelete

 

 

2008-04-04 20:43:25     Re: i2c.c bug?

Robin Getz (UNITED STATES)

Message: 53663    Frank:

 

I think Mike was digging around for some hardware to check this out - but I don't think we have any of the RTC parts to check specifically....

QuoteReplyEditDelete

 

 

2008-04-18 20:00:09     Re: i2c.c bug?

Mike Frysinger (UNITED STATES)

Message: 54511    please give current svn trunk a spin ... i rewrote the driver and now things seem to work for me with your rtc board:

bfin> imd 68 0 0x13

0000: 51 40 12 01 01 01 00 09 28 08 5d 21 29 19 1c 88    Q@......(.]!)...

0010: 00 16 80    ...

bfin> imd 68 0 0x13

0000: 52 40 12 01 01 01 00 09 28 08 5d 21 29 19 1c 88    R@......(.]!)...

0010: 00 16 80    ...

bfin> imd 68 0 0x13

0000: 53 40 12 01 01 01 00 09 28 08 5d 21 29 19 1c 88    S@......(.]!)...

0010: 00 16 80    ...

 

(you can see the first field there incrementing by one second)

 

this output pretty much matches what i get under linux:

root:/> i2cdump -r 0-0x12 -y 0 0x68 b

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef

00: 35 48 12 01 01 01 00 09 28 08 5d 21 29 19 1c 88    5H????.?(?]!)???

10: 00 17 00                                           .?.

QuoteReplyEditDelete

 

 

2008-04-21 17:57:39     Re: i2c.c bug?

Frank Shew (UNITED STATES)

Message: 54653   

 

Thanks, Mike.  I'm tied up with some other code at the moment, but I'll give the new driver a try in a couple of days.

 

Frank

Attachments

    Outcomes