A library to read and write all 25* serial SPI eeprom devices from Microchip (from 25xx010 to 25xx1024).

Dependents:   RobotRic VITI2_ihm_2

Embed: (wiki syntax)

« Back to documentation index

Ser25LCxxx Class Reference

Ser25LCxxx Class Reference

A class to read and write all 25* serial SPI eeprom devices from Microchip (from 25xx010 to 25xx1024). More...

#include <Ser25lcxxx.h>

Public Member Functions

 Ser25LCxxx (SPI *spi, PinName enable, int bytes, int pagesize)
 create the handler class
 ~Ser25LCxxx ()
 destroys the handler, and frees the /CS pin
char * read (unsigned int startAdr, unsigned int len)
 read a part of the eeproms memory.
bool write (unsigned int startAdr, unsigned int len, const char *data)
 writes the give buffer into the memory.
bool clearPage (unsigned int pageNum)
 fills the given page with 0xFF
void clearMem ()
 fills the while eeprom with 0xFF

Detailed Description

A class to read and write all 25* serial SPI eeprom devices from Microchip (from 25xx010 to 25xx1024).

One needs to provide total size and page size, since this cannot be read from the devices, and the page size differs even by constant size (look up the data sheet for your part!)

Definition at line 35 of file Ser25lcxxx.h.


Constructor & Destructor Documentation

Ser25LCxxx ( SPI *  spi,
PinName  enable,
int  bytes,
int  pagesize 
)

create the handler class

Parameters:
spithe SPI port where the eeprom is connected. Must be set to format(8,3), and with a speed matching the one of your device (up to 5MHz should work)
enablethe pin name for the port where /CS is connected
bytesthe size of you eeprom in bytes (NOT bits, eg. a 25LC010 has 128 bytes)
pagesizethe size of a single page, to provide overruns

Definition at line 30 of file Ser25lcxxx.cpp.

~Ser25LCxxx (  )

destroys the handler, and frees the /CS pin

Definition at line 38 of file Ser25lcxxx.cpp.


Member Function Documentation

void clearMem (  )

fills the while eeprom with 0xFF

Definition at line 155 of file Ser25lcxxx.cpp.

bool clearPage ( unsigned int  pageNum )

fills the given page with 0xFF

Parameters:
pageNumthe page number to clear
Returns:
if the pageNum is out of range

Definition at line 131 of file Ser25lcxxx.cpp.

char * read ( unsigned int  startAdr,
unsigned int  len 
)

read a part of the eeproms memory.

The buffer will be allocated here, and must be freed by the user

Parameters:
startAdrthe adress where to start reading. Doesn't need to match a page boundary
lenthe number of bytes to read (must not exceed the end of memory)
Returns:
NULL if the adresses are out of range, the pointer to the data otherwise

Definition at line 42 of file Ser25lcxxx.cpp.

bool write ( unsigned int  startAdr,
unsigned int  len,
const char *  data 
)

writes the give buffer into the memory.

This function handles dividing the write into pages, and waites until the phyiscal write has finished

Parameters:
startAdrthe adress where to start writing. Doesn't need to match a page boundary
lenthe number of bytes to read (must not exceed the end of memory)
Returns:
false if the adresses are out of range

Definition at line 75 of file Ser25lcxxx.cpp.