[国产单片机] 【东软载波ES32F369x+ADC采样】

[复制链接]
 楼主| freeelectron 发表于 2021-2-8 22:03 | 显示全部楼层 |阅读模式
1、引脚使用PA5,也就是ADC的通道9




2、引脚复用功能
复用功能是功能0,因此在软件配置的时候需要配置为复用功能0


3、ADC初始化
硬件设计上,使用VDD作为参考,因此软件配置的时候也要配置为使用VDD。
  1. void adc_init(void)
  2. {
  3.         md_gpio_init_t x;

  4.         x.mode  = MD_GPIO_MODE_INPUT;
  5.         x.pupd  = MD_GPIO_PUSH_UP;
  6.         x.odos  = MD_GPIO_PUSH_PULL;
  7.         x.podrv = MD_GPIO_OUT_DRIVE_1;
  8.         x.nodrv = MD_GPIO_OUT_DRIVE_1;
  9.         x.flt   = MD_GPIO_FILTER_DISABLE;
  10.         x.type  = MD_GPIO_TYPE_CMOS;
  11.         x.func  = MD_GPIO_FUNC_0;
  12.         md_gpio_init(GPIOA, MD_GPIO_PIN_5, &x);
  13.        
  14.         md_adc_init_t h_adc;
  15.   md_adc_nch_conf_t config;
  16.        
  17.   md_adc_struct_init(&h_adc);
  18.         md_adc_normal_struct_init(&config);
  19.         md_adc_init(ADC0, &h_adc);
  20.         md_adc_normal_channel_config(ADC0, &config);
  21. }

4、获取ADC
  1. uint32_t get_adc_value(void)
  2. {
  3.         uint32_t value=0;
  4.                 /* Start normal convert */
  5.         md_adc_set_normal_channel_conv_start_nchtrg(ADC0);
  6.         /* Wait convert finish */
  7.         while (md_adc_get_stat_nche(ADC0) == 0);
  8.         /* Clear complete flag */
  9.         md_adc_set_clr_nche(ADC0);
  10.         /* Read normal convert result */
  11.         value = md_adc_get_normal_channel_val(ADC0);
  12.        
  13.         return value;
  14. }
5、现象
通过调节R8的阻值,可以看到ADC采样值的变化


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

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

本版积分规则

个人签名:stm32/LoRa物联网:304350312

65

主题

785

帖子

11

粉丝
快速回复 在线客服 返回列表 返回顶部
个人签名:stm32/LoRa物联网:304350312

65

主题

785

帖子

11

粉丝
快速回复 在线客服 返回列表 返回顶部