@Klaus_K Thank you so much. I'm getting close enough to my end goal. Added LCD display as well.. The only error I have is the device ID outputs 17 instead of 16 as defined in the datasheet of MX25L640 page 22.
Your Questions;
- Relay Control needs to be HIGH
- CS Pin: 10
- Yes, there is a board for MX25L640. Unfortunately, I can't show it for privacy consideration.
- Shield's pin number is not consistent with Arduino Due. I followed Arduino's pin numbering instead.
/* NOTES
Manufacturer ID for Macronix and the Device ID are shifted out on the falling edge of SCLK with
most significant bit (MSB) first as shown in Figure 26.
SHIELD PERPECTIVE:
MISO_1/BIOS SDO: Pin 108 Arduino DUE
MOSI_1/BIOS SDI: Pin 109 Arduino DUE
SCK_1/BIOS_SCL: Pin 110 Arduino DUE
*/
#include <SPI.h>
#include "Adafruit_LiquidCrystal.h"
#include "Wire.h"
#define SPI_DUMMY_BYTE 0x00
#define MX25_REMS_COMMAND 0x90
#define MX25_REMS_ADDRESS_MANUFACTURER_ID 0x00
#define MX25_REMS_ADDRESS_DEVICE_ID 0x01
#define PowerControl 11 //Shield power 3VDC power control pin
#define RelayCtrl 12 //Relay Control SPI pin MOSI & SCK.
#define SPI_CS_PIN 10 //Chip Select Pin
#define ModuleDetectPin 55 //Module insertion detect pin
SPISettings spiSettings( 100000, MSBFIRST, SPI_MODE0 ); // SPI_MODE0: CPOL = 0 | CPHA = 0 | Output Edge = Falling | Data Capture = Rising
// Connect via i2c, default address #0 (A0-A2 not jumpered)
Adafruit_LiquidCrystal lcd(0);
void setup()
{
pinMode(PowerControl, OUTPUT);
digitalWrite(PowerControl, HIGH); //Set it LOW to activate 3V based on Shield Schematic
pinMode(RelayCtrl, OUTPUT); //Enable Relay Control
digitalWrite(RelayCtrl, LOW); //Set HIGH to activate
pinMode(SPI_CS_PIN, OUTPUT);
digitalWrite(SPI_CS_PIN, HIGH); //Set LOW to activate
Serial.begin( 9600 );
while ( !Serial ); //Adding this line makes the board pause until you open the serial port, so you get to see that initial bit of data.
SPI.begin();
lcd.setBacklight(HIGH);
}
void loop()
{
lcd.begin(16, 2); //set up the LCD's number of rows and columns:
digitalWrite(PowerControl, LOW); //Turn ON 3V
digitalWrite(RelayCtrl, HIGH); //Set HIGH to turn relay ON (U2) and connect MOSI and SPI Clock
printMX25REMS();
delay(5000);
}
// See MX25L6406E DATASHEET
// Page 21 and 43
// Figure 26. Read Electronic Manufacturer & Device ID (REMS) Sequence (Command 90)
void printMX25REMS()
{
SPI.beginTransaction( spiSettings );
digitalWrite(SPI_CS_PIN, LOW); //Instruction is iniated by driving the CS# pin low based on manuf datasheet. Chip Select/Slave Slect
SPI.transfer( MX25_REMS_COMMAND ); //Shift the instruction code to 90h
SPI.transfer( SPI_DUMMY_BYTE ); //Followed by two dummy bytes
SPI.transfer( SPI_DUMMY_BYTE );
SPI.transfer( MX25_REMS_ADDRESS_DEVICE_ID ); //Followed by one byte address (A7~A0). 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.
//uint8_t: unsigned integer of 8bits length
uint8_t deviceID = SPI.transfer( SPI_DUMMY_BYTE );
uint8_t manufacturerID = SPI.transfer( SPI_DUMMY_BYTE );
SPI.endTransaction();
delay(1000);
/* IF & ELSE statement will wait till SCLK initiates */
/* square wave pattern from the initial power cycle */
if(deviceID < 0xFF)
{
Serial.print("Device ID: 0x" );
Serial.println(deviceID, HEX );
lcd.setCursor(0,0);
lcd.print("DeviceID is:"); // Print a message to the LCD.
lcd.setCursor(0,1); // set the cursor to column 0, line 1
lcd.print(deviceID, HEX);
delay(2000);
}
else
{
Serial.print( "Device ID:" );
Serial.println(" reading...wait ");
lcd.setCursor(0,0);
lcd.print("DeviceID is:"); // Print a message to the LCD.
lcd.setCursor(0,1); // set the cursor to column 0, line 1
lcd.print(" reading...");
delay(2000);
}
if(manufacturerID < 0xFF)
{
Serial.print( "Manuf ID: 0x" );
Serial.println( manufacturerID, HEX );
lcd.setCursor(0,0);
lcd.print("Manuf ID is:"); // Print a message to the LCD.
lcd.setCursor(0,1); // set the cursor to column 0, line 1
lcd.print(manufacturerID, HEX);
delay(2000);
}
else
{
Serial.print("Manuf ID:");
Serial.println(" reading...wait");
lcd.setCursor(0,0);
lcd.print("Manuf ID is:"); // Print a message to the LCD.
lcd.setCursor(0,1); // set the cursor to column 0, line 1
lcd.print(" reading...");
delay(2000);
}
digitalWrite( SPI_CS_PIN, HIGH ); //Instruction complete based on manuf datasheet
}
Output: