RobG 1,892 Posted July 7, 2012 Share Posted July 7, 2012 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")); memory.h memory.c timotet, krzyk2, DigitalDad and 1 other 4 Quote Link to post Share on other sites
RobG 1,892 Posted July 7, 2012 Author Share Posted July 7, 2012 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); ) bluehash 1 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.