Shivanand Gowda / Mbed 2 deprecated SPI_FLASH_MEM_1Gb

Dependencies:   S70FL01GS mbed

Fork of SPI_FLASH_MEM by Shivanand Gowda

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

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