该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

官方的stm32cube软件教程实例ADC操作代码(官方自带的,可以无视),看不懂怎么用的可以等本贴吧更新图片教程,现在就是凑帖子数量,完成转职的,请谅解!

/**

******************************************************************************

* @file ADC/ADC_RegularConversion_Polling/Src/main.c

* @author MCD Application Team

* @version V1.0.1

* @date 26-February-2014

* @brief This example describes how to use Polling mode to convert data.

******************************************************************************

* @attention

*

*

© COPYRIGHT(c) 2014 STMicroelectronics

*

* Redistribution and use in source and binary forms, with or without modification,

* are permitted provided that the following conditions are met:

* 1. Redistributions of source code must retain the above copyright notice,

* this list of conditions and the following disclaimer.

* 2. Redistributions in binary form must reproduce the above copyright notice,

* this list of conditions and the following disclaimer in the documentation

* and/or other materials provided with the distribution.

* 3. Neither the name of STMicroelectronics nor the names of its contributors

* may be used to endorse or promote products derived from this software

* without specific prior written permission.

*

* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"

* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE

* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE

* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE

* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL

* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR

* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER

* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,

* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE

* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*

******************************************************************************

*/

/* Includes ------------------------------------------------------------------*/

#include "main.h"

/** @addtogroup STM32F4xx_HAL_Examples

* @{

*/

/** @addtogroup ADC_RegularConversion_Polling

* @{

*/

/* Private typedef -----------------------------------------------------------*/

/* Private define ------------------------------------------------------------*/

/* Private macro -------------------------------------------------------------*/

/* Private variables ---------------------------------------------------------*/

/* ADC handler declaration */

ADC_HandleTypeDef AdcHandle;

/* Variable used to get converted value */

__IO uint16_t uhADCxConvertedValue = 0;

/* Private function prototypes -----------------------------------------------*/

static void SystemClock_Config(void);

static void Error_Handler(void);

/* Private functions ---------------------------------------------------------*/

/**

* @brief Main program.

* @param None

* @retval None

*/

int main(void)

{

ADC_ChannelConfTypeDef sConfig;

/* STM32F4xx HAL library initialization:

- Configure the Flash prefetch, instruction and Data caches

- Configure the Systick to generate an interrupt each 1 msec

- Set NVIC Group Priority to 4

- Global MSP (MCU Support Package) initialization

*/

HAL_Init();

/* Configure the system clock to 144 Mhz */

SystemClock_Config();

/* Configure LED3 */

BSP_LED_Init(LED3);

/*##-1- Configure the ADC peripheral #######################################*/

AdcHandle.Instance = ADCx;

AdcHandle.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV2;

AdcHandle.Init.Resolution = ADC_RESOLUTION12b;

AdcHandle.Init.ScanConvMode = DISABLE;

AdcHandle.Init.ContinuousConvMode = DISABLE;

AdcHandle.Init.DiscontinuousConvMode = DISABLE;

AdcHandle.Init.NbrOfDiscConversion = 0;

AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;

AdcHandle.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T1_CC1;

AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT;

AdcHandle.Init.NbrOfConversion = 1;

AdcHandle.Init.DMAContinuousRequests = DISABLE;

AdcHandle.Init.EOCSelection = DISABLE;

if(HAL_ADC_Init(&AdcHandle) != HAL_OK)

{

/* Initialization Error */

Error_Handler();

}

/*##-2- Configure ADC regular channel ######################################*/

sConfig.Channel = ADCx_CHANNEL;

sConfig.Rank = 1;

sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;

sConfig.Offset = 0;

if(HAL_ADC_ConfigChannel(&AdcHandle, &sConfig) != HAL_OK)

{

/* Channel Configuration Error */

Error_Handler();

}

/*##-3- Start the conversion process #######################################*/

if(HAL_ADC_Start(&AdcHandle) != HAL_OK)

{

/* Start Conversation Error */

Error_Handler();

}

/*##-4- Wait for the end of conversion #####################################*/

/* Before starting a new conversion, you need to check the current state of

the peripheral; if it抯 busy you need to wait for the end of current

conversion before starting a new one.

For simplicity reasons, this example is just waiting till the end of the

conversion, but application may perform other tasks while conversion

operation is ongoing. */

HAL_ADC_PollForConversion(&AdcHandle, 10);

/* Check if the continous conversion of regular channel is finished */

if(HAL_ADC_GetState(&AdcHandle) == HAL_ADC_STATE_EOC_REG)

{

/*##-5- Get the converted value of regular channel ########################*/

uhADCxConvertedValue = HAL_ADC_GetValue(&AdcHandle);

}

/* Infinite loop */

while(1)

{

}

}

/**

* @brief System Clock Configuration

* The system Clock is configured as follow :

* System Clock source = PLL (HSE)

* SYSCLK(Hz) = 144000000

* HCLK(Hz) = 144000000

* AHB Prescaler = 1

* APB1 Prescaler = 4

* APB2 Prescaler = 2

* HSE Frequency(Hz) = 25000000

* PLL_M = 25

* PLL_N = 288

* PLL_P = 2

* PLL_Q = 6

* VDD(V) = 3.3

* Main regulator output voltage = Scale2 mode

* Flash Latency(WS) = 5

* @param None

* @retval None

*/

static void SystemClock_Config(void)

{

RCC_ClkInitTypeDef RCC_ClkInitStruct;

RCC_OscInitTypeDef RCC_OscInitStruct;

/* Enable Power Control clock */

__PWR_CLK_ENABLE();

/* The voltage scaling allows optimizing the power consumption when the device is

clocked below the maximum system frequency, to update the voltage scaling value

regarding system frequency refer to product datasheet. */

__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);

/* Enable HSE Oscillator and activate PLL with HSE as source */

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;

RCC_OscInitStruct.HSEState = RCC_HSE_ON;

RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;

RCC_OscInitStruct.PLL.PLLM = 25;

RCC_OscInitStruct.PLL.PLLN = 288;

RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;

RCC_OscInitStruct.PLL.PLLQ = 6;

HAL_RCC_OscConfig(&RCC_OscInitStruct);

/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2

clocks dividers */

RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);

RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;

RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;

RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;

HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4);

}

/**

* @brief This function is executed in case of error occurrence.

* @param None

* @retval None

*/

static void Error_Handler(void)

{

/* Turn LED3 on */

BSP_LED_On(LED3);

while(1)

{

}

}

#ifdef USE_FULL_ASSERT

/**

* @brief Reports the name of the source file and the source line number

* where the assert_param error has occurred.

* @param file: pointer to the source file name

* @param line: assert_param error line source number

* @retval None

*/

void assert_failed(uint8_t* file, uint32_t line)

{

/* User can add his own implementation to report the file name and line number,

ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

/* Infinite loop */

while (1)

{

}

}

#endif

/**

* @}

*/

/**

* @}

*/

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

adc 接收cube_官方的stm32cube软件教程实例ADC操作代码(官方自带的,可以无视相关推荐

  1. 工具类软件操作手册_全套广联达软件学习资料合集:教程+实例讲解+操作手册,一文搞定...

    要学习并掌握好算量软件,不仅仅需要软件知识,还需要各种造价相关知识,只有精通软件及造价知识,才能大大的提高算量的速度及准确度. 一个算量的高手掌握的不单是软件操作技术,还要掌握的是造价的基础知识,你要 ...

  2. 修改视频音频图片文件MD5软件教程傻瓜式操作

    先看图如下 这个软件修改批量修改文件的MD5,具有速度快,多文件批量.使用方法也很简单,先设置保存目录后,你只要文件导入软件列表后点击开始修改即可,支持图片,声音,视频等,傻瓜式操作,软件为共享软件, ...

  3. I.MX6ULL 官方 U-Boot 移植系列教程 1 —— 前期准备

    文章目录 前言 一.搭建开发环境 二.获取官方资料 1. 获取官方开发板资料 2. 获取官方 U-Boot 源码 总结 前言 去年入手了一块正点原子的 I.MX6U-ALPHA 开发板,跟着其配套的指 ...

  4. 新塘单片机烧写器_新唐单片机软件加密|新唐单片机软件(NuConsole) v2.04.6725官方版 附安装教程_星星软件园...

    NuConsole是一款实用的新唐单片机软件,该软件可以通过SWD接口操作,为用户提供不中断目标芯片和主机的信息传输机制,是机械和电气领域不可或缺的软件.软件简洁实用.操作简单.极易使用,需要的朋友赶 ...

  5. socket 获取回传信息_Luat系列官方教程5:Socket代码详解

    文章篇幅较长,代码部分建议横屏查看,或在PC端打开本文链接.文末依然为爱学习的你准备了专属福利~ TCP和UDP除了在Lua代码声明时有一些不同,其他地方完全一样,所以下面的代码将以TCP长连接的数据 ...

  6. 委外订单_ERP软件教程:金蝶ERP的委外加工业务流程(一)

    ERP软件教程:金蝶ERP的委外加工业务流程 关注我,我将定期分享更多的ERP解决方案 转发关注并私信我,了解更多的解决方案及操作方法哦 欢迎大家随时咨询关于金蝶ERP的任何问题! 一.应用软件版本: ...

  7. 【STM32】HAL库 STM32CubeMX教程九---ADC

    前言: 本系列教程将 对应外设原理,HAL库与STM32CubeMX结合在一起讲解,使您可以更快速的学会各个模块的使用 所用工具: 1.芯片: STM32F407ZET6/ STM32F103ZET6 ...

  8. 怎样上android官方下载,【图文教程】如何安装 iOS/Android(安卓)触动精灵?

    iOS 注意事项 必须越狱. iOS12 及其以上系统只能安装专业版 arm64 版本客户端并且购买专业版授权,专业版授权和标准版授权不通用. iPhone 7 10 系统设备由于越狱问题无法使用触动 ...

  9. 红米Android降级,红米Note 5(安卓9.0 不要降级刷低版本)纯净ROOT线刷包分享,一键救砖教程,轻松刷回官方系统,流畅如初!...

    红米Note 5(安卓9.0 不要降级刷低版本)纯净ROOT线刷包分享,一键救砖教程,轻松刷回官方系统,流畅如初! 发布日期:2019-05-06   来源:互联网   编辑:lanxi 红米Note ...

最新文章

  1. R语言负二项分布函数Negative Binomial Distribution(dnbinom, pnbinom, qnbinom rnbinom )实战
  2. Silverlight游戏设计(Game Design):(五)面向对象的思想塑造游戏对象
  3. python使用redis队列_Python的Flask框架应用调用Redis队列数据的方法
  4. 手机型号大全资料_电子元器件知识资料大全
  5. 黄聪:如何使用CodeSmith批量生成代码(原创系列教程)
  6. go waitgroup.done()异常处理_Go 异常处理
  7. C# -- RSA加密与解密
  8. CentOS 7 防火墙操作
  9. openoffice转化太慢且不能多线程_职场新人众多工作要处理,手足无措咋办?“多线程工作法”来救急...
  10. Linux RedHat 5.2 mySQL和Apache协同
  11. 现控笔记(三):状态空间表达式的解
  12. FileUpload类中FileUpload1.FileName和FileUpload1.PostedFile.FileName的区别
  13. 麦咖啡服务器怎么进系统,麦咖啡(McAfee)系统托盘图标不见了怎么办?
  14. 阿里云发布智慧书店解决方案 联手新华书店总店落地首个“城市书房”
  15. Excel数据填充技巧
  16. ARM公司发展历程 - 从1985年至今
  17. Windows图像标注软件安装与使用(Vott、labelImg、labelme)
  18. 解决ueditor编辑器图片在线管理图片无法显示
  19. 什么是数据科学?数据科学的基本内容
  20. 使用superset完成mysql数据库或者hive数据库的数据可视化

热门文章

  1. Error:org.gradle.api.internal.tasks.DefaultTaskInputs$TaskInputUnionFileCollection cannot be cast to
  2. 二逼平衡树——树套树(线段树套Splay平衡树)
  3. 计算机名称改变之后,HOUDINI Server 连接不上的解决办法
  4. Delphi 之Copyrect的使用
  5. 原生js自动完成 [转]
  6. opencv——pcb上寻找mark点(拟合椭圆的方法)
  7. 基于 WPF + Modern UI 的 公司OA小助手 开发总结
  8. 从瀑布模型、极限编程到敏捷开发
  9. C++排序算法实现(更新中)
  10. python绘制盖尔圆并做特征值的隔离