我在用SPI来读写ST95040(EEPROM),搞了一天了,还是不对,SPI有数据输出,而95040一点反应也没有.不知道哪里出错,请搞过的兄弟们帮我看一看.哪里有错 误.
//三线制,MOSI MISO SCLK void SpiInit(void) { SPIC1 = 0x5c; // Master mode, SPI enable. SPIC2 = 0x00; // SPIBR = 0x00; // 2MHZ PTADD_PTADD7 = 1;// Out }
unsigned char Read_SR(void) { unsigned char Tmp;
SPID = 0x05; //M95040 Read Stat Register while (!SPIS_SPTEF);
Tmp = SPID; while (!SPIS_SPRF);
return Tmp; }
unsigned char EepromByteRead(unsigned int EepromAddr) { unsigned char Tmp; SPID = 0x03; //M95040 Read Command while (!SPIS_SPTEF);
SPID = EepromAddr; // M95040 Read Address while (!SPIS_SPTEF); Tmp = SPID; while (!SPIS_SPRF);
return Tmp; }
oid EepromByteWrite(unsigned char EepromAddr, unsigned char data) { SPID = 0x01; //M95040 Wrtie Stat Register while (!SPIS_SPTEF);
SPID = 0x06; //M95040 Write Enable while (!SPIS_SPTEF); SPID = 0x02; //M95040 Send Write Command while (!SPIS_SPTEF);
SPID = EepromAddr; //Send Writen Address while (!SPIS_SPTEF); SPID = data; //Writen 8 bit MSB while (!SPIS_SPTEF); }
|