Shivanand Gowda / Mbed OS SPI_EEPROM

Dependencies:   EE25LC1024

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 
00002 // SPI Single IO NOR eeprom Library for Nucleo F767ZI Interfacing
00003 
00004 
00005 
00006 #include "mbed.h"
00007 #include "EE25LC1024.h"
00008 #include <string>
00009 
00010 Serial pc(USBTX, USBRX); // tx, rx
00011 DigitalOut WP(D7);
00012 int main()
00013 {
00014     
00015     char str2[24] = {0};
00016     char str3[24] = {0};
00017     char str4[24] = {0};
00018     
00019     
00020     WP=1;
00021     EE25LC1024 eeprom(PA_7, PA_6, PA_5, PA_4);
00022     pc.printf("SPI init done\r\n\r\n");
00023   
00024     // Read Identification information Related to chip.
00025 
00026   int ID = eeprom.ReleaseDPD_ReadSign();
00027   printf("ID  and Signature is :%d",ID);
00028 
00029     wait(1);
00030     // Reading eeprom Memory Status Register contents.
00031 
00032  
00033 
00034     eeprom.readStream(0x00, str2, 23);
00035     pc.printf("After Read 1 String Here: %s\r\n",str2);
00036     eeprom.readStream(23, str4, 23);
00037     pc.printf("After Read 2 String Here: %s\r\n",str2);
00038     eeprom.readStream(46, str3, 23);
00039     pc.printf("After Read 3 String Here: %s\r\n",str2);
00040 
00041 // write a stream of characters to arbitrary address 0x168
00042     char stri[] = "Shivanand Gowda Ramaiah";
00043 
00044     pc.printf("Writing String Here: %s\r\n",stri);
00045     eeprom.writeStream(0x00, stri, 23); //Writing Strings in three Differnt addresses.
00046     eeprom.writeStream(23, stri, 23);
00047     eeprom.writeStream(46, stri, 23);
00048     
00049 //   
00050 //    uint8_t a=eeprom.readRegister();
00051 //    read stream from 0x168
00052     
00053     pc.printf("Before String Here: %s\r\n",str2);
00054     eeprom.readStream(0x00, str2, 23);
00055     pc.printf("After Read 1 String Here: %s\r\n",str2);
00056     eeprom.readStream(23, str4, 23);
00057     pc.printf("After Read 2 String Here: %s\r\n",str2);
00058     eeprom.readStream(46, str3, 23);
00059     pc.printf("After Read 3 String Here: %s\r\n",str2);
00060 //
00061 //    for(int i=0; i<20;i++)
00062 //    pc.printf("Printing byte by byte %c\r\n",str2[i]);
00063 
00064 
00065    // eeprom.sectorErase(0x00);
00066 //    while(1) {
00067 //        uint8_t busy=eeprom.checkIfBusy();
00068 //        if(busy==0) {
00069 //            pc.printf("Not  Busy any More \r\n");
00070 //            break;
00071 //        } else if (busy==1)
00072 //            pc.printf("Busy Now \r\n");
00073 //    }
00074 
00075     pc.printf("Exited from program  \r\n");
00076     return 0;
00077 
00078 }