野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10192|回复: 1

STM32F429外接AD9851产生信号

[复制链接]
发表于 2019-8-7 21:08:42 | 显示全部楼层 |阅读模式
要使用F4外界DDS模块  但是移植了一直不成功 有大佬指点一下吗
int main(void)
{
        int   i=0;
        double frequence=1000;
        LED_GPIO_Config();
        AD9851_IO_Init();
        ad9851_reset();
        ad9851_wr_parrel(0x01,2000);


        while (1)
        {
                LED1( ON );                         // áá
                Delay(0xFFFFFF);
                LED1( OFF );                  // Ãe
    Delay(0xFFFFFF);


        }
}
void AD9851_IO_Init(void)
{
   GPIO_InitTypeDef GPIO_InitStructure;
       
         RCC_AHB1PeriphClockCmd(ad9851_w_clk_GPIO_CLK, ENABLE);         //ê1ÄüPB,PE¶Ë¿úê±Öó
   RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);//ê1ÄüGPIOBê±Öó
                GPIO_InitStructure.GPIO_Pin = ad9851_w_clk_PIN|ad9851_fq_up_PIN|ad9851_rest_PIN;       

                /*éèÖÃòy½ÅÄ£ê½Îaêä3öÄ£ê½*/
                GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;   

    /*éèÖÃòy½ÅμÄêä3öààDíÎaíÆíìêä3ö*/
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

    /*éèÖÃòy½ÅÎaéÏà-Ä£ê½*/
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;

                /*éèÖÃòy½ÅËùÂêÎa2MHz */   
                GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;

                /*μ÷óÿaoˉêy£¬ê1óÃéÏÃæÅäÖÃμÄGPIO_InitStructure3õê¼»ˉGPIO*/
                GPIO_Init(ad9851_w_clk_GPIO_PORT, &GPIO_InitStructure);       
       
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;//LED0oíLED1¶Ôó|IO¿ú
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;//ÆÕí¨êä3öÄ£ê½
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//íÆíìêä3ö
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//25MHz
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;//ÏÂà-
  GPIO_Init(GPIOB, &GPIO_InitStructure);//3õê¼»ˉGPIO

  GPIO_ResetBits(GPIOB,GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_5);
        GPIO_ResetBits(GPIOH,GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5);               
}

void ad9851_wr_parrel(unsigned char w0,double frequence)
{
unsigned char w;
long int y;
double x;
//¼ÆËãÆμÂêμÄHEXÖμ
x=4294967295/180;//êêoÏ180M¾§Õñ/180Îa×îÖÕê±ÖóÆμÂ꣨»ò30Máù±¶Æ죩
//èç1ûê±ÖóÆμÂê2»Îa180MHZ£¬DT¸Ä¸Ã′|μÄÆμÂêÖ죬μ¥λMHz £¡£¡£¡
frequence=frequence/1000000;
frequence=frequence*x;
y=frequence;
//D′w0êy¾Y
w=w0;   
GPIO_Write(GPIOB,w|(GPIO_ReadOutputData(GPIOB)&0xff00));        //w0
ad9851_w_clk(ON);
ad9851_w_clk(OFF);
//D′w1êy¾Y
w=(y>>24);
GPIO_Write(GPIOB,w|(GPIO_ReadOutputData(GPIOB)&0xff00));        //w1
ad9851_w_clk(ON);
ad9851_w_clk(OFF);
//D′w2êy¾Y
w=(y>>16);
GPIO_Write(GPIOB,w|(GPIO_ReadOutputData(GPIOB)&0xff00));         //w2
ad9851_w_clk(ON);
ad9851_w_clk(OFF);
//D′w3êy¾Y
w=(y>>8);
data=w|(GPIO_ReadOutputData(GPIOB)&0xff00);
GPIO_Write(GPIOB,w|(GPIO_ReadOutputData(GPIOB)&0xff00));         //w3
ad9851_w_clk(ON);
ad9851_w_clk(OFF);
//D′w4êy¾Y
w=(y>>=0);
GPIO_Write(GPIOB,w|(GPIO_ReadOutputData(GPIOB)&0xff00));        //w4
ad9851_w_clk(ON);
ad9851_w_clk(OFF);
//òÆèëê¼Äü
ad9851_fq_up(ON);
ad9851_fq_up(OFF);
}

void ad9851_reset()
{
  ad9851_w_clk(OFF);
  ad9851_fq_up(OFF);
  //restDÅoÅ
  ad9851_rest(OFF);
  ad9851_rest(ON);
  ad9851_rest(OFF);
}

回复

使用道具 举报

发表于 2019-8-8 22:53:57 | 显示全部楼层
…帮顶
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-4-29 06:54 , Processed in 0.025661 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表