Jump to content
43oh

Serial SPI memory functions


Recommended Posts

Here is the set of functions needed to read and write serial SPI memory, SRAM & EEPROM.

 

EEPROM: Microchip 25AAxxx series

SRAM: Microchip 23Kxxx series

 

Included are byte and sequence read and write functions (page boundaries must be handled by user.)

Test functions are also included. Additional functions will be added later on.

 

Those functions can be used with some of my booster packs, like CC2500, Universal Color LCD, and few other.

 

Test example

// setup SPI pins, which can be shared with other devices
// setup memory specific pins
P1OUT |= SRAM_CS_PIN + SRAM_HOLD_PIN;
P1DIR |= SRAM_CS_PIN + SRAM_HOLD_PIN;
P2OUT |= EEPROM_CS_PIN;
P2DIR |= EEPROM_CS_PIN;
// setup display
// run tests
drawString(0,0,"Test SRAM:");
drawString(64, 0, (testSRAM() == 'O' ? "Pass" : "Fail"));
drawString(0,10,"Test EEPROM:");
drawString(76, 10, (testEEPROM() == 'O' ? "Pass" : "Fail"));

 

post-197-135135556219_thumb.jpeg

 

memory.h

memory.c

Link to post
Share on other sites

Examples

 

Simple read and write

// Byte mode is a default mode, so this command is not necessary. If only one mode is used, mode command has to be executed just once.
sramWriteStatus(MODE_BYTE);
// write data to address 0x0010
sramWriteByte(0x0010, data);
// read it back
unsigned char data = sramReadByte(0x0010);

 

Page or sequential read and write

sramWriteStatus(MODE_SEQUENTIAL);
// sramWriteStatus(MODE_PAGE);  // 23K256/23K640 page size is 32
// start sequence at memory location 0x0000
sramWriteSequence(0x0000);
char c = 0;
while(c < 16) {
   // write each byte
   sramWrite(bytes[c++]);
}
// finish sequence
sramEndSequence();

// and read it back
sramReadSequence(0x0000);
c = 0;
while(c < 16) {
   // read each byte
   bytes[c++] = sramRead();
}
// finish sequence
sramEndSequence();

 

Reading and writing EEPORM is pretty much the same, except page sizes can be from 16 to 256 bytes (depending on chip) and sequential write cannot exceed size of the page (it will wrap.) Larger writes will require multiple sequential writes.

Also, mode commands are for SRAM only ( i.e. sramWriteStatus(MODE_SEQUENTIAL); )

 

post-197-135135556223_thumb.png

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...