找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 774|回复: 0
收起左侧

STM32单片机控制ADF4351整套资料 源程序原理图等

[复制链接]
ID:722006 发表于 2025-1-1 22:03 | 显示全部楼层 |阅读模式
如题

  1. #include "ADF4351.h"

  2. #define SET_LE()                GPIO_SetBits(GPIOC, GPIO_Pin_8)        //LE
  3. #define CLR_LE()                GPIO_ResetBits(GPIOC, GPIO_Pin_8)

  4. #define        SET_SCL()                GPIO_SetBits(GPIOA, GPIO_Pin_5)        //CLK
  5. #define        CLR_SCL()                GPIO_ResetBits(GPIOA, GPIO_Pin_5)

  6. #define SET_DATA()                GPIO_SetBits(GPIOA, GPIO_Pin_7)        //DAT
  7. #define CLR_DATA()                GPIO_ResetBits(GPIOA, GPIO_Pin_7)

  8. #define SET_CE()                GPIO_SetBits(GPIOC, GPIO_Pin_13)        //CE
  9. #define CLR_CE()                GPIO_ResetBits(GPIOC, GPIO_Pin_13)
  10.         
  11. u8 buf[4];


  12. //写入32个字节
  13. void ADF4351_Write(u32 adf_dat)
  14. {
  15.         u8 i;

  16.         CLR_LE();
  17.         for (i = 0; i < 32; i++)
  18.         {
  19.                 if ((adf_dat & 0x80000000) == 0x80000000)
  20.                         SET_DATA();
  21.                 else
  22.                         CLR_DATA();
  23.                 CLR_SCL();
  24.                 SET_SCL();
  25.                 CLR_SCL();
  26.                 adf_dat <<= 1;
  27.         }
  28.         SET_LE();
  29.         delay(1);
  30.         CLR_LE();
  31. }

  32. void delay (int length)
  33. {
  34.         int i;
  35.         i = length * 200 ;
  36.         while (i >0)
  37.         i--;
  38. }

  39. void ADF4351_Initiate(void)
  40. {
  41.                 GPIO_InitTypeDef  GPIO_InitStructure;
  42.                
  43.                 RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOA |RCC_APB2Periph_GPIOD, ENABLE); ;
  44.                
  45.                 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_13;
  46.                 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;   
  47.                 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;                 
  48.                 GPIO_Init(GPIOC, &GPIO_InitStructure);   
  49.         
  50.         
  51.                 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_7;
  52.                 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  53.                 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  54.                 GPIO_Init(GPIOA, &GPIO_InitStructure);

  55.                 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
  56.                 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  57.                 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  58.                 GPIO_Init(GPIOD, &GPIO_InitStructure);
  59.         
  60.                 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
  61.                 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  62.                 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  63.                 GPIO_Init(GPIOC, &GPIO_InitStructure);
  64.         
  65.                 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
  66.                 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  67.                 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  68.                 GPIO_Init(GPIOA, &GPIO_InitStructure);
  69.         
  70.         
  71.                 GPIO_ResetBits(GPIOC, GPIO_Pin_9);        //PDRF恒为0
  72.                 SET_CE();


  73. }




  74. //---------------------------------
  75. //void WriteToADF4350(unsigned char count,unsigned char *buf);
  76. //---------------------------------
  77. //Function that writes to the ADF4350 via the SPI port.
  78. //--------------------------------------------------------------------------------


  79. void WriteToADF4350(unsigned char count, unsigned char *buf)
  80. {
  81.         unsigned        char        ValueToWrite = 0;
  82.     unsigned        char        i = 0;
  83.         unsigned        char        j = 0;
  84.         
  85.         
  86.         delay(1);
  87.         CLR_SCL();
  88.         CLR_LE();
  89.         delay(1);

  90.         for(i=count;i>0;i--)
  91.          {
  92.                  ValueToWrite = *(buf + i - 1);
  93.                 for(j=0; j<8; j++)
  94.                 {
  95.                         if(0x80 == (ValueToWrite & 0x80))
  96.                         {
  97.                                 SET_DATA();          //Send one to SDO pin
  98.                         }
  99.                         else
  100.                         {
  101.                                 CLR_DATA();          //Send zero to SDO pin
  102.                         }
  103.                         delay(1);
  104.                         SET_SCL();
  105.                         delay(1);
  106.                         ValueToWrite <<= 1;        //Rotate data
  107.                         CLR_SCL();
  108.                 }
  109.         }
  110.         CLR_DATA();
  111.         delay(1);
  112.         SET_LE();
  113.         delay(1);
  114.         CLR_LE();
  115. }


  116. //---------------------------------
  117. //void ReadFromADF4350(unsigned char count,unsigned char *buf)
  118. //---------------------------------
  119. //Function that reads from the ADF4350 via the SPI port.
  120. //--------------------------------------------------------------------------------
  121. void ReadFromADF4350(unsigned char count, unsigned char *buf)
  122. {
  123.         unsigned        char        i = 0;
  124.         unsigned        char        j = 0;
  125.         unsigned        int          iTemp = 0;
  126.         unsigned        char          RotateData = 0;


  127.         
  128.         delay(1);
  129.         CLR_SCL();
  130.         CLR_LE();
  131.         delay(1);

  132.         for(j=count; j>0; j--)
  133.         {
  134.                 for(i=0; i<8; i++)
  135.                 {
  136.                         RotateData <<= 1;                //Rotate data
  137.                         delay(1);
  138. //                        iTemp = GP4DAT;                        //Read DATA of ADF4350
  139.                         SET_SCL();        
  140.                         if(0x00000020 == (iTemp & 0x00000020))
  141.                         {
  142.                                 RotateData |= 1;        
  143.                         }
  144.                         delay(1);
  145.                         CLR_SCL();
  146.                 }
  147.                 *(buf + j - 1)= RotateData;
  148.         }         
  149.         delay(1);
  150.         SET_LE();
  151.         delay(1);
  152.         CLR_LE();
  153. }



  154. void Frequency_25MHz(void)
  155. {                      //4G输出配置
  156.         buf[3] = 0x00;
  157.         buf[2] = 0x58;
  158.         buf[1] = 0x00;                                //write communication register 0x00580005 to control the progress
  159.          buf[0] = 0x05;                                //to write Register 5 to set digital lock detector
  160.         WriteToADF4350(4,buf);               

  161.         buf[3] = 0x00;
  162.         buf[2] = 0x0F;        //EC                        //(DB23=1)The signal is taken from the VCO directly;(DB22-20:6H)the RF divider is 64;(DB19-12:50H)R is 80
  163.         buf[1] = 0xA0;                                //(DB11=0)VCO powerd up;
  164.          buf[0] = 0x24;                                //(DB5=1)RF output is enabled;(DB4-3=3H)Output power level is 5
  165.         WriteToADF4350(4,buf);               

  166.         buf[3] = 0x00;
  167.         buf[2] = 0x00;
  168.         buf[1] = 0x04;                                //(DB14-3:96H)clock divider value is 150.
  169.          buf[0] = 0xB3;
  170.         WriteToADF4350(4,buf);        

  171.         buf[3] = 0x01;
  172.         buf[2] = 0x00;                                //(DB6=1)set PD polarity is positive;(DB7=1)LDP is 6nS;
  173.         buf[1] = 0x8E;                                //(DB8=0)enable fractional-N digital lock detect;
  174.          buf[0] = 0x42;                                //(DB12-9:7H)set Icp 2.50 mA;
  175.         WriteToADF4350(4,buf);                //(DB23-14:1H)R counter is 1

  176.         buf[3] = 0x08;
  177.         buf[2] = 0x00;
  178.         buf[1] = 0x80;                           //(DB14-3:6H)MOD counter is 6;
  179.          buf[0] = 0x11;                           //(DB26-15:6H)PHASE word is 1,neither the phase resync
  180.         WriteToADF4350(4,buf);           //nor the spurious optimization functions are being used
  181.                                                            //(DB27=1)prescaler value is 8/9

  182.         buf[3] = 0x00;
  183.         buf[2] = 0x28;
  184.         buf[1] = 0x00;
  185.          buf[0] = 0x00;                                //(DB14-3:0H)FRAC value is 0;
  186.         WriteToADF4350(4,buf);                //(DB30-15:140H)INT value is 320;


  187. ////25MHz
  188. //        buf[3] = 0x00;
  189. //        buf[2] = 0x58;
  190. //        buf[1] = 0x00;
  191. //         buf[0] = 0x05;                                
  192. //        WriteToADF4350(4,buf);               

  193. //        buf[3] = 0x00;
  194. //        buf[2] = 0x8C;
  195. //        buf[1] = 0x80;
  196. //         buf[0] = 0x3C;                                
  197. //        WriteToADF4350(4,buf);               

  198. //        buf[3] = 0x00;
  199. //        buf[2] = 0x00;
  200. //        buf[1] = 0x04;
  201. //         buf[0] = 0xB3;                                
  202. //        WriteToADF4350(4,buf);               

  203. //        buf[3] = 0x00;
  204. //        buf[2] = 0x00;
  205. //        buf[1] = 0x4E;
  206. //         buf[0] = 0x42;                                
  207. //        WriteToADF4350(4,buf);               

  208. //        buf[3] = 0x08;
  209. //        buf[2] = 0x00;
  210. //        buf[1] = 0x80;
  211. //         buf[0] = 0x11;                                
  212. //        WriteToADF4350(4,buf);               

  213. //        buf[3] = 0x00;
  214. //        buf[2] = 0x50;
  215. //        buf[1] = 0x00;
  216. //         buf[0] = 0x00;                                
  217. //        WriteToADF4350(4,buf);               

  218. }



  219.         /*-------------------------------------200MHz---------------------------------------------
  220.         Reference frequency: 20MHz;Output frequency: 200MHz;VCO frequency: 3200MHz;Prescaler: 8/9;
  221.         RF divider: 16;VCO channel spacing frequency: 200KHz;PFD frequency: 10MHz;
  222.         INT: 320;FRAC: 0;MOD: 100;R: 1;Lock Clk Div: 6; bank clk div: 200; Phase: 1  
  223.         ----------------------------------------------------------------------------------------*/
  224.         /*RFout = [INT + (FRAC/MOD)] * (Fpfd/RF Divider)*/
  225.         /*Fpfd = REFIN * [(1 + D)/(R * (1 + T))]*/
  226.         /*Fvco = RF divider * Output frequency   2.2G-4.4G*/

  227. void ADF_SetFre(void){

  228.         u32 adf_data;
  229.         u16 adf_R=1;                //RF参考分频系数
  230.   u8 adf_D=0;                //RF REFin倍频器位(0 or 1)
  231.   u8 adf_T=0;                //参考二分频位,产生占空比50%,减少周跳
  232.   u16 adf_Locktime=160;
  233.   u16 adf_MOD=1;
  234.   u16 adf_INT=256;
  235.   u16 adf_FARC=0;
  236.   u16 adf_PHASE=1;
  237. //  u8 pinduan;
  238.         

  239.         CLR_SCL();
  240.         CLR_LE();
  241.         
  242.         
  243.         //配置寄存器5
  244.         adf_data = 0x00580000;        //数字锁存   LD引脚的工作方式为数字锁存   D23 D22=01
  245.         adf_data =adf_data | ADF_R5;        
  246.         ADF4351_Write(adf_data);
  247.         
  248.         
  249.         //配置寄存器4
  250.         adf_data = 0x00800038;
  251.         /*(DB23=1)The signal is taken from the VCO directly,信号直接从VCO获得
  252.         可修改RF divider, R的值(DB22-20)the RF divider is 16;
  253.         (DB11=0)VCO powerd up;        辅助RF输出禁用; 频段选择时钟,分频至125k, 分频值160*/
  254.         adf_data = adf_data | (RF_div32 << 20);                //RF divider is 16
  255.         adf_data = adf_data | (160 << 12);                //频段选择时钟
  256.         adf_data = adf_data | ADF_R4;        //(DB5=1)RF output is enabled;(DB4-3=3H)Output power level is 5dBm
  257.         ADF4351_Write(adf_data);
  258.         
  259.         
  260.         //配置寄存器3
  261.         adf_data = 0x00848000;        
  262.         /*选择高频段(D23=1), APB6ns(D22=0,=建议小数分频使用),,(D21=0,小数分频使用) 使能CSR(D18=1),(D16 D15=01)快速锁定
  263.         可修改clock divider value的值*/
  264.         adf_data = adf_data | (adf_Locktime << 3);
  265.         adf_data = adf_data | ADF_R3;        
  266.         ADF4351_Write(adf_data);
  267.         
  268.         //配置寄存器2
  269.         adf_data = 0x61002040;
  270.         //低杂散输出, 禁用参考倍频, 二分频触发器使能(减少周跳必须)
  271.         //使能双缓冲器, 设置电荷磅电流0.31, 小数N分频(40), 设置R分频器的值为1
  272.         //设置鉴相器的极性, (DB6)同向滤波器1,反向滤波器0,这里用同向滤波器
  273.         adf_data = adf_data | (adf_D << 25);
  274.         adf_data = adf_data | (adf_T << 24);
  275.         adf_data = adf_data | (adf_R << 14);        
  276.         adf_data = adf_data | ADF_R2;        
  277.         ADF4351_Write(adf_data);
  278.         
  279.         //配置寄存器1
  280.         adf_data = 0x01008000;
  281.         //禁用相位调整,预分频器的值为8/9
  282.   //相位字为1
  283.         adf_data = adf_data | (adf_PHASE << 15);
  284.         adf_data = adf_data | (adf_MOD << 3);
  285.         adf_data = adf_data | ADF_R1;        
  286.         ADF4351_Write(adf_data);
  287.         
  288.         //配置寄存器0
  289.         adf_data = 0x00000000;
  290.         adf_data = adf_data | (adf_INT << 15);
  291.         adf_data = adf_data | (adf_FARC << 3);
  292.         adf_data= adf_data | ADF_R0;        
  293.         ADF4351_Write(adf_data);
  294.         
  295.         
  296.         
  297.         
  298.         
  299.         
  300. }
复制代码


0_Datasheet.rar

1.37 MB, 下载次数: 0, 下载积分: 黑币 -5

1_原理图.rar

632.17 KB, 下载次数: 0, 下载积分: 黑币 -5

3_STM32测试源程序.7z

186.47 KB, 下载次数: 0, 下载积分: 黑币 -5

ADF435X模块使用说明和测试记录.rar

997.56 KB, 下载次数: 0, 下载积分: 黑币 -5

评分

参与人数 1黑币 +50 收起 理由
admin + 50

查看全部评分

回复

使用道具 举报

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

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

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