Using Flash Memory - MX25L4006e

Hi everyone,

I’m doing a project that involves storing data in memory. I chose to purchase MX25L4006E Flash memory for this purpose.
Datasheet: http://www.macronix.com/Lists/DataSheet/Attachments/1781/MX25L4006E,%203V,%204Mb,%20v1.6.pdf

I’m having trouble getting the device to work correctly. I have experience with the SPI protocol from experience with serial ADCs and DACs.

I’m trying to do a simple function to test the functionality:

  1. input the command WREN (0x06) to set the status register WEL bit to 1; and
  2. read the status register and print it out to the serial monitor.

Doesn’t sound very hard right… Apparently it is.

here’s my code, please see if you can see any problems:

#include <SPI.h>
#include <serial.h>

/*

SPI library dictates, digital Pins:
11 - MOSI - master in slave out
12 - MISO - master out slave in
13 - SCK  - serial clock

*/

// chip_select pin definitions
#define MEM_CHIPSELECT 7
#define MEM_HOLD_PIN 4
#define MEM_WRITEPROTECTION_PIN 3


#define STATUS_CMD B00000100  //read status register
#define WREN_CMD B00000110    //write enable
#define WRDI_CMD 0x04    //write disable
#define RDSR_CMD 0x03    //read data
#define SE_CMD 0x20      //sector erase
#define BE_CMD 0xD8      //block erase
#define CE_CMD 0xC7      //chip erase

byte status_contents;

//setup the program for SPI and serial transfers
void setup () {
  
  Serial.begin(9600);
  
  pinMode(MEM_CHIPSELECT, OUTPUT);
  pinMode(MEM_HOLD_PIN, OUTPUT);
  pinMode(MEM_WRITEPROTECTION_PIN, OUTPUT);
  
  SPI.begin();                             //  Initialize SPI parameters
  SPI.setBitOrder(MSBFIRST);               //  MSB to be sent first
  SPI.setDataMode(SPI_MODE0);
  
  digitalWrite(MEM_CHIPSELECT, HIGH); //disable MEM CS
  digitalWrite(MEM_HOLD_PIN, HIGH); //disable MEM HOLD FUNCTION
  digitalWrite(MEM_WRITEPROTECTION_PIN, HIGH); //disable write protection
    
}


//puts values of status register in status_contents and returns a 1 if the chip is busy
void checkStatusRegister () {
  digitalWrite(MEM_CHIPSELECT, LOW);
  SPI.transfer(STATUS_CMD);
  status_contents = SPI.transfer(0x0);
  Serial.println( status_contents );  
  digitalWrite(MEM_CHIPSELECT, HIGH);
  
}

void writeEnable() {
  digitalWrite(MEM_CHIPSELECT, LOW);
  SPI.transfer(WREN_CMD);
  digitalWrite(MEM_CHIPSELECT, HIGH);
}

void writeDisable() {
  digitalWrite(MEM_CHIPSELECT, LOW);
  SPI.transfer(WRDI_CMD);
  digitalWrite(MEM_CHIPSELECT, HIGH);
}

void loop () {
  writeEnable();
  checkStatusRegister ();

}

Thanks so much,
Dan

I found a problem: I was interfacing the arduino to the chip directly. I forgot that the chip will only take 3.3V digital inputs... whoops

Will update when I get hold of some MOSFETs for some bLLCs.