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 PAGE_READ_CACHE_SEQUENCIAL 03h
#define READ_FROM_CACHE 3Bh
#define PAGE_READ_CACHE_END 3Fh
#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){
SPI.transfer(PAGE_READ_CACHE_END);
} else if (page_to_read == 1) {
SPI.transfer(PAGE_READ);
SPI.transfer(PAGE_READ_CACHE_SEQUENCIAL);
}
SPI.transfer(READ_FROM_CACHE);
page_to_read++;
}
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 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?Dimitrios Desyllas– Dimitrios Desyllas2022年02月28日 07:56:47 +00:00Commented Feb 28, 2022 at 7:56
-
Yes, a smaller buffer will help.2022年02月28日 08:09:57 +00:00Commented Feb 28, 2022 at 8:09
-
Why do you think you need a buffer at all when you're just outputting through serial?Majenko– Majenko2022年02月28日 08:59:44 +00:00Commented 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.Dimitrios Desyllas– Dimitrios Desyllas2022年02月28日 12:54:16 +00:00Commented Feb 28, 2022 at 12:54
SPI.transfer(buffer, BUFFER_LEN);
-- arduino.cc/en/Reference/SPITransferSPI.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 theSPI.transfer()
, andSPI.endTransaction()
to be called after you done with the data transfer. This allows other tasks to be able to use the SPI bus.