IIC how to

Newcomers to Astrobe and Oberon are welcome to ask any beginner-level questions here
Post Reply
alain
Posts: 6
Joined: Tue Jan 04, 2011 9:28 pm

IIC how to

Post by alain » Wed Jan 19, 2011 3:25 pm

Hello,
Unexpected results when running IIC example EEPROM2K with different 24LC256.
Got at each run :
EEPROM OK
Read ID OK
Write ID OK
Ready OK
0
Write counter OK
..........
Seems to be a fail to write or a missmatch
Not corrected by adding a 5mS delay after the write... ID

Same results with Sceptre and generic LPC boards, ck= 100khz, IIC device at3.3v or level shifter to 5v

Where is the snag ???

Regards

Alain

cfbsoftware
Site Admin
Posts: 423
Joined: Fri Dec 31, 2010 12:30 pm
Contact:

Re: IIC how to

Post by cfbsoftware » Thu Jan 20, 2011 4:08 am

The EEPROM2K example supplied with Astrobe is designed for use with 2Kbit EEPROMs which use 8-bit location addresses. The 24LC256 is a 256Kbit EEPROM which uses 16-bit location addresses.

Hence the variables idAddr and counterAddr need to be declared as 16-bit unsigned integer variables instead of 8-bit CHARs. If you want to modify the code yourself you can get some clues on how to implement UInt16s by looking at the I2C Compass and Temperature examples.

In the meantime we'll implement an additional EEPROM example to target the Elektor Sceptre and a 24LC256 EEPROM on I2C0 and post it in the Enhancements section of this forum as soon as it has been tested.

alain
Posts: 6
Joined: Tue Jan 04, 2011 9:28 pm

Re: IIC how to

Post by alain » Sat Jan 22, 2011 2:52 pm

OK, I'll try it on (I suggest you remove the reference to CAT24LC256 in the header comment , because it is not applicable here)

Regarding the IIC Library, I am questionning about the accessing to IIC components like PCF8574 : should we must put NIL as params because there is no register address ?

I understand that Oberon-07 uses CHAR to access SYSTEM.BYTE because the 8 bits !; but, this seems not so trivial in case of adressing or data not related to printable characters !. Is't it possible to imagine a more "elegant" way to resolve this problem ?
for example, a library module including types and procedures dealing with ...
I think that may improve the readability of program sources and certainly reduce programmer's headeache :P :P :P
regards
Alain

cfbsoftware
Site Admin
Posts: 423
Joined: Fri Dec 31, 2010 12:30 pm
Contact:

Re: IIC how to

Post by cfbsoftware » Sun Jan 23, 2011 5:56 am

The reference to CAT24LC256 will be removed.

In the process of working on the 256Kbit EEPROM example we've added a couple of extra functions to the I2C module to give greater control over the parameters. You will be able to specify the number of bytes (including 0) for both the params and data parameters. That now allows us to specify that the address is a 2-byte quantity. We'll post the updated I2C module here along with the EEPROM example.

Acheiving elegance is a challenge when you are dealing with endian issues :( That was what led us to the different approach for the EEPROM example. We're now using INTEGER for the address instead of the UInt16 record type. However, the low bytes have to be swapped as the EEPROM expects to receive the most significant byte first. There are several ways of doing this - we're currently using the following:

Code: Select all

PROCEDURE* SwapBytes*(CONST addr: INTEGER; VAR addr16: INTEGER);
(* Swap the bytes of an unsigned 16-bit value *)
VAR
  lsb: INTEGER;
BEGIN
  ASSERT((addr >= 0) & (addr < 10000H), 20);
  lsb := addr MOD 100H;
  addr16 := LSR(addr, 8) + LSL(lsb, 8)
END SwapBytes;

cfbsoftware
Site Admin
Posts: 423
Joined: Fri Dec 31, 2010 12:30 pm
Contact:

Re: IIC how to

Post by cfbsoftware » Tue Jan 25, 2011 2:02 am

cfbsoftware wrote:We'll post the updated I2C module here along with the EEPROM example.
These have now been uploaded to the Enhancements & Suggestions section of this forum.

alain
Posts: 6
Joined: Tue Jan 04, 2011 9:28 pm

Re: IIC how to

Post by alain » Tue Jan 25, 2011 2:26 pm

Bravo for all these enhancements :D :D :D
Regards
Alain

Post Reply