//**************************** Read Data *****************************
unsigned int ReadData(unsigned int addr,unsigned char *data,unsigned int n)
{
unsigned char *a, temp;
a = (unsigned char*)&addr;
SPIBR = 0x11;
SPICR2 = 0x0d; //enable cs0;
SPICR1 |= 0x80;
while(!(SPISR & 0x02));
SPIDR = 0x03;
for(i = 1; i < 4; i++)
{
while(!(SPISR & 0x02));
SPIDR = a[i]; //use SPI 4-level FIFO
}
while(!(SPISR & 0x20)); //发送未完成死循环
//temp = SPIDR; //这个是不是错误的先注释
SPICR4 |=0x80; //同时清空发送FIFO和接收FIFO
delay_ms_spi(100);
for(i=0;i
{
delay_ms_spi(10);
/////////////****************************************************大爷的这两句不能注释,注释后为错
while(!(SPISR & 0x02)); //发送FIFO满死循环*******************初步怀疑为预读先写 不过DataSheet中并没有明确表明!!!
SPIDR = 0x00;
/////////////****************************************************大爷的这两句不能注释,注释后为错
while(!(SPISR & 0x04)); //接收FIFO空死循环
*data = SPIDR;
data++;
delay_ms_spi(10);
}
SPICR4 |=0x80; //同时清空发送FIFO和接收FIFO
SPICR2 = 0x0c; //disable cs0
}
阅读(860) | 评论(0) | 转发(0) |