0% found this document useful (0 votes)
130 views8 pages

Arduino Esp32 Con w25q128

This document provides a program for reading and writing to an SPI Flash memory using an ESP32, which is compatible with Arduino Nano. It includes functions to create, open, and delete files, along with a directory listing feature. Additionally, it outlines the necessary connections between the ESP32 and the W25Q128JV chip.

Uploaded by

m3939010
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
130 views8 pages

Arduino Esp32 Con w25q128

This document provides a program for reading and writing to an SPI Flash memory using an ESP32, which is compatible with Arduino Nano. It includes functions to create, open, and delete files, along with a directory listing feature. Additionally, it outlines the necessary connections between the ESP32 and the W25Q128JV chip.

Uploaded by

m3939010
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

***PROGRAMA PARA LEER MEMORIA SPI CON ESP32, FUNCIONA OK CON

ARDUINO NANO***
#include <SerialFlash.h>
#include <SPI.h>

const int FlashChipSelect = 4;

void setup(){

[Link](115200);
delay(3000);
[Link]("SPI Flash");

if (![Link](FlashChipSelect)) {
[Link]("Unable to access SPI Flash chip");
while(1){}
}

void loop(){

// MAIN MENU
[Link]("");
[Link]("");
[Link]("SerialFlash Read and Write");
[Link]("(switch your terminal to no line endings)");
[Link]("--------------------------");
[Link]("1) Create a new file");
[Link]("2) Open a file");
[Link]("3) Delete a file");
[Link]("--------------------------");
[Link]("Select a number");
while(![Link]()){}
char choice = [Link]();
while([Link]()){[Link]();}

switch(choice){

case '1':
newFile();
break;

case '2':
openFile();
break;

case '3':
deleteFile();
break;

default:
[Link]("Invalid Selection");

/* Create a new file


*
* Request filename up to 20 chars
* Request a size up to 256 bytes
* Request some contents
* Create a file
*/
void newFile(){

[Link]("Enter a filename"); // Request filename from user


while(![Link]()){} // Wait for user

char filename[20] = {}; // buffer to store user filename


[Link](' ', filename, 20);
while([Link]()){[Link]();}

[Link]("Enter a filesize in bytes"); // Request file size from user


while(![Link]()){} // Wait for user

char sizeArray[3] = {}; // buffer to store requested file size


[Link](' ', sizeArray, 3);
while([Link]()){[Link]();}
int filesize = atoi(sizeArray); // Convert char array to int (i.e. "40" to 40)

if([Link](filename, filesize)){ // Returns false if file already exists

SerialFlashFile file; // Open the file we just created for writing


file = [Link](filename);
[Link]("Write some file contents:"); // Request file contents from user
while(![Link]()){} // Wait for user

char contents[256] = {}; // buffer to store file contents


[Link](255, contents, 256);
while([Link]()){[Link]();} // Empty read buffer
[Link](contents, filesize); // Write the contents buffer
[Link]("");
[Link]("New file ");
[Link](filename);
[Link](" created with size ");
[Link](filesize);
[Link](" bytes!");
}else{
[Link]("");
[Link]("There was an error creating this file (does it already exist?)");
}

return;

/* Open a file
*
* Print the directory listing
* Request filename up to 20 chars
* Open file and display contents
*/
void openFile(){

printDir(); // Function to print the directory listing

[Link]("Enter a filename to OPEN"); // Request file name from user


[Link]();
while(![Link]()){} // Wait for user

char filename[20] = {}; // buffer to store the file name


[Link](' ', filename, 20);
while([Link]()){[Link]();}

[Link](filename);

SerialFlashFile file;
file = [Link](filename); // open the file
if (file) {
[Link]("File Name: ");
[Link](filename);
[Link]();
[Link]("File Size: ");
[Link]([Link]());
[Link](" bytes");
[Link]();
[Link]("File Contents:");
char buffer[256] = {}; // create a buffer for the file contents
[Link](buffer, 256); // read file to buffer
[Link](buffer);
}else{
[Link]("File not found!");
}

return;

}
/* Delete a file
*
* Print the directory listing
* Request filename up to 20 chars
* Delete File
*/
void deleteFile(){

printDir(); // Function to print the directory listing

[Link]("Enter a filename to DELETE"); // Request file name from user


while(![Link]()){} // Wait for user

char filename[20] = {}; // buffer to store file name


[Link](' ', filename, 20);
while([Link]()){[Link]();}

[Link](filename); // Delete the file

return;

/* Print Directory
*
* Print a list of all files on the chip
* Stolen from SerialFlash library example "ListFiles"
*/
void printDir(){
[Link]("Directory Listing");
[Link]("-----------------");

[Link]();
while (1) {
char filename[64];
uint32_t filesize;

if ([Link](filename, sizeof(filename), filesize)) {


[Link](" ");
[Link](filename);
spaces(20 - strlen(filename));
[Link](" ");
[Link](filesize);
[Link](" bytes");
[Link]();
} else {
break; // no more files
}
}
}

void spaces(int num) {


for (int i=0; i < num; i++) {
[Link](" ");
}
}

CONEXIONES
ESP32 W25Q128JV
3V3 --------> 3.3V
PIN4 --------> CS
PIN18 --------> CLK
PIN23 --------> DI
PIN19 --------> DO
3V3 --------> WP
3V3 --------> HOLD
GND --------> GND

You might also like