回读不正确......第一句:上电之后,是否做了reset操作是什么概念,是指AD5752R芯片?
程序读写操作参照
ExampleCode_DAC_AD5754.zip来写的,把AD5752R里不同的寄存器地址照着手册改了一下,这什么情况?求解答。
这是读写和配置代码:
//DA_Delay;
void DA_Delay(int length)
{
while (length >0)
length--;
}
/********************************************************************************
Function that writes to the AD5754R via the SPI port.
********************************************************************************/
void WriteToAD57524RViaSpi(long int *RegisterData)
{
long int ValueToWrite = *RegisterData;
int i;
// SPI start
IOWR_ALTERA_AVALON_PIO_DATA(PIO_DA_SYNC_BASE,1);//SET_SYNC();
DA_Delay(10);
IOWR_ALTERA_AVALON_PIO_DATA(PIO_DA_SYNC_BASE,0);//CLR_SYNC(); //bring SYNC low
DA_Delay(1);
//Write out the 24 bit ControlWord
for(i=0; i<24; i++)
{
IOWR_ALTERA_AVALON_PIO_DATA(PIO_DA_SCLK_BASE,1);//SET_SCLK();
DA_Delay(5);
if(0x800000 == (ValueToWrite & 0x800000))//MSB方式优先
{
IOWR_ALTERA_AVALON_PIO_DATA(PIO_DA_SDIN_BASE,1);//SET_SDIN(); //Send one to SDI pin
}
else
{
IOWR_ALTERA_AVALON_PIO_DATA(PIO_DA_SDIN_BASE,0);//CLR_SDIN(); //Send zero to SDI pin
}
DA_Delay(5);
IOWR_ALTERA_AVALON_PIO_DATA(PIO_DA_SCLK_BASE,0);//CLR_SCLK();
DA_Delay(5);
ValueToWrite <<= 1; //Rotate data
DA_Delay(5);
}
// SPI ends
IOWR_ALTERA_AVALON_PIO_DATA(PIO_DA_SYNC_BASE,1);//SET_SYNC();
DA_Delay(10);
}
/********************************************************************************
Function that read from the AD5754R via the SPI port.
********************************************************************************/
void ReadFromAD57524RViaSpi(long int *RegisterData)
{
unsigned int i = 0;
unsigned int iTemp = 0;
unsigned long RotateData = 0;
unsigned long Noop = Nop;
// SPI start
IOWR_ALTERA_AVALON_PIO_DATA(PIO_DA_SYNC_BASE,1);//SET_SYNC();
DA_Delay(20);
IOWR_ALTERA_AVALON_PIO_DATA(PIO_DA_SYNC_BASE,0);//CLR_SYNC(); //bring SYNC low
DA_Delay(2);
for(i=0; i<24; i++)
{
IOWR_ALTERA_AVALON_PIO_DATA(PIO_DA_SCLK_BASE,1);//SET_SCLK();
DA_Delay(5);
//////////////////////////////////////////////////
if(0x800000 == (Noop & 0x800000))
{
IOWR_ALTERA_AVALON_PIO_DATA(PIO_DA_SDIN_BASE,1);//SET_SDIN(); //Send one to SDI pin
}
else
{
IOWR_ALTERA_AVALON_PIO_DATA(PIO_DA_SDIN_BASE,0);//CLR_SDIN(); //Send zero to SDI pin
}
//////////////////////////////////////////////////
IOWR_ALTERA_AVALON_PIO_DATA(PIO_DA_SCLK_BASE,0);//CLR_SCLK();
DA_Delay(5);
iTemp = IORD_ALTERA_AVALON_PIO_DATA(PIO_DA_SDO_BASE);//iTemp = GP4DAT;//Read DIN of AD736, P4.4->SDout
RotateData <<= 1;
if(0x00000010 == (iTemp & 0x00000010))
{
RotateData |= 1;
}
//Rotate data
//////////////////////////////////////////////////
Noop <<= 1;
//////////////////////////////////////////////////
DA_Delay(5);
}
// SPI ends
IOWR_ALTERA_AVALON_PIO_DATA(PIO_DA_SYNC_BASE,1);//SET_SYNC();
DA_Delay(20);
*RegisterData=RotateData;
}
//---------------------
//Configure AD5754R
//---------------------
void ConfigAD57524R()
{
int i;
long int *p;
long int ins[2] = {0, 0};
/*IOWR_ALTERA_AVALON_PIO_DATA(PIO_DA_BIN_BASE,0); //双极性以二进制补码输出
IOWR_ALTERA_AVALON_PIO_DATA(PIO_DA_LDAC_BASE,0);//更新设置。在SYNC的上升沿更新所寻址的DAC寄存器
IOWR_ALTERA_AVALON_PIO_DATA(PIO_DA_CLR_BASE,1); //不使能清除为零平代码
*/
IOWR_ALTERA_AVALON_PIO_DATA(PIO_DA_BIN_BASE,0);
IOWR_ALTERA_AVALON_PIO_DATA(PIO_DA_LDAC_BASE,0);
ins[1] = PowerCtrl_Reg | Power_RefShut; //上电设置,开A、B通道,关闭内部基准电压(使用外部基准2.048V)
ins[0] = OutputRange_Reg | Channel_AB | Range4; //通道输出范围设置
p = ins;
for(i=0; i<2; i++)
{
WriteToAD57524RViaSpi(p);
DA_Delay(200);
p++;
}
}
这是主程序里的代码:
cstr = Write | DAC_Reg | Channel_A | 0x00AEC0; |
|
//VoutA=-2.6v |
WriteToAD57524RViaSpi(&cstr);
cstr = Write | DAC_Reg | Channel_B | 0x005140; |
|
//VoutB=2.6V,参照P23 |
WriteToAD57524RViaSpi(&cstr);
//DA反馈读取
cstr = Read | DAC_Reg | Channel_A; //the CommAssistant display
WriteToAD57524RViaSpi(&cstr);
//DA_Delay(20);
ReadFromAD57524RViaSpi(&buf); |
//Read select register, using two instruction cycles |
tx[2] = ((buf)&0xFF0000)>>16;
tx[1] = ((buf)&0x00FF00)>>8;
tx[0] = (buf)&0x000000FF;