1

I'm trying to set up SPI in order to interact with a CMOS flash, the MX25L6405DMI-12G to be exact. As a test I'm trying to read the identifier (RDID) which should return 3 fixed bytes. Currently the chip seems to respond to my request but the first bytes is 0xC3 instead of 0xC2 and the rest of the bytes are all 0xFF.

Now I haven't got a clue what's going on as my understanding of electronics is still limited.

The sketch:

#include <SPI.h>

void setup()
{
  Serial.begin(9600);
  SPI.begin();
  SPI.beginTransaction(SPISettings(SPI_CLOCK_DIV8, MSBFIRST, SPI_MODE3));
  digitalWrite(10, LOW);
  SPI.transfer(0x9F); // RDID
  Serial.println(SPI.transfer(0));
}

void loop()
{
  Serial.println(SPI.transfer(0));
  Serial.println(SPI.transfer(0));
  Serial.println(SPI.transfer(0));
  delay(1000);
}

My attempt at drawing the circuit, I hope it's clear enough. The level converter is the SparkFun bi-directional LLC which should be able to handle SPI at lower frequencies although not optimal (according to reviews).

enter image description here

Of course I attempted various things like adding delays (10ms) between the transactions to give the CMOS time to respond (or isn't this a thing? Again, my knowledge is limited.) or trying different clock frequencies but that doesn't seem to make any difference in output. I've read the datasheet multiple times and see no obvious thing I'm missing but I don't understand most of it. What am I doing wrong here?

Edit:

I also stumbled upon the SPIMemory library which seems to be able to talk to the MX25L4005 chip which seems similar to the one I have. I've had a peekaboo at the source and attempted to replicate it. They also fetch the manufacturer/device ID's but use a different command. I've annotated my code with the relevant description from the datasheet for convenience.

void setup()
{
  Serial.begin(9600);
  SPI.begin();
  Serial.println("Beginning transfer");
  SPI.beginTransaction(SPISettings(SPI_CLOCK_DIV8, MSBFIRST, SPI_MODE0));

  // The instruction is initiatedby driving the CS# pin low and shift
  // the instruction code "90h" followed by two dummy bytes and one bytes address (A7~A0).
  digitalWrite(10, LOW);
  SPI.transfer(0x90);
  Serial.println(SPI.transfer('R'));
  Serial.println(SPI.transfer('R'));
  Serial.println(SPI.transfer(0));
  // After which, the Manufacturer ID for MXIC (C2h) and the Device ID are shifted out
  // on the falling edge of SCLK with mostsignificant bit (MSB) first as shown in figure 25.
  // The Device ID values are listed in Table of ID Definitions on page 16.
  // If the one-byte address is initially set to 01h, then the device ID will be read first
  // and then followed by the Manufacturer ID.The Manufacturer and Device IDs can be read 
  // continuously, alternating from one to the other.
  Serial.println(SPI.transfer('R')); // 195 = C3
  Serial.println(SPI.transfer('R')); // 31 = 1F
  // The instruction is completedby driving CS# high.
  digitalWrite(10, HIGH);  
}

I now receive two values (as expected) but the values are still off. The manufacturer ID is still returned as C3 and the device ID is 1F while that should be 0x16 as seen in the table from the datasheet below.

enter image description here

5
  • Try SPI_MODE0 - it's very rare that anything uses anything other than mode 0. – Majenko Oct 20 '20 at 20:13
  • + maybe that bidirectional level translation module might not be able to handle 2MHz clock? Or maybe the mosfets are fast enough but pull ups are too weak? – KIIV Oct 20 '20 at 20:56
  • 1
    In the mean time I've tried SPI_MODE0 which doesn't seem to make a difference sadly. I get the same results when using a 10KHz clock. – siebz0r Oct 21 '20 at 0:27
  • The particular flash works in both SPI_MODE3 and SPI_MODE0, and I don't think it is your code that caused the problem. I think if you have a 3v3 MCU, maybe try to eliminate the level-shifter and see how it go? – hcheung Oct 21 '20 at 2:28
  • @hcheung Thanks for confirming I'm not doing anything obviously wrong in my code. I have ordered a couple devices that might operate better. For now I've checked the power consumption of the flash (25mA) and what the nano clone can supply (~30mA?). I've also tested with a UNO and have the same results. I've tried some other operations but overall the chip doesn't seem to behave as expected. I must be understanding the datasheet wrong... – siebz0r Oct 23 '20 at 22:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.