IIC how to
IIC how to
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
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
-
- Site Admin
- Posts: 497
- Joined: Fri Dec 31, 2010 12:30 pm
- Contact:
Re: IIC how to
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.
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.
Re: IIC how to
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
regards
Alain
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
![Razz :P](./images/smilies/icon_razz.gif)
![Razz :P](./images/smilies/icon_razz.gif)
![Razz :P](./images/smilies/icon_razz.gif)
regards
Alain
-
- Site Admin
- Posts: 497
- Joined: Fri Dec 31, 2010 12:30 pm
- Contact:
Re: IIC how to
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:
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
![Sad :(](./images/smilies/icon_e_sad.gif)
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;
-
- Site Admin
- Posts: 497
- Joined: Fri Dec 31, 2010 12:30 pm
- Contact:
Re: IIC how to
These have now been uploaded to the Enhancements & Suggestions section of this forum.cfbsoftware wrote:We'll post the updated I2C module here along with the EEPROM example.
Re: IIC how to
Bravo for all these enhancements
Regards
Alain
![Very Happy :D](./images/smilies/icon_e_biggrin.gif)
![Very Happy :D](./images/smilies/icon_e_biggrin.gif)
![Very Happy :D](./images/smilies/icon_e_biggrin.gif)
Regards
Alain