void Spi_Data_Out( uchr length, uchr d )
{
for ( ; length > 0 ; length -- )
{
Spi_sck = 0;
Spi_Delay(0xf);
if( d & 0x80 )
Spi_out_port = 1;
else
Spi_out_port = 0;
d <<= 1;
Spi_Delay(0xf);
Spi_sck = 1;
Spi_Delay(0xf);
}
Spi_sck = 0;
}
void Spi_Char_Wr( uchr addr, uchr d )
{
Spi_cs = SPI_ENABLE;
Spi_Delay(0xff);
Spi_Data_Out(8,CMD_WRITE);
Spi_Data_Out(8,addr);
Spi_Data_Out(8,d);
Spi_cs = SPI_DISABLE;
Spi_Delay(0xff);
}
///////////输出数据的代码没问题,在proteus中可以看到结果
uchr Spi_Char_Rd( uchr addr)
{
uchr r = 0;
Spi_cs = SPI_ENABLE;
Spi_Delay(0xff);
Spi_Data_Out(8,CMD_READ);
Spi_Data_Out(8,addr);
Spi_cs = SPI_DISABLE;
Spi_Delay(0xff);
r = Spi_Data_In(8);
Spi_cs = SPI_DISABLE;
Spi_Delay(0xff);
return r;
}
uchr Spi_Data_In( uchr length )
{
uchr in = 0;
Spi_sck = 1;
Spi_Delay(0xff);
Spi_cs = SPI_ENABLE;
Spi_Delay(0xff);
for ( ; length > 0 ; length -- )
{
in <<= 1;
Spi_sck = 0;
Spi_Delay(0xff);
if ( Spi_in_port )
in |= 0x01;
else
in &= 0xfe;
Spi_sck = 1;
Spi_Delay(0xff);
}
return in;
}
这个是仿照别人的代码写的程序,读取时钟返回0xff ,请高手帮帮忙呀。。。
你的EEPROM是什么型号 ,
如果是24CXX系列的不用模拟SPI吧,随便2个端口就可以搞定。
我有24CXX读写程序,自己再用。如果需要给你发你份
引用: 引用 2 楼 wangfan027 的回复:
普通的E2PROM不是用I2C接口么?
有SPI接口的EEPROM,网络芯片8019就有提供SPI接口连接这样的EEPROM,9346就是SPI接口的EEPROM。
但是没有玩过这方面的驱动。
不知道有没有人用过proteus的SPI debuger , 怎么发送数据呀?