#define MISO BIT2
#define SCK BIT3
+
//This could be more accurate.
//Does it ever need to be?
#define SPISPEED 0
P5OUT|=SS;
}
-//! Read and write an SPI bit.
+
+//! Read and write an SPI byte.
unsigned char spitrans8(unsigned char byte){
unsigned int bit;
//This function came from the SPI Wikipedia article.
return byte;
}
+
//! Enable SPI writing
void spiflash_wrten(){
P5OUT&=~SS; //Drop !SS to begin transaction.
P5OUT|=SS; //Raise !SS to end transaction.
}
+
//! Grab the SPI flash status byte.
unsigned char spiflash_status(){
unsigned char c;
P5OUT|=SS; //Raise !SS to end transaction.
return c;
}
+
+
//! Grab the SPI flash status byte.
void spiflash_setstatus(unsigned char c){
P5OUT&=~SS; //Drop !SS to begin transaction.
P5OUT|=SS; //Raise !SS to end transaction.
txdata(app,verb,len);
break;
+
+
case SPI_JEDEC://Grab 3-byte JEDEC ID.
P5OUT&=~SS; //Drop !SS to begin transaction.
spitrans8(0x9f);
txdata(app,verb,len);
P5OUT|=SS; //Raise !SS to end transaction.
break;
+
+
case PEEK://Grab 128 bytes from an SPI Flash ROM
-
spiflash_peek(app,verb,len);
break;
+
+
case POKE://Poke up bytes from an SPI Flash ROM.
spiflash_setstatus(0x02);
spiflash_wrten();
for(i=0;i<len;i++)
spitrans8(cmddata[i]);
P5OUT|=SS; //Raise !SS to end transaction.
- while(spiflash_status()&0x01);//while busy
+
+
+ while(spiflash_status()&0x01)//while busy
+ P1OUT^=1;
+ P1OUT&=~1;
+
txdata(app,verb,len);
break;
+
+
case SPI_ERASE://Erase the SPI Flash ROM.
spiflash_wrten();
P5OUT&=~SS; //Drop !SS to begin transaction.
spitrans8(0xC7);//Chip Erase
P5OUT|=SS; //Raise !SS to end transaction.
+
+
+ while(spiflash_status()&0x01)//while busy
+ P1OUT^=1;
+ P1OUT&=~1;
+
txdata(app,verb,0);
break;
+
case SETUP:
spisetup();
txdata(app,verb,0);