How To Write And Read Flash Memory Using Arduino

Table of contents:

How To Write And Read Flash Memory Using Arduino
How To Write And Read Flash Memory Using Arduino

Video: How To Write And Read Flash Memory Using Arduino

Video: How To Write And Read Flash Memory Using Arduino
Video: ESP32 Flash Memory - Store Permanent Data (Write and Read) 2024, April
Anonim

In this article, we will look at how to write to and read from flash memory using an Arduino using the 25L8005 microcircuit as an example.

How to write and read flash memory using Arduino
How to write and read flash memory using Arduino

Necessary

  • - flash memory chip with SPI support;
  • - an adapter for memory or a panel with zero gain (ZIF-panel);
  • - Arduino;
  • - computer;
  • - connecting wires.

Instructions

Step 1

First, we need to make it so that we can easily connect to the microcircuit. To do this, you can use either a special adapter, to which you have to solder the microcircuit, or (which is preferable) use a zero-gain panel (the so-called ZIF panel).

Flash memory chip on ZIF-panel
Flash memory chip on ZIF-panel

Step 2

Now let's put together the electrical diagram for connecting the flash memory chip to the Arduino. We will use the SPI interface for memory programming, so we will connect to the standard pins:

- CS - digital pin 10, - MOSI - digital pin 11, - MISO - digital pin 12, - SCK - digital pin 13.

Diagram of connecting Flash memory to Arduino
Diagram of connecting Flash memory to Arduino

Step 3

Before writing data to memory, it is necessary to erase the sector or page to which we are going to write. If there is not much data to be written (in our tutorial example it will be only 16 bytes), then it is enough to erase 1 sector. From the documentation for the microcircuit, we see that the erasing sequence is as follows: set the write permission (1 byte), send the erase command (1 byte) and the address (3 bytes), set the write prohibition (1 byte). This is exactly what the above sketch does. Let's load it into Arduino. After the sketch is completed, the flash drive is ready for recording.

Flash sector erase sketch
Flash sector erase sketch

Step 4

Now let's write the data. Let's take a small array of 16 bytes as an example. As you can see from the documentation, first you need to set the write permission (1 byte), then send the write command (1 byte), the starting address (3 bytes) and data (in our example, 16 bytes), at the end set the write prohibition (1 byte).

Upload the sketch to Arduino. After executing this sketch, our test array should have been written to flash memory. Let's check if this is so.

A sketch of writing an array of bytes to flash memory
A sketch of writing an array of bytes to flash memory

Step 5

Let's write a sketch to read 16 bytes from flash memory. Let's load it into Arduino and open the serial port monitor. In the monitor, as expected, our array, read from memory using the Arduino, will be displayed 1 time per second.

Recommended: