SPI communication Teensy+NOR Flash Memory

Status
Not open for further replies.

shexp

New member
Hello.

I have a project to establish the SPI communication between N25Q00A Micron NOR Flash Memory and Teensy 3.1

The connections are listed below:

N25Q00A-->Teensy 3.1
MISO--> pin 12
MOSI--> pin 11
DQ2--> pin 22
DQ3--> pin 23
CS--> pin 2
CLK--> pin 13


I initially dealt with SPI library in Arduino and obtained successful operation. Example code for a read shown below for reading ID and flag status register.

Code:
#include <SPI.h>

const int miso = 12;
const int mosi = 11;
const int sck = 13;
const int cs = 2; //cs pin connected to flash memory.
const int dq2 = 22;
const int dq3 = 23;

const int kill = 33; //Kill switch
const int powerLed = 30; //Power LED


void setup() {
  pinMode(miso, OUTPUT);
  pinMode(mosi, OUTPUT);
  pinMode(dq2, OUTPUT);
  pinMode(dq3, OUTPUT);
  pinMode(sck, OUTPUT);
  pinMode(cs, OUTPUT);

  digitalWrite(miso, LOW);
  digitalWrite(mosi, LOW);
  digitalWrite(sck, HIGH);
  digitalWrite(cs, HIGH);
  digitalWrite(dq2, LOW);
  digitalWrite(dq3, LOW);

  pinMode (powerLed, OUTPUT);// Led 1
  digitalWrite(powerLed, HIGH); // indicate device is on

  Serial.begin(9600); //Set up serial
  delay(500);
  while (!Serial) {
  }
  SPI.begin(); // initialize spi my setting MOSI, SS, SCK as outputs
  SPI.setMOSI(11);
  SPI.setMISO(12);
  SPI.setSCK(13);
}


void loop() {

  SPI.beginTransaction(SPISettings (2000000, MSBFIRST, SPI_MODE0));

  while (Serial.available() > 0)
  {
    char c = Serial.read();

    switch (c)
    {

      case '\r':
        break;

      case '\n':
        break;

      case 'a':
        {
          int result;
          digitalWrite(cs, LOW);
          SPI.transfer(0x9E);
          int n = 4;
          for (int i = 0; i < n; i++) {
            byte result = 0;
            result = SPI.transfer(0);
            Serial.print("Byte Number ");
            Serial.print(i);
            Serial.print(": ");
            Serial.println(result, HEX);
            if (i == 3) {
              n = 4 + result;
            }
          }

          digitalWrite(cs, HIGH);
          Serial.println(result);
        }

      case 'o':
        {
          int result;
          digitalWrite(cs, LOW);
          SPI.transfer(0x70);
          result = SPI.transfer(0);
          digitalWrite(cs, HIGH);
          Serial.println(result);
        }
    }
  }

  SPI.endTransaction();
}


Afterwards however, I was writing to the non-volatile register when I began obtaining all results as FF. My inclination was that I had set the operation of the NOR flash memory to operate in dual or quad mode and hence the results I was obtaining were all FF because my commands were not being sent through in the same manner that dual and quad more require it to be.
Note: No matter what I'm reading, no matter if the location is written to, the result is always FF.
Note: I have tried changing clock speed and mode (mode0 and mode3 supported in this NOR flash device).

I didn't know how to use the SPI library in Arduino to create a code for dual/quad mode (if it can be done even) so I decided to go with the bit bang method. I did the process for both dual and quad operation, as well as extended for checking. The code did not work to execute the SPI communication as the only results I manage to read from the pins are the results I had written to those pins. The code below shows reading of non-volatile register for dual I/O , however, it is the same for reading anything and the same for quad and extended I/O.

Code:
const int miso = 12;
const int mosi = 11;
const int sck = 13;
const int cs = 2; //cs pin connected to flash memory.
const int dq2 = 22;
const int dq3 = 23;

const int kill = 33; //Kill switch
const int powerLed = 30; //Power LED

byte SPIDualTransfer(int _send1, int _send2) { //also try by not changing INPUT and OUTPUT Everytime?!?
  byte _receive = 0;
  byte _receive2 = 0;
  for (int i = 3; i >= 0; i--) {
    pinMode(miso, OUTPUT);
    pinMode(mosi, OUTPUT);
    digitalWrite(mosi, bitRead(_send1, i));
    digitalWrite(miso, bitRead(_send2, i));
    pinMode(miso, INPUT);
    pinMode(mosi, INPUT);
    digitalWrite(sck, LOW);
    bitWrite(_receive, 2 * i, digitalRead(mosi));
    bitWrite(_receive2, 2 * i + 1, digitalRead(miso));
    digitalWrite(sck, HIGH);
  }

  _receive2 != _receive;

  return _receive2;
}


void setup() {
  pinMode(miso, OUTPUT);
  pinMode(mosi, OUTPUT);
  pinMode(dq2, OUTPUT);
  pinMode(dq3, OUTPUT);
  pinMode(sck, OUTPUT);
  pinMode(cs, OUTPUT);

  digitalWrite(miso, HIGH);
  digitalWrite(mosi, HIGH);
  digitalWrite(sck, HIGH);
  digitalWrite(cs, HIGH);
  digitalWrite(dq2, HIGH);
  digitalWrite(dq3, HIGH);

  pinMode (powerLed, OUTPUT);// Led 1
  digitalWrite(powerLed, HIGH); // indicate device is on

}


void loop() {

  while (Serial.available() > 0)
  {
    char c = Serial.read();

    switch (c)
    {

      case '\r':
        break;

      case '\n':
        break;

      case 'a':
        {
          int result;
          digitalWrite(cs, LOW);
          SPIDualTransfer(7, 12);
          result = SPIDualTransfer(0, 0);
          Serial.println(result);
          break;
        }

    }
  }
}

The output for the code above would be 0 as that is the last thing written to the pins.

Any help on this would be much appreciated. Thanks.
 
Status
Not open for further replies.
Back
Top