原子哥,我用的是您的程序,驱动9854为什么不行呢?两个正弦信号均没有输出。板子是现成的模块,接线地址口A5-A0接PC13-PC8,数据口D7-D0接PC7-PC0,RDB接PB13。
IO-Updata接PB15,WRB接PB14,MASTER RESET接PB12。
#define AD9854_DATA GPIOC->ODR
#define AD9854_ADDR GPIOC->ODR
#define ad9854_reset  
Bout(12)
#define ad9854_rd PBout(13)
#define ad9854_wr PBout(14)
#define ad9854_updata PBout(15)
unsigned char ControlRegister[]={0x14,0x4f,0x00,0x60}; //AD9852控制寄存器初始值,Mode 0
unsigned char FTW[]={0x00,0x00,0x37,0xec}; //Frequency Tuning Word 1 倍频300MHz后输出频率对应的FTW值
unsigned char PAR[]={0x00,0x00}; //Phase Adjust Register 1
unsigned char OSK[]={0x0a,0xff}; //Output shaped keying multiplier, 650mv
void single_wave(unsigned long int fre);
void Init_AD9854(void);
void AD9854_Set_Mode0(void);
void AD9852_Send(unsigned char addr,unsigned char data);
void change_frequency(unsigned long int fre_temp);
void Init_Port(void);
int main( void )
{
Stm32_Clock_Init(9);
// 9倍频
delay_init(72);
// 72M晶振时延时
delay_ms(200);
Init_Port();
Init_AD9854();
single_wave(1000000);
while(1);
}
void Init_Port(void)
{
RCC->APB2ENR |= 1<<3 ;
GPIOB->CRH &= 0x0000ffff ;
//通用推挽输出模式PB15-12
GPIOB->CRH |= 0x33330000 ;
GPIOB->ODR |= 0xf000 ;
RCC->APB2ENR |= 1<<4 ;
GPIOC->CRL &= 0x00000000 ;
//通用推挽输出
GPIOC->CRL |= 0x33333333 ;
GPIOC->CRH &= 0x00000000 ;
GPIOC->CRH |= 0x33333333 ;
GPIOC->ODR |= 0xffff ;
}
void AD9852_Send(unsigned char addr,unsigned char data) //按照并行输入时序
{
ad9854_wr = 1;
// AD9854_WR_SET;
AD9854_ADDR &= 0x00ff|addr<<8;
AD9854_ADDR |= 0xff00&addr<<8;
ad9854_wr = 1;
// AD9854_WR_SET;
AD9854_DATA &= 0xff00|data;
AD9854_DATA |= 0x00ff&data;
ad9854_wr = 0;
// AD9854_WR_CLR;
ad9854_wr = 1;
// AD9854_WR_SET;
ad9854_updata = 1;
// AD9854_UPDATA_SET;
ad9854_updata = 0;
// AD9854_UPDATA_CLR;
}
void Init_AD9854(void)
{
unsigned char addr;
unsigned char i;
ad9854_reset = 0 ;
// AD9854_RESET_CLR;
ad9854_wr = 1 ;
// AD9854_WR_SET;
ad9854_rd = 0 ;
// AD9854_RD_CLR;
ad9854_updata = 0 ;
// AD9854_UPDATA_CLR;
addr = 0x1d;
for(i=4;i>0;i--)
{
AD9852_Send(addr,ControlRegister[4-i]);
//控制寄存器模式0
addr++;
}
}
void AD9854_Set_Mode0(void)
//Mode 0 设置
{
unsigned char addr;
unsigned char counter;
for(addr=0x00,counter=2;counter>0;counter--)
//设置Phase Adjust Register 1
{
AD9852_Send(addr,PAR[2-counter]);
addr++;
}
for(addr=0x04,counter=4;counter>0;counter--)
//设置Frequency Tuning Word 1
{
AD9852_Send(addr,FTW[4-counter]);
addr++;
}
for(addr=0x21,counter=2;counter>0;counter--)
//设置Output shaped keying multiplier
{
AD9852_Send(addr,OSK[2-counter]);
addr++;
}
}
void single_wave(unsigned long int fre)
{
unsigned char addr,i;
unsigned long int ff;
unsigned char *p;
ff=(unsigned long int)(4294967296*fre/300000000);
p=(unsigned char*)&ff;
for(addr=0x04,i=0;i<4;i++) //设置Frequency Tuning Word 1
{
AD9852_Send(addr,*(p+3-i));
addr++;
}
for(addr=0x00,i=0;i<2;i++) //设置Phase Adjust Register 1
{
AD9852_Send(addr,PAR
);
addr++;
}
for(addr=0x21,i=2;i>0;i--) //设置Output shaped keying multiplier
{
AD9852_Send(addr,OSK[2-i]);
addr++;
}
}
void change_frequency(unsigned long int fre_temp)
{
unsigned char addr,counter;
unsigned char *p;
p=(unsigned char*)&fre_temp;
for(addr=0x04,counter=0;counter<4;counter++) //设置Frequency Tuning Word 1
{
AD9852_Send(addr,*(p+3-counter));
addr++;
}
}
---------------------------------
请问你有STM32 的AD9854 程序吗?调了几天了都有问题,频率不能上200M,数据传送也有问题
楼主调出来了?
一周热门 更多>