在一个设计中采用了AD7328采集8路外部电压信号,现在在软件读的过程中发现每次只能读出1路电压数据,请各位大虾帮忙看看问题出在哪里?对着datasheet看了很久都没有搞定。
我设定为每路的输入都是0-10V,不采用队列读取方式。
初始化
void MNL_Init(void)
{
SpiInit();
WriteToAd7328(0xBFE0);//1011 1111 1110 0000 //设置量程寄存器1 0-10V
ReadFromAd7328(); // set range register 1
WriteToAd7328(0xDFE0);//1101 1111 1110 0000 //设置量程寄存器2 0-10V
ReadFromAd7328(); // set range register 2
WriteToAd7328(0xFFE0);//1111 1111 1110 0000 //设置序列寄存器 0-7通道
ReadFromAd7328(); // set SEQUENCE REGISTER
MnlInitOK=TRUE;
}
循环读取AD0-AD7的电压值
uint08 MNL_ReadAll(void)
{
uint16 tmp[8]={0,0,0,0,0,0,0,0};
uint08 i;
WriteToAd7328(0x8000 | (0<<11));
ADConversion(); //产生转换时序
MnlBuf[0]=ReadFromAd7328(); //读取数据
WriteToAd7328(0x8000 | (1<<11));
ADConversion();
MnlBuf[1]=ReadFromAd7328();
WriteToAd7328(0x8000 | (2<<11));
ADConversion();
MnlBuf[2]=ReadFromAd7328();
WriteToAd7328(0x8000 | (3<<11));
ADConversion();
MnlBuf[3]=ReadFromAd7328();
WriteToAd7328(0x8000 | (4<<11));
ADConversion();
MnlBuf[4]=ReadFromAd7328();
WriteToAd7328(0x8000 | (5<<11));
ADConversion();
MnlBuf[5]=ReadFromAd7328();
//WriteToAd7328(0xE040);
//tmp[6]=ReadFromAd7328();
WriteToAd7328(0x8000 | (6<<11));
ADConversion();
MnlBuf[6]=ReadFromAd7328();
//WriteToAd7328(0xE020);
//tmp[7]=ReadFromAd7328();
WriteToAd7328(0x8000 | (7<<11));
ADConversion();
MnlBuf[7]=ReadFromAd7328();
return TRUE;
}
|