Atmel JEDEC info for SPI Flash.
[goodfet] / firmware / apps / spi / spi.c
index 94fbf0e..6e503f2 100644 (file)
@@ -66,9 +66,11 @@ unsigned char spitrans8(unsigned char byte){
 //! Enable SPI writing
 void spiflash_wrten(){
   SETSS;
+  /*
   P5OUT&=~SS; //Drop !SS to begin transaction.
   spitrans8(0x04);//Write Disable
   P5OUT|=SS;  //Raise !SS to end transaction.
+  */
   P5OUT&=~SS; //Drop !SS to begin transaction.
   spitrans8(0x06);//Write Enable
   P5OUT|=SS;  //Raise !SS to end transaction.
@@ -142,7 +144,7 @@ void spiflash_pokeblock(unsigned long adr,
     spitrans8(buf[i]);
   SETSS;  //Raise !SS to end transaction.
   
-  //while(spiflash_status()&0x01);
+  while(spiflash_status()&0x01);
   
   return;
 }
@@ -205,7 +207,7 @@ void spihandle(unsigned char app,
   case SPI_JEDEC://Grab 3-byte JEDEC ID.
     P5OUT&=~SS; //Drop !SS to begin transaction.
     spitrans8(0x9f);
-    len=3;
+    len=3;  //Length is variable in some chips, 3 minimum.
     for(i=0;i<len;i++)
       cmddata[i]=spitrans8(cmddata[i]);
     txdata(app,verb,len);
@@ -222,17 +224,19 @@ void spihandle(unsigned char app,
     spiflash_setstatus(0x02);
     spiflash_wrten();
     
-    P5OUT&=~SS; //Drop !SS to begin transaction.
-    spitrans8(0x02); //Poke command.
+    P5OUT&=~SS;         //Drop !SS to begin transaction.
+    spitrans8(0x02);    //Poke command.
     
     //First three bytes are address, then data.
     for(i=0;i<len;i++)
       spitrans8(cmddata[i]);
-    P5OUT|=SS;  //Raise !SS to end transaction.
+    P5OUT|=SS;          //Raise !SS to end transaction.
     
     
-    while(spiflash_status()&0x01)//while busy
+    
+    while(spiflash_status()&0x01)
       P1OUT^=1;
+    
     P1OUT&=~1;
     
     txdata(app,verb,len);