Hi all,
I try to read the Manufacturer ID of a SPI Flash W25Q80BV. The flash is 3.3V, so I use a CD4050 for level shifting 5V to 3.3V for SCK, SS, MOSI. MISO is connected directly between the flash and the Arduino.
The length wire is 15cm, and I have to slow down the clock to 1MHz in order to have no variation on the output of the flash.
I read "F8h" at this time in continous, whereas the datasheet indicates "EFh" for Spansion Manufacturer.
The code is very simple, so I don't know why I couldn't read the good value.
I use a Breadboard Mini Self-Adhesive and a Protoshield from sparkfun
Hereunder my code:
//SPI flash programmer for Winbond W25Q80BV DIP8
//Strap wire length 15cm
// CD4050 used as level shifter 5V to 3.3V
//Pins:
//Flash CD4050 Arduino Uno
// 8(VCC) 1(VDD) 3.3V
// 1(/CS) 2(OUTA)
// 3(INA) 10(SS)
// 5(DI) 4(OUTB)
// 5(INB) 11(MOSI)
// 6(CLK) 6(OUTC)
// 7(INB) 13(SCK)
// 4 8(VSS) GND
// 2(DO) 12(MISO)
// 3(/WP) 3.3V
// 7(/HOLD) 3.3V
// CD4050 datasheet: http://www.fairchildsemi.com/ds/CD/CD4049UBC.pdf
// W25Q80BV datasheet: http://www.winbond.com/NR/rdonlyres/4D2BF674-7427-4FC8-AEF0-1A534DF74F16/0/W25Q80BV.pdf
#include <SPI.h>
//Pin Definition
//#define MOSI 11
//#define MISO 12
//#define SCK 13
#define SS 10
//SPI command
#define ID 0x9F
//Read Manufacturer, Memory type and capacity
void deviceid()
{
digitalWrite(SS,LOW); //start spi transfert
SPI.transfer(ID); //send JEDEC ID command
byte MANUFACTURERID = SPI.transfer(0xFF);
byte MEMORYTYPE = SPI.transfer(0xFF);
byte CAPACITY = SPI.transfer(0xFF);
digitalWrite(SS,HIGH); //end spi transfert
Serial.println(MANUFACTURERID,HEX); //should read "EFh"
}
void setup()
{
Serial.begin(9600);
// digitalWrite(SS,HIGH); //already declared in SPI.cpp
// pinMode(SS, OUTPUT); //already declared in SPI.cpp
SPI.setBitOrder(MSBFIRST);
SPI.setClockDivider(SPI_CLOCK_DIV16); //16MHz div by 16=1MHz
SPI.setDataMode(SPI_MODE0);
SPI.begin();
}
void loop()
{
deviceid();
delay(100);
}
When I connect a Saleae logic anlyser, the output change to FFh, due to the input impedance of the analyser. So, I couldn't use the logic analyser to help me.
First, could you check my code, and tell me if it is correct or not ?