I'm bought a Dataflash 16Mb chip from sparkfun: DataFlash 16Mbit AT45DB161D - COM-00301 - SparkFun Electronics
And I'm trying without success to make something happen. Below is my bare bones code that attempts to write a byte to the buffer, and then read it back.
//DataFlash pins
byte MOSI = 11;
byte MISO = 12;
byte SCLK = 13;
byte CS = 8;
byte RESET = 9;
byte data;
void setup()
{
Serial.begin(9600);
pinMode(MOSI, OUTPUT);
pinMode(MISO, INPUT);
pinMode(SCLK, OUTPUT);
pinMode(CS, OUTPUT);
pinMode(RESET, OUTPUT);
digitalWrite(CS,HIGH);
digitalWrite(RESET,HIGH);
pinMode(5, OUTPUT);
digitalWrite(5,HIGH);
SPCR = B01010000; // Set SPI config registry
digitalWrite(CS,LOW);
SPDR = B10000100;
SPDR = B11111111;
SPDR = B11111110;
SPDR = B10100000;
SPDR = B00111110;
while(!(SPSR & (1 << SPIF)));
digitalWrite(CS,HIGH);
delay(500);
digitalWrite(CS,LOW);
SPDR = B11010100;
SPDR = B11111111;
SPDR = B11111110;
SPDR = B10100000;
SPDR = B11111111;
//while(!(SPSR & (1 << SPIF)));
digitalWrite(5,LOW);
digitalWrite(CS,HIGH);
Serial.print(SPSR,DEC);
}
void loop()
{
}
It gets stuck in the second while loop if I uncomment it. I copied that while loop form the playground: http://www.arduino.cc/en/Tutorial/SPIEEPROM but I'm not sure what exactly its doing. Supposedly SPIF, is a bit in SPSR, the status registry, however I don't understand why its being shifted, why it is its own variable, and why it shits the 1 7 bits, when a flag should only be 0 or 1. Anyway, I get 0 when I read it back, not what it should be..