Shivanand Gowda / Mbed OS SPI_EEPROM_2MB

Dependencies:   M95M02D

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 
00002 #include "mbed.h"
00003 #include "M95M02D.h"
00004 #include <string>
00005  
00006 Serial pc(USBTX, USBRX); // tx, rx
00007 DigitalOut WP(D7);
00008 int main()
00009 {
00010     
00011     char str2[24] = {0};
00012     char str3[24] = {0};
00013     char str4[24] = {0};
00014     
00015     
00016     WP=1;
00017     M95M02D eeprom(PA_7, PA_6, PA_5, PA_4,D13,D14);
00018     pc.printf("SPI init done\r\n\r\n");
00019   
00020     // Read Identification information Related to chip.
00021  
00022   int ID = eeprom.ReadSignature();
00023   printf("ID  and Signature is :%d",ID);
00024  
00025     wait(1);
00026  
00027  
00028     eeprom.readStream(0x00, str2, 23);
00029     pc.printf("After Read 1 String Here: %s\r\n",str2);
00030     eeprom.readStream(23, str4, 23);
00031     pc.printf("After Read 2 String Here: %s\r\n",str2);
00032     eeprom.readStream(46, str3, 23);
00033     pc.printf("After Read 3 String Here: %s\r\n",str2);
00034  
00035     char stri[] = "Shivanand Gowda Ramaiah";
00036  
00037     pc.printf("Writing String Here: %s\r\n",stri);
00038     eeprom.writeStream(0x00, stri, 23); //Writing Strings in three Differnt addresses.
00039     eeprom.writeStream(23, stri, 23);
00040     eeprom.writeStream(46, stri, 23);
00041      
00042     pc.printf("Before String Here: %s\r\n",str2);
00043     eeprom.readStream(0x00, str2, 23);
00044     pc.printf("After Read 1 String Here: %s\r\n",str2);
00045     eeprom.readStream(23, str4, 23);
00046     pc.printf("After Read 2 String Here: %s\r\n",str2);
00047     eeprom.readStream(46, str3, 23);
00048     pc.printf("After Read 3 String Here: %s\r\n",str2);
00049     pc.printf("Exited from program  \r\n");
00050     return 0;
00051  
00052 }
00053