void SpiInit(void)
{
SPIC1 = 0x5c; // Master mode, SPI enable.
SPIC2 = 0x00; //
SPIBR = 0x00; // 2MHZ
PTADD_PTADD7 = 1;// Out
//PTAD_PTAD7 = 1; // Initail zero
}
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;
}
void 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);
}
[此贴子已经被作者于2008-9-1 16:48:23编辑过]
这是我写ST95040(EEPROM)的SPI程序,但是不知道哪里错了,就是没有感觉,只有单片机输出数据,而
95040没有数据返回,请大家帮我看一看,我的SPI是不是有问题啊????
我也是这么认为的,但是我把ST95040换了一个,也不行.
我总觉的是自已的时序没有写对头,所以才这样
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |