I have wired a Macronix MX35LF1GE4AB Flash memory into an arduino Uno using Logic Level Shifters. What I try to do with it is to dump its contents.

In order to do so, I am implementing the following sketch:

#include <SPI.h> 

#define LASTBLOCK 1023
#define LASTPAGE 63
#define LASTBYTE 2111

#define PAGE_READ 13h

#define BUFFER_LEN 2111 

int page_to_read = 1;
int block_to_read = 1;

// We store each page to Microcontroiller's ram
byte buffer[BUFFER_LEN]; 

void setup() {
 SPI.beginTransaction(SPISettings(14000000, MSBFIRST, SPI_MODE0));
// Serial.begin(9600);

void loop() {

  // I need to reset the counts before reading any block 
  if(page_to_read > LASTPAGE){
    page_to_read = 1;
    block_to_read ++;

  if(block_to_read > LASTBLOCK){
    return ;

  if(page_to_read == LASTPAGE){
  } else if (page_to_read == 1) {


Now what I want is to populate the buffer byte buffer[BUFFER_LEN] with data, so I can send them over a serial port.

How I can achieve that?

  • 1
    SPI.transfer(buffer, BUFFER_LEN); -- arduino.cc/en/Reference/SPITransfer
    – Majenko
    Feb 27, 2022 at 16:48
  • Other than what Nick and Majenko point out, for proper use of SPI library, you should always call SPI.begin() in your setup (unless you are running it as a slave) because it help to setup the proper IO states of MOSI, MISO and SS, etc.. SPI.beginTransaction() should be called before the SPI.transfer(), and SPI.endTransaction() to be called after you done with the data transfer. This allows other tasks to be able to use the SPI bus.
    – hcheung
    Mar 1, 2022 at 0:56

1 Answer 1

#define BUFFER_LEN 2111 
byte buffer[BUFFER_LEN];

That will definitely not work because the Uno has 2048 bytes of RAM, some of which are needed by the system. The serial buffers, for example, are 64 bytes each.

  • So I'll need a 32byte buffer? Feb 28, 2022 at 7:56
  • Yes, a smaller buffer will help.
    – Nick Gammon
    Feb 28, 2022 at 8:09
  • Why do you think you need a buffer at all when you're just outputting through serial?
    – Majenko
    Feb 28, 2022 at 8:59
  • In order to fan the data read from spi though USB serial, though I can just read them byte by byte. Also I'll need to transcode them as well in hex. Futhermore I'll need to send the page and the block id's in order to recontruct the data into a file in my computer. Feb 28, 2022 at 12:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.