|
用SPI读AD7888通道0,1,2转换的结果。收到的数据总是不对,不知道下面的程序有什么问题,请各位大侠们帮忙看看。该怎么修改呢?
void AD_READ(void) //读AD数据
{ unsigned char temp,clear;
unsigned int i,ad1,ad2,ad0;
SELECT_AD; //选通AD芯片
SPDR = 0x00; //指令通道0
while (!(SPSR&(1<<SPIF)));
clear = SPSR;
clear = SPDR;
SPDR = 0x00;
while (!(SPSR&(1<<SPIF)));
clear = SPSR;
temp = SPDR;
NOSELECT_AD;
SELECT_AD; //选通AD芯片
SPDR = 0x08;
while (!(SPSR&(1<<SPIF)));
clear = SPSR;
clear = SPDR;
ad0=(unsigned int)(temp*256)+clear;
SPDR = 0x08; //指令通道1
while (!(SPSR&(1<<SPIF)));
clear = SPSR;
temp=SPDR;
NOSELECT_AD;
SELECT_AD; //选通AD芯片
SPDR = 0x10; //指令通道2
while (!(SPSR&(1<<SPIF)));
clear = SPSR;
clear = SPDR;
ad1=(unsigned int)(temp*256)+clear;
SPDR = 0x10;
while (!(SPSR&(1<<SPIF)));
clear = SPSR;
temp=SPDR;
NOSELECT_AD;
SELECT_AD; //选通AD芯片
SPDR = 0x00; //指令通道0
while (!(SPSR&(1<<SPIF)));
clear = SPSR;
clear = SPDR;
ad2=(unsigned int)(temp*256)+clear;
SPDR = 0x00;
while (!(SPSR&(1<<SPIF)));
NOSELECT_AD;
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|