Implementation of reading and writing to AT25512N-SH SPI-Serial EEPROM. Use it in your own risk. Free software.
Revision 0:d6075c37f0a4, committed 2019-08-13
- Comitter:
- mjm2016
- Date:
- Tue Aug 13 05:35:58 2019 +0000
- Commit message:
- Simple functions for writing and reading from SPI Serial EEPROM 512 Kbits (65,536x8)-AT25512N-SH. This might help you in understanding how the communications works with the flash memory.Please read the datasheet for further informations.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed-os.lib | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r d6075c37f0a4 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Aug 13 05:35:58 2019 +0000 @@ -0,0 +1,61 @@ +#include "mbed.h" +/** +* Writing and reading from Serial Flash memory +* AT25512N-SH +* http://ww1.microchip.com/downloads/en/DeviceDoc/AT25512-SPI-Serial-EEPROM-512-Kbits-20006218A.pdf +* Author : Mariwan jalal +*/ + +SPI device(SPI_MOSI, SPI_MISO, SPI_SCK); + +DigitalOut CS(SPI_CS); + +Serial pc(USBTX, USBRX); +void read() +{ + CS=1; + int v=0; + for(int i=0x200; i<0x210; i++) { + wait_ms(1); + CS=0; + device.write(0x03); + device.write((i&0xff00)>>8); + device.write(i&0xff); + v=device.write(0);///dummy + CS=1; + pc.printf("Results for i=%i : %x\n",i,v); + } + +} +void write() +{ + for(int i=0x200; i<0x0210; i++) { + CS=1; + CS=0; + wait_ms(1); + device.write(0x01); + device.write(0x00); + CS=1; + CS=0; + device.write(0x6); + CS=1; + CS=0; + device.write(0x02); + device.write((i&0xff00)>>8); + device.write(i&0xff); + device.write((0xDA)); + CS=1; + pc.printf("Address= %x %x\n",((i&0xff00)>>8), (i&0xff)); + } + +} +int main() +{ + pc.printf("device Started\n"); + device.format(8, 0); + device.frequency(1000000); + pc.printf("START Write\n"); + write(); + pc.printf("START Read\n"); + read(); +} \ No newline at end of file
diff -r 000000000000 -r d6075c37f0a4 mbed-os.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Tue Aug 13 05:35:58 2019 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#c966348d3f9ca80843be7cdc9b748f06ea73ced0