I am using an ARDUINO MEGA2560
Here is the datasheet of my device, the MB85RS16N
Trying to read device's manufacturer ID. Can't seem to get any real information. I'm aware that once you use the RDID command, that 32 bits (for this specific device) are sent to the MISO pin on the SPI device and able to be obtained by SPI.transfer and any dummy values can be sent for this.
Here is what I've done
- Ensured that the Pins are correctly going into the correct GPIO slots, which on the MEGA2560 for SPI are 50, 51, 52, and 53.
- Checked all the physical connections and ensured with multi-meter that they work and don't interfere
- Checked for physical damage to SPI device.
- Checked orientation to ensure I didn't mix up sides.
- Because I bought 5 of these, I re-soldered a new one and tried to use that in case the first SPI device was broken.
also performed previous step on the new one to ensure all connections were fine.
I'm brand new at this, but am wondering if it has something to do with the Clock not properly syncing? I know that the datasheet says that the device runs at 20Mhz but the ARDUINO MEGA2560 runs at 16MHz. I also do not have on the SPI device pins 3 (WP) and 7 (HOLD) connected to anything, since I believe I do not need them for this test.
Let me know if you need more information or pictures. I hope this is a Coding error.
#include <SPI.h>
// FRAM: MB85RS16N
// SPI
// 16Kilobits memory a.k.a. 2 KiloBytes
//**FRAM IC Pinout**
// 1: CS - Chip select pin
// 2: MISO - Serial data output pin (Master input, Slave output) [This reads data]
// 3: WP - Write protect pin
// 4: GND - Ground pin
// 5: MOSI - Serial data input pin (Master output, Slave input) [This writes data]
// 6: SCK - Serial clock pin
// 7: HOLD - Hold pin
// 8: VDD - Supply voltage pin
//**FRAM IC SPI Commands** Uses binary to communicate with the chip
// OP codes
#define WREN B00000110 //WREN command. Write enable latch (WEL), which must be set before you can write
#define WRDI B00000100 //WRDI command. Resets WEL so you can no longer write.
#define
RDSR B00000101 //RDSR command. Reads status register data. SPDR holds
byte about to be shifted out of MOSI line and data shifted in the MISO
line
#define WRSR B00000001 //WRSR command. Writes data to nonvolatile memory bit of status register
#define READ B00000011 //READ command. Reads FRAM memory cell aray data.
#define WRITE B00000010 //WRITE command. Writes data to FRAM memory cell array.
#define RDID B10011111 //RDID command. Reads fixed device ID.
// Pinouts
#define MISO 50 // Yellow jumper MISO
#define MOSI 51 // Blue jumper MOSI
#define SCK 52 // Green jumper SCK
#define SS 53 // White jumper CS
void setup() {
Serial.begin(9600);
pinMode(MISO, INPUT); // Incoming data from the FRAM
pinMode(MOSI, OUTPUT); // Outgoing data to the FRAM
pinMode(SCK,OUTPUT); // sets serial clock to output
pinMode(SS, OUTPUT); // sets slaveselect to output
digitalWrite(SS, HIGH); // ensure SS stays high
// Set up to match device datasheet
SPISettings FRAM(20000000, MSBFIRST, SPI_MODE0);
SPI.begin(); // Initializes the SPI bus by setting SCK, MOSI, and CS(SS) to outputs,
// pulling SCK and MOSI low, and CS(SS) high.
// Write get device ID
SPI.beginTransaction(FRAM);
digitalWrite(SS, LOW);
SPI.transfer(RDID); // Sends OP code to FRAM chip
Serial.print ("Manufacturer: ");
Serial.println(SPI.transfer(0x00),HEX); // prints manufacturer ID
Serial.print ("Continuation code: ");
Serial.println(SPI.transfer(0x00),HEX); // prints Continuation code
Serial.print ("Product ID 1: ");
Serial.println(SPI.transfer(0x00),HEX); // prints Product ID 1
Serial.print ("Product ID 2: ");
Serial.println(SPI.transfer(0x00),HEX); // prints Product ID 2
digitalWrite(SS, HIGH);
SPI.endTransaction();
}
void loop() {
while(1);
}
Here is my output
Manufacturer: 0
Continuation code: 0
Product ID 1: 0
Product ID 2: 0