STM32 ADC synchronization rule mode (two-channel)

Source: Internet
Author: User

STM32 ADC synchronization rule mode (two-channel)

It feels better to directly paste the code ......

  

1 # include "adc. h "2 3 float AD1_Value [N]; 4 float AD2_Value [N]; 5 volatile u32 ADCConvertedValue [N]; // AD × ue» ° ³ Ç çø, Õ Ó RAM 0.8KB 6 7 8 void Adc_Init (void) 9 {10 TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; 11 ADC_InitTypeDef ADC_InitStructure; 12 GPIO_InitTypeDef GPIO_InitStructure; 13 DMA_InitTypeDef DMA_InitStructure; 14 NVIC_InitTypeDef NVIC_InitStructure; 15 // Enable Clock/ //////////////////////////////////////// //////////////////// 16 RCC_ADCCLKConfig (RCC_PCLK2_Div6 ); // 72 M/6 = 12, ADC the Max Time Is Lager Than 14 M 17 RCC_AHBPeriphClockCmd (temperature, ENABLE); 18 RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOA | temperature, ENABLE ); // Ê ¹ äüadc1 ísampled ± öó 19 RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOA | RCC_APB2Periph_ADC2, ENABLE ); // Ê ¹ äadc2 ísampled ±öó 20 // RCC_ADCCLKConfig (RCC_PCLK2_Div6); // 72 M/6 = 12, ADC the Max Time Is Lager Than 14 M 21 22 // PA0.PA1. PA4.PA5 × ~~~ä£äâ ísampled sampled ~~~~~~%23 then = GPIO_Pin_2 | GPIO_Pin_1; 24 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; // ä£äâ ********%25 GPIO_Init (GPIOA, & GPIO_InitStructure ); 26 27 ////////////////////////////////////// // Initialize DMA //////////////////////////////////// //// // 28 DMA_DeInit (DMA1_Channel1 ); // Reset DMA_Channel_1's Register To Default Value 29 Register = (u32) & ADC1-> DR; // DMA Device to ADC's Base Address 30 DMA_InitStructure.DMA_MemoryBaseAddr = (u32) & ADCConvertedValue; // DMA Memory Base Address 31 // region = (u32) & ADCConvertedValue; // DMA Memory Base Address 32 DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; // Memory be use to Data Chansminsion's Destination 33 DMA_InitStructure.DMA_BufferSize = N; // DMA Channel's DMA Buffer Size 34 bytes = DMA_PeripheralInc_Disable; // Outside Address's Register Is not Change 35 DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; // Buffer Address's Register Is Increasing 36 bytes = DMA_PeripheralDataSize_Word; // Data size is 16 Bit 37 bytes = DMA_MemoryDataSize_Word; // Data Size Is 16 Bit 38 bytes = DMA_Mode_Circular; // Work in Cycle Cache Mode 39 40 bytes = DMA_Priority_High; // DMA Channel X Have The Higest Priority 41 member = DMA_M2M_Disable; // DMA Channel X do not set up to Chansmission in Memory to Memory 42 DMA_Init (DMA1_Channel1, & DMA_InitStructure ); // According to DMA_InitStruct to Initialize the DMA Channel 43 DMA_Cmd (DMA1_Channel1, ENABLE ); // Ê ¹ äüdma1írμ À 1 44 45 46 ///////////////////////// //// // Initialize C /////////////////////// //////////////////////////////////////// ///// 47 NVIC_PriorityGroupConfig (NVIC_PriorityGroup_1 ); 48 channels = DMA1_Channel1_IRQn; 49 channels = 1; 50 channels = 1; 51 channels = ENABLE; 52 NVIC_Init (& NVIC_InitStructure); 53 DMA_ITConfig (DMA1_Channel1, DMA_IT_TC, ENABLE ); // Ê ¹ äüdma Ö öð Ï 64 /////////////////////////// /// // Initialize ADC ///////////////////////// //////////////////////////////////////// /// 65 66 ADC_DeInit (ADC1 ); // comment 'response» ADC1, ~« íâ éè ADC1 µäè «² ¿Ä ä'æ æ Ö ööéè Î è ± Ê ¡Ö öμ 67 ADC_DeInit (ADC2 ); // comment 'response» ADC1, when «íâ éè ADC1 µäè «² ¿Ä ä' then æ Ö öø éè è È ± Ê Ö öµ68 69 ADC_InitStructure.ADC_Mode = ADC_Mode_RegSimult; // adc¹ ¤ ×ä ä£;;:adc1 ° íadc2 ¹ ¤ ×÷ ú¶ ááä ä£;%%70 ADC_InitStructure.ADC_ScanConvMode = ENABLE; // ADC Works in Scan Model 71 placement = ENABLE; // ADC works in Continious Changing Model 72 placement = ADC_ExternalTrigConv_None; // ADC is triggered by sofeware instead of Outside 73 placement = ADC_DataAlign_Right; // ADC Data Right Align 74 ADC_InitStructure.ADC_NbrOfChannel = 1; // please refer to zookeeper without prior written consent. Please refer to zookeeper × unauthorized» maid ADC_Init (ADC1, & ADC_InitStructure ); // please refer to your ADC _ InitStruct öö ö~~%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 76 ADC_RegularChannelConfig (ADC1, ADC_Channel_1, 1, ADC_SampleTime_1Cycles5); 77 ADC_DMACmd (ADC1, ENABLE); // Ê Ä äadc1 DMA
84 ADC_InitStructure.ADC_Mode = ADC_Mode_RegSimult; // ADC bandwidth limit × ~ä£;;:adc2 bandwidth limit × ~~úantááä£;%85 ADC_InitStructure.ADC_ScanConvMode = ENABLE; // ADC Works in Scan Model 86 placement = ENABLE; // ADC works in Continious Changing Model 87 placement = ADC_ExternalTrigConv_None; // ADC is triggered by sofeware instead of Outside 88 ADC_InitStructure.ADC_D AtaAlign = ADC_DataAlign_Right; // ADC Data Right Align 89 ADC_InitStructure.ADC_NbrOfChannel = 1; // zookeeper × quorum» µäadädírāµäê ää 90 ADC_RegularChannelConfig (ADC2, ADC_Channel_2, 1, ADC_SampleTime_1Cycles5); 91 ADC_Init (ADC2, & ADC_InitStructure ); // please refer to your ADC _ InitStruct öö ö~~%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 92 ADC_ExternalTrigConvCmd (ADC2, ENABLE); 93 94 95 ADC_DMACmd (ADC1, ENABLE); 96 ADC_Cmd (ADC1, E NABLE); // Ê Ä äüö¸ ¨ μ äadc1 98 99 ADC_ResetCalibration (ADC1 ); // when Ä äüll' then» then £ * else 100 while (ADC_GetResetCalibrationStatus (ADC1 )); // microè '{}' then» £ × ***ámø 101 ADC_StartCalibration (ADC1 ); // please wait until there is AD before X 102 while (ADC_GetCalibrationStatus (ADC1); // µè then x ~~á~ø 103 104 ADC_Cmd (ADC2, ENABLE); 105 ADC_ResetCalibration (ADC2); // Ê Ä äü ¸ 'deliiter» %£× %106 while (ADC_GetResetCalibrationStatus (ADC2 )); // microè '{}' then» £m. × **á Ê ø 107 ADC_StartCal Ibration (ADC2); // please wait until there is AD before X when 108 while (ADC_GetCalibrationStatus (ADC2 )); // maid 109 110 // delay_ms (10); 111 ADC_SoftwareStartConvCmd (ADC1, ENABLE ); // Ê Ä äüö¸ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% () 116 {117 2010i; 118 2010temp1, temp2; 119 DMA_ClearFlag (DMA1_FLAG_TC1); // clear DMA transmission completion interrupt 120 DMA_Cmd (DMA1_Channel1, DISABLE); 121 for (I = 0; I <N; I ++) 122 {123 temp1 = (ADCConvertedValue [I] <16)> 16; 124 temp2 = ADCConvertedValue [I]> 16; 125 AD1_Value [I] = (float) temp1) * (3.3/4096); 126 AD2_Value [I] = (float) temp2) * (3.3/4096); 127 Get_tem_buf (I); 128} 129 DMA_Cmd (DMA1_Channel1, ENABLE); 131 LED0 = ~ LED0; 132}

Some annotations are not supported if they are directly attached to Keil5 ....... So embarrassing .... Next time, the code comments will still be calculated in full English ,,,

Haha .. Any questions can be discussed together, and I don't know why the Classification CANNOT be embedded, so I have to click Linux ..

Related Article

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.