Stm32f103 ADC code rt-thread

Source: Internet
Author: User
#ifndef __ADC_H__#define __ADC_H__#include <rtthread.h>void rt_hw_adc_init(void);#endif
# Include <rtthread. h> # include <stm32f10x. h> void construct (void) {ADC_InitTypeDef ADC_InitStructure; using GPIO_InitStructure; using (encoding, ENABLE); Using (encoding, ENABLE); Using = GPIO_Pin_0; using = callback; GPIO_Init (GPIOC, & GPIO_InitStructure); ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; // standalone mode = DISABLE; // continuous multi-channel mode = ENABLE; // Continuous Conversion Scheme = ADC_ExternalTrigConv_None; // conversion is not determined by the outside world. bytes = ADC_DataAlign_Right; // right-aligned bytes = 1; // Number of scan channels ADC_Init (ADC1, & ADC_InitStructure); ADC_RegularChannelConfig (ADC1, ADC_Channel_10, 1, dependencies); ADC_Cmd (ADC1, ENABLE); // enables or disables the specified ADCADC_ResetCalibration (ADC1); while (ADC_GetResetCalibrationStatus (ADC1); ADC_StartCalibration (ADC1 ); rt_kprintf ("ACD init ..... OK \ n \ r ") ;}# ifdef RT_USING_FINSH # include <finsh. h> void adc (void) {rt_int32_t adc; rt_kprintf ("hello here is a ADC test \ n \ r"); ADC_SoftwareStartConvCmd (ADC1, ENABLE ); // enable or disable the software conversion startup function of the specified ADC while (ADC_GetFlagStatus (ADC1, ADC_FLAG_EOC) = RESET ); // check whether the specified ADC_FLAG_EOC flag position is 1 or not. ADC_GetConversionValue (ADC1); rt_kprintf ("ADC: 0X % xV \ n \ r", adc ); rt_kprintf ("ADC: 0D % dV \ n \ r", adc); rt_kprintf ("ADC: 0X % xV \ n \ r", adc * 3230 ); rt_kprintf ("ADC: 0D % dV \ n \ r", adc * 3230); rt_kprintf ("ADC: 0X % xV \ n \ r", adc * 3230/4095 ); rt_kprintf ("ADC: 0D % dV \ n \ r", adc * 3230/4095); rt_thread_delay (RT_TICK_PER_SECOND/2);} FINSH_FUNCTION_EXPORT (adc, start adc test function .) # endif

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.