I have an MX25R8035F flash module. I am trying to communicate with this module through SPI.
I tried sending it simple commands like the 0x90 command to retrieve its manufacturer ID and this does work so I know the wiring is okay.
However when I want to save data in its memory something goes wrong.
Either the writing of data fails or the retrieval of data fails but I don't know which one or how to fix it.
Sadly I don't have an oscilloscope available to help me with debugging.
I hope someone could help me out with this problem.
Below is the code I use to write to the flash module.
#include <SPI.h>
const int chipSelectPin = 7;
// I have tried other SPI Modes as well but the result stayed the same
SPISettings settings(10000000, MSBFIRST, SPI_MODE0);
void setup() {
Serial.begin(9600);
SPI.begin();
SPI.setDataMode(SPI_MODE0);
pinMode(chipSelectPin, OUTPUT);
delay(2000);
}
void loop() {
unsigned int result1, result2, result3, result4, result5, result6, result7;
uint32_t cmd = 0x020B0000; // 02 is Page Program command, 0B0000 is the address I want to write to
writeEnable(); // set the write enable register to 1
SPI.beginTransaction(settings);
digitalWrite(chipSelectPin, LOW);
result1 = SPI.transfer(cmd);
// write the following lines of data to memory
result2 = SPI.transfer(0x01);
result3 = SPI.transfer(0x05);
result4 = SPI.transfer(0x01);
result5 = SPI.transfer(0x06);
result6 = SPI.transfer(0x06);
result7 = SPI.transfer(0x02);
digitalWrite(chipSelectPin, HIGH);
SPI.endTransaction();
delay(1000);
Serial.println("Start reading...");
cmd = 0x030B0000; // 03 is the Read command and 0B0000 is the address I want to read from
SPI.beginTransaction(settings);
digitalWrite(chipSelectPin, LOW);
result1 = SPI.transfer(cmd);
result2 = SPI.transfer(0x00);
result3 = SPI.transfer(0x00);
result4 = SPI.transfer(0x00);
result5 = SPI.transfer(0x00);
result6 = SPI.transfer(0x00);
result7 = SPI.transfer(0x00);
digitalWrite(chipSelectPin, HIGH);
SPI.endTransaction();
Serial.println("Received: ");
Serial.print(result1, HEX);
Serial.print(" ");
Serial.print(result2, HEX);
Serial.print(" ");
Serial.print(result3, HEX);
Serial.print(" ");
Serial.print(result4, HEX);
Serial.print(" ");
Serial.print(result5, HEX);
Serial.print(" ");
Serial.print(result6, HEX);
Serial.print(" ");
Serial.print(result7, HEX);
Serial.println();
Serial.println();
Serial.println();
delay(1000);
}
void writeEnable() {
uint8_t data = 0x06;
SPI.beginTransaction(settings);
digitalWrite(chipSelectPin, LOW);
SPI.transfer(data);
digitalWrite(chipSelectPin, HIGH);
SPI.endTransaction();
}