输出是类似晶振的信号,不是正弦波啊,频率也不对。
#include "sys.h"
#include "delay.h"
#define AD9854_DATA GPIOB->ODR//PB高八位
#define AD9854_ADDR GPIOA->ODR//PA低八位
#define ad9854_reset PCout(0)
#define ad9854_osk PCout(1)//OSK触发信号
#define ad9854_fbh PCout(2)//FSK触发信号
#define ad9854_updata PCout(3)
#define ad9854_wr PCout(4)
#define ad9854_rd PCout(5)
unsigned char ControlRegister[]={0x04,0x00,0x00,0x60}; //AD9854 特殊功能寄存器地址 无倍频,Mode 0
unsigned char FTW[]={0xf1,0xd2,0x4d,0x62,0x10,0x00}; //Frequency Tuning Word1 20M 5KHZ的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 )
{
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
#include "delay.h"
#define AD9854_DATA GPIOB->ODR//PB高八位
#define AD9854_ADDR GPIOA->ODR//PA低八位
#define ad9854_reset PCout(0)
#define ad9854_osk PCout(1)//OSK触发信号
#define ad9854_fbh PCout(2)//FSK触发信号
#define ad9854_updata PCout(3)
#define ad9854_wr PCout(4)
#define ad9854_rd PCout(5)
unsigned char ControlRegister[]={0x04,0x00,0x00,0x60}; //AD9854 特殊功能寄存器地址 无倍频,Mode 0
unsigned char FTW[]={0xf1,0xd2,0x4d,0x62,0x10,0x00}; //Frequency Tuning Word1 20M 5KHZ的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();
delay_ms(10);
AD9854_Set_Mode0();
while(1);
}
//IO初始化
void Init_Port(void)
{
RCC->APB2ENR |= 1<<2 ;
GPIOA->CRL &= 0xff000000;
GPIOA->CRL |= 0x00333333 ;
GPIOA->ODR |= 0x00ff ;
RCC->APB2ENR |= 1<<3 ;
GPIOB->CRH &= 0xffffffff ;
GPIOB->CRH |= 0x33333333 ;
GPIOB->ODR |= 0xff00 ;
RCC->APB2ENR |= 1<<4 ;
GPIOC->CRL &= 0xff000000 ;
GPIOC->CRL |= 0x00333333 ;
GPIOC->ODR |= 0x00ff ;
}
//写入一个控制字
void AD9852_Send(unsigned char addr,unsigned char data) //????????
{
ad9854_wr = 1; // AD9854_WR_SET;
AD9854_ADDR &= 0xff00|addr;
AD9854_ADDR |= 0x00ff&addr;
ad9854_wr = 1; // AD9854_WR_SET;
AD9854_DATA &= 0x00ff|data<<8;
AD9854_DATA |= 0xff00&data<<8;
ad9854_wr = 0; // AD9854_WR_CLR;
ad9854_wr = 1; // AD9854_WR_SET;
ad9854_updata = 1; // AD9854_UPDATA_SET;
ad9854_updata = 0; // AD9854_UPDATA_CLR;
}
//AD9854初始化 特殊功能寄存器给地址
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]);
addr++;
}
ad9854_updata = 1; // AD9854_UPDATA_SET;
ad9854_updata = 0; // AD9854_UPDATA_CLR;
}
//MODE0 频率相位和幅度给特定控制字的地置
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=6;counter>0;counter--) //??Frequency Tuning Word 1
{
AD9852_Send(addr,FTW[6-counter]);
addr++;
}
for(addr=0x21,counter=2;counter>0;counter--) //??Output shaped keying multiplier
{
AD9852_Send(addr,OSK[2-counter]);
addr++;
}
ad9854_updata = 1; // AD9854_UPDATA_SET;
ad9854_updata = 0; // AD9854_UPDATA_CLR;
}
//
//void single_wave(unsigned long int fre)
//{
// unsigned char addr,i;
// unsigned long int ff;
// unsigned char *p;
// ff=(unsigned long int)(4294967296*fre/20000000);//20M
//
// p=(unsigned char*)&ff;
//
// for(addr=0x04,i=0;i<6;i++) //??Frequency Tuning Word 1
// {
// AD9852_Send(addr,*(p+5-i));
// addr++;
// }
//
// for(addr=0x00,i=0;i<2;i++) //??Phase Adjust Register 1
// {
// AD9852_Send(addr,PAR[i]);
// 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<6;counter++) //??Frequency Tuning Word 1
// {
// AD9852_Send(addr,*(p+5-counter));
// addr++;
// }
//}
ad9854_reset = 0 ; // AD9854_RESET_CLR;
ad9854_wr = 1 ; // AD9854_WR_SET;
ad9854_rd = 0 ; // AD9854_RD_CLR;
ad9854_updata = 0 ; // AD9854_UPDATA_CLR;
改为
ad9854_wr = 1 ; //将读,写控制端设为无效 ad9854_rd= 1 ;
AD9854_reset = 1;
delay_us(10);
AD9854_reset = 0; //复位AD9854
ad9854_updata = 0 ; // AD9854_UPDATA_CLR;
delay_ms(1000);//延时1S,等待初始化完成,10个系统时钟周期。
ad9854_reset = 0 ; // AD9854_RESET_CLR;
ad9854_wr = 1 ; // AD9854_WR_SET;
ad9854_rd = 0 ; // AD9854_RD_CLR;
ad9854_updata = 0 ; // AD9854_UPDATA_CLR;
改为
ad9854_wr = 1 ; //将读,写控制端设为无效
ad9854_rd= 1 ;
AD9854_reset = 1;
delay_us(10);
AD9854_reset = 0; //复位AD9854
ad9854_updata = 0 ; // AD9854_UPDATA_CLR;
delay_ms(1000);//延时1S,等待初始化完成,10个系统时钟周期。
AD9854_reset = 1;
AD9854_reset = 0;
你知道reset这个高电平的宽度是多少?
手册要求是多少?
一周热门 更多>