Pages: 1 [2]   Go Down
Author Topic: New SPI EEPROM Library  (Read 4554 times)
0 Members and 1 Guest are viewing this topic.
Maryland, USA
Offline Offline
Full Member
***
Karma: 0
Posts: 162
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Checked out the SPIEEPROM code, looks like my code went a bit further so I decided to add support for int, long, float, and double to mine.

Decided to start using bitbucket too.  Check my version out:

https://bitbucket.org/spirilis/spieep
(I usually rename the 'spieep' dir to SPIEEP all uppercase btw, not sure how to make that happen by default)

In addition to read, write, readn, writen, read_page, write_page, I now have:

read_int, write_int, readn_int, writen_int, read_int_offset, write_int_offset, readn_int_offset and writen_int_offset
along with long, float, and double variants of all those functions.

The EEPROM "address" you supply to each of those int/long/float/double variants gets multiplied by the size of those variables, so you could for instance use the whole EEPROM as one huge array of double's, accessing each item's address by incrementing a variable one at a time (rather than having to compute byte addresses yourself).  The "offset" variants allows you to specify a origin byte-level address where the int/long/float/double address should start counting.

Or in plain code:
read_int(p) runs the underlying readn() with (byte) address = p * sizeof(int)
read_int_offset(offset, p) runs the underlying readn() with (byte) address = p * sizeof(int) + offset

Since these functions use my readn and writen functions, they can work across page boundaries without requiring any further consideration.

I haven't actually tested the int/long/float/double variants yet, just forewarning... I will do that later smiley
Hope this helps!
« Last Edit: August 29, 2011, 10:37:03 am by spirilis » Logged

Maryland, USA
Offline Offline
Full Member
***
Karma: 0
Posts: 162
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Tested writing & reading longs last night, seems to work correctly.

Added support for the 25LC040 to my library this morning, it'll set a simple bool in the class if it sees addrwidth = 8 bits & totalsize = 512 bytes and during any reads & writes it'll test that bool before writing the instruction (and add the 9th addrbit to the instruction if the bool is true).
Logged

Maryland, USA
Offline Offline
Full Member
***
Karma: 0
Posts: 162
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Tweaked/updated some things in the code; disabled testing for Deep Power Down functionality if the EEPROM in question has less than 64KB capacity (b/c all Microchip 25LC series chips below the 512Mbit model don't seem to have it), changed some variable types in the write/read functions to avoid a few bit-width gotchas.

Added pretty thorough documentation to my wiki: https://bitbucket.org/spirilis/spieep/wiki/Home
Logged

Pages: 1 [2]   Go Up
Jump to: