当前位置:   article > 正文

STM32对HMC7044进行配置的详细过程及代码_stm32 配置hmc7044配置

stm32 配置hmc7044配置

1.STM32的3线SPI初始化:

  1. void spi_init()
  2. {
  3. GPIO_InitTypeDef GPIO_InitStructure;
  4. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB ,ENABLE);
  5. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_15; //SLEN
  6. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  7. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  8. GPIO_Init(GPIOB, &GPIO_InitStructure);
  9. GPIO_ResetBits(GPIOB, GPIO_Pin_15);
  10. }
  11. void sdata_In_Init()
  12. {
  13. GPIO_InitTypeDef GPIO_InitStructure;
  14. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB ,ENABLE);
  15. /*SPI SDATA PB15*/
  16. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; //SDATA
  17. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  18. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  19. GPIO_Init(GPIOB, &GPIO_InitStructure);
  20. }
  21. void sdata_Out_Init()
  22. {
  23. GPIO_InitTypeDef GPIO_InitStructure;
  24. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB ,ENABLE);
  25. /*SPI SDATA PB15*/
  26. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; //SDATA
  27. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  28. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  29. GPIO_Init(GPIOB, &GPIO_InitStructure);
  30. }

2.STM32对HMC7044的C函数:

 HMC7044数据手册上的读写时序图

  1. void hmc7044_Write(unsigned long int addrData)
  2. {
  3. int i = 0;
  4. sdata_Out_Init();
  5. HMC7044_SPI_SLEN = 1;
  6. HMC7044_SPI_SCLK = 0;
  7. HMC7044_SPI_SDATA = 0;
  8. delay_us(5);
  9. HMC7044_SPI_SLEN = 0;
  10. //trans data
  11. for(i=0;i<24;i++)
  12. {
  13. HMC7044_SPI_SCLK = 0;
  14. data2 = ((addrData>>(23-i)) & 0x1);
  15. HMC7044_SPI_SDATA = data2;
  16. delay_us(5);
  17. HMC7044_SPI_SCLK = 1;
  18. delay_us(5);
  19. }
  20. HMC7044_SPI_SLEN = 1;
  21. }
  22. uint8_t hmc7044_Read(unsigned long int addrData)
  23. {
  24. int i = 0;
  25. uint8_t tempvalue = 0;
  26. sdata_Out_Init();
  27. HMC7044_SPI_SLEN = 1;
  28. HMC7044_SPI_SCLK = 0;
  29. HMC7044_SPI_SDATA = 0;
  30. delay_us(5);
  31. HMC7044_SPI_SLEN = 0;
  32. //trans data
  33. for(i=0;i<16;i++)
  34. {
  35. HMC7044_SPI_SCLK = 0;
  36. data2 = ((addrData>>(15-i)) & 0x1);
  37. HMC7044_SPI_SDATA = data2;
  38. delay_us(5);
  39. HMC7044_SPI_SCLK = 1;
  40. delay_us(5);
  41. }
  42. sdata_In_Init();
  43. for(i=0;i<8;i++)
  44. {
  45. HMC7044_SPI_SCLK = 0;
  46. delay_us(5);
  47. tempvalue<<=1;
  48. HMC7044_SPI_SCLK = 1;
  49. if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_15))
  50. {
  51. tempvalue++;
  52. }
  53. delay_us(5);
  54. }
  55. HMC7044_SPI_SLEN = 1;
  56. return tempvalue;
  57. }

3.HMC7044需要按照芯片手册的顺序进行配置:

  1. 1.更新配置寄存器
  2. 2.配置PLL2寄存器
  3. 3.配置PLL1寄存器
  4. 4.配置SYSREF寄存器
  5. 5.配置输出通道的分频比等
  6. 6.软件重启:0x01寄存器

4.HMC7044的锁定检测:

  1. PLL1锁定检测寄存器:
  2. 0x007C的bit51表示已锁定
  3. PLL2锁定检测寄存器:
  4. 0x007D的bit31表示PLL1和PLL2已锁定

5.HMC7044配置上位机,可生成配置寄存器的数据:https://download.csdn.net/download/qq_41953165/8558160466https://download.csdn.net/download/qq_41953165/85581604

6.STM32F103配置HMC的dPLL2输出2.4G程序

STM32F103配置HMC7044程序-嵌入式文档类资源-CSDN下载icon-default.png?t=M4ADhttps://download.csdn.net/download/qq_41953165/85655161

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/秋刀鱼在做梦/article/detail/752195
推荐阅读
相关标签
  

闽ICP备14008679号