本帖最后由 shinekl 于 2009-12-21 20:43 编辑
我用的是430FW4系列做主控芯片,因为芯片本身没有SPI,所用我用IO口模拟SPI,用ADS采集PT100的信号,但是总是得不到信号J5总是0,最悲哀的是写了个简单的读写寄存器的程序得到的结果J5总是0,请高手指点一下,在这多谢了
或者哪位高手可以分享程序参考一下,非常谢谢了!!!!我邮箱509019189@qq.com,重谢
现在问题程序贴出来,麻烦指点一下,在线等
main函数:
P1OUT |= 0x40; //使能start=1
P5OUT |= 0x80; //禁用reset=1
delay(200) ;
reset();
delay(200) ;
write_4register(0x40,0x03,0xC1,0x00,0x30,0x74);//向MUX0开始的四个寄存器写;其中AIN0 is the positive channel,AIN1 is the negative channel,PGA gain = 128,
data rate = 1kSPS;VBIAS 未用;
delay(200);
write_2register(0x4A,0x01,0x0F,0x0c);//写IDAC0和IDAC1,其中DOUT和DRDY共用;第一个IDA流过AIN0
delay(200);
J5=sampling()*2.048;
子函数:
reset()//复位
{
unsigned int k,Data=0x06;
for(k = 0; k < 8; k++)
{
if(Data & 0x80) SET_DOUT;//单片机给ad发1
else CLR_DOUT;//单片机给ad发0
SET_SCLK;
Data <<= 1;
CLR_SCLK;
}
SET_DOUT;
}
void write_2register(unsigned int Address,unsigned int Data,unsigned int Data2) /////1次写2个寄存器
{
unsigned int m,n,long=0x01;
for(i = 0; i < 8; i++)
{
if(Address & 0x80) SET_DOUT;//单片机给ad发1
else CLR_DOUT;//单片机给ad发0
SET_SCLK;
Address <<= 1;
CLR_SCLK;
}
for(j = 0; j < 7;j++)
{ if(long & 0x80) SET_DOUT;//单片机给ad发1
else CLR_DOUT;//单片机给ad发0
SET_SCLK;
long<<= 1;
CLR_SCLK;}
for(m= 0; m < 8; m++)
{
if(Data & 0x80) SET_DOUT;
else CLR_DOUT;
SET_SCLK;
Data <<= 1;
CLR_SCLK;
}
for(n= 0; n < 8; n++)
{
if(Data2& 0x80) SET_DOUT;
else CLR_DOUT;
SET_SCLK;
Data <<= 1;
CLR_SCLK;
}
SET_DOUT;
}
float sampling(void)/////读24位数
{
unsigned long int readData2=0x000000;
unsigned char i,j, Data=0x12;
while(READ_DIN); // 等待ADC完成
for(i= 0; i < 8; i++) //写入0x12h命令
{
if(Data & 0x80) SET_DOUT;
else CLR_DOUT;
SET_SCLK;
Data <<= 1;
CLR_SCLK;
}
SET_DOUT; //写入空操作
for(j = 0; j < 24; j++) //读数据
{
SET_SCLK;
readData2 <<= 1;
if(READ_DIN==0x01) readData2= readData2|0x000001;
CLR_SCLK;
}
return(readData2/8388607.0);}
谢谢指教!!!!!!!!!!!!!!!
|
|