目前用PIC24FJ64GA010驱动AD9951,驱动代码如下:
////////////////////////////////////////////////////////////////////////////////
static void DumpDelay ( void )
{
unsigned char i = 3;
while (i--);
}
////////////////////////////////////////////////////////////////////////////////
// 说明:9951双线接口写操作,上升沿采样输入
static void AD9951TwoLineWr ( unsigned char Data )
{
signed char i;
AD9951_SCLK_LOW ();
SET_AD9951_SDIO_OUTPUT();
for ( i = 7; i >=0; i-- )
{
if ( Data & (1 << i) )
{
AD9951_SDIO_HIGH ();
}
else
{
AD9951_SDIO_LOW ();
}
DumpDelay ();
AD9951_SCLK_HIGH ();
DumpDelay ();
AD9951_SCLK_LOW ();
DumpDelay ();
}
}
////////////////////////////////////////////////////////////////////////////////
// 说明:9951双线接口读操作, 下降沿采样输出
static unsigned char AD9951TwoLineRd ( void )
{
unsigned char Data = 0;
signed char i;
AD9951_SCLK_LOW ();
SET_AD9951_SDIO_INPUT ();
for ( i = 7; i >=0; i-- )
{
AD9951_SCLK_HIGH ();
DumpDelay ();
AD9951_SCLK_LOW ();
DumpDelay ();
if ( IS_AD9951_SDIO_HIGH() )
{
Data |= (1 << i);
}
}
return Data;
}
////////////////////////////////////////////////////////////////////////////////
// 说明:写寄存器
static void AD9951WrReg ( unsigned char Cmd, unsigned char *p_Para, unsigned char Length )
{
unsigned char Temp;
AD9951_CHIP_SEL();
#ifdef AD9951_CTRL_BY_2LINE
AD9951TwoLineWr (Cmd);
#else
Temp = SPITransferByte ( Cmd );
#endif
while ( Length-- )
{
#ifdef AD9951_CTRL_BY_2LINE
AD9951TwoLineWr (*(p_Para++));
#else
Temp = SPITransferByte ( *(p_Para++) );
#endif
}
AD9951_CHIP_DESEL();
DumpDelay ();
AD9951_IO_UPDATE_HIGH();
DumpDelay ();
AD9951_IO_UPDATE_LOW();
}
////////////////////////////////////////////////////////////////////////////////
// 说明:读寄存器
static void AD9951RdReg ( unsigned char Cmd, unsigned char *p_Para, unsigned char Length )
{
unsigned char Temp;
AD9951_CHIP_SEL();
#ifdef AD9951_CTRL_BY_2LINE
AD9951TwoLineWr ( Cmd );
#else
Temp = SPITransferByte ( Cmd );
#endif
while ( Length-- )
{
#ifdef AD9951_CTRL_BY_2LINE
*(p_Para++) = AD9951TwoLineRd ();
#else
*(p_Para++) = SPITransferByte ( 0xff );
#endif
}
AD9951_CHIP_DESEL();
}
////////////////////////////////////////////////////////////////////////////////
// 说明:写32位寄存器
void AD9951WrLongReg ( unsigned char Reg, unsigned long int Para )
{
unsigned char TempBuff[4];
signed char i;
for ( i = 0; i < 4 ; i++ )
{
TempBuff
= Para >> ((3-i)*8);
}
AD9951WrReg ( AD9951_CMD_WR | Reg, &TempBuff[0], 4 );
}
////////////////////////////////////////////////////////////////////////////////
// 说明:读32位寄存器
unsigned long int AD9951RdLongReg ( unsigned char Reg )
{
unsigned long int Data = 0;
unsigned char TempBuff[4], i;
AD9951RdReg ( AD9951_CMD_RD | Reg, &TempBuff[0], 4 );
for ( i = 0; i < 4 ; i++ )
{
Data |= TempBuff;
if ( i < 3 )
{
Data <<= 8;
}
}
return Data;
}
现在情况如下,示波器上面看到写入到AD9951的数据是正确的,但是读到的寄存器值始终不对,按道理, 只要9951上电正常,操作寄存器应该是没问题的
希望有有过9951的朋友指点一下
下面的是DDS电路
DDS驱动电路 (原文件名:DDS电路.JPG)
手册写道
All data input to the AD9951 is registered on the rising edge of SCLK.
All data is driven out of the AD9951 on the falling edge of SCLK.
应该是在下降沿输出上升沿保持的。
看手册中的图就明白了。
一周热门 更多>