Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I2C library & examples
15-06-2012, 03:38 PM, (This post was last modified: 16-06-2012, 09:35 AM by mf01.)
#21
RE: I2C library & examples
Hi RLmonitor,

I think you are reading too much into the statement in 24.5.2 ... "4. On the ninth SCLx clock, the module shifts in the ACK bit from the slave device and writes its value into the ACKSTAT bit (I2CxSTAT<15>)." - what it does not say is which edge of the clock ACTSTAT is set on - this is dealt with in 24.5.2.3 as noted in my last post. From the statement in 24.5.2.3 taken together with Figure 24-9: Master Transmission Timing Diagram I believe it is clear that both the setting of ACKSTAT and the setting of the master interrupt effectively happen at the same time, so "waiting" for the master interrupt effectively ensures that the ACKSTAT has the correct value. If it is attempted to read ACKSTAT any earlier then the correct value might not have been written into ACKSTAT.

That having been said both my test code and yours return the value of ACKSTAT after the master interrupt has been set and my test code appears to work OK. I tested it by addressing a I2C device and checking the returned value both when the correct address and also the incorrect address was used. In both cases it worked as expected. I have also tried modifying the code to read the value of ACKSTAT before waiting for the master interrupt. In this case for an incorrect address it would falsely report ACKSTAT as "0" before the "wait" but always correctly report ACKSTAT as "1" after the "wait" (ACKSTAT appears to default to "0" not only on reset as per the data sheet but also on I2C start).

Like you I have no 8 bit hardware so do not have the capability to check its operation - every now and then I try to add to the documentation on the wiki hence my interest in checking at least the function calls between the two variants. Hopefully once we have a working and stable version of I2C I will have time to get round to that and that will address some of the points you raise about what each of the functions is meant to do. I agree that at the moment a certain amount of detective work is necessary to use a new library. Luckily for me you had already done most of it for the P32 I2C library.

I see the "wait" function as an "internal" function within the i2c library, i.e. not normally used directly by the user, so it is relatively easy to change its name. I suspect that however wrote the function originally was caught between choosing a short easy to type name and choosing a longer more meaningful name.

UPDATE: I have checked the P8 I2C_writechar() function and it returns (!SSPCON2bits.ACKSTAT) so for consistency with the P8 version, I think we should follow the same logic. This will also be consistent with the current version for P32 where a successful write returns "true" (=1).

Regards
Board = PIC32-Pinguino-OTG Rev C
OS = Linux Unbuntu 11.10 till 26 Apr 2012
OS = Linux Unbuntu 12:04 from 27 Apr 2012
Reply
17-06-2012, 12:07 PM,
#22
RE: I2C library & examples
Hi RLmonitor,

I have been doing some further investigating and I think it may be possible to simplify some of the functions within the P32 I2C library. Noticing that the current P8 library only uses the wait() function rather than also waiting for particular function flag to clear for things like start(), restart(), stop(), readchar() and writechar() I checked on the MicroChip P32 I2C reference document it appears that the interrupt flag (I2C#MIF) is always set when each of these functions is complete (twice in the case of readchar() once after 8 characters are received and a second time after ACK/NACK is sent). Based on this it does not appear to be necessary to also wait for the particular function flag to be set or cleared. Where I have checked the timing diagrams in the P32 I2C reference document the particular function flag appears to be actually set/cleared at the same time that the interrupt flag is set. From your investigations of the I2C library are you aware of any other reasons why the functions need to wait for the individual function flags to be set/cleared as well as waiting for the interrupt flag and resetting it?

Just to check I have "remarked out" a number of the while statements and the two I2C devices that I have still respond as they did before.

Regards
Board = PIC32-Pinguino-OTG Rev C
OS = Linux Unbuntu 11.10 till 26 Apr 2012
OS = Linux Unbuntu 12:04 from 27 Apr 2012
Reply
17-06-2012, 12:50 PM,
#23
RE: I2C library & examples
That seems reasonable. When I was getting the routines working, I had noticed that the state flags and the interrupt flags seemed duplicate functionality. I think that I was following the datasheet explanation step by step.

I can't think of a reason to use the state flags. Perhaps in a threaded application indicate that the I2C engine is busy?
Reply
17-06-2012, 01:44 PM,
#24
RE: I2C library & examples
Hi RLmonitor

What I2C devices have you used and when are you likely to have your hardware back? I would like to check operation on a few more I2C devices before committing any updated code to the repository. At the moment the updated code will not in general change the functionality, only the implementation, but it would be nice to check it on a few more I2c devices if possible. The only change in functionality will be for writechar to return (!SSPCON2bits.ACKSTAT) rather than return true as previously discussed but as a successful write results in a "1" being returned it should not break anything.

Regards
Board = PIC32-Pinguino-OTG Rev C
OS = Linux Unbuntu 11.10 till 26 Apr 2012
OS = Linux Unbuntu 12:04 from 27 Apr 2012
Reply
17-06-2012, 11:25 PM,
#25
RE: I2C library & examples
An LIS331 accelerometer and a BMP085 barometric sensor. The BMP085 would get "stuck" sometimes, when I was developing the routines and got something wrong. I had to de-power it to get it working.

mf01, in this thread has used a PFC8563 real time clock.

It'll be a couple of weeks before I get the hardware back from field testing. I may make a duplicate before then. I do have a PIC32 UNO I could use, and we have a few BMP085s in stock ...
Reply
18-06-2012, 08:09 AM,
#26
RE: I2C library & examples
Hi RLmonitor,

I also have a 24LC64 EEPROM as well as the PFC8563 and I am testing the code against both devices.

Regards
Board = PIC32-Pinguino-OTG Rev C
OS = Linux Unbuntu 11.10 till 26 Apr 2012
OS = Linux Unbuntu 12:04 from 27 Apr 2012
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)