I found a lot of examples for reference and got a general understanding of the settings of ADC and DMA. I directly used the development board to do some experiments to verify the related operations and ensure my understanding of the settings of each part.
I used three ADC channels here, one for external variable resistor input, and the other two for internal temperature sampling and Vrefint. This way, continuous sampling can be formed to test multi-channel ADC automatic scanning. ADC is divided into rule conversion and injection conversion. In fact, rule conversion is to convert sequentially according to the established settings, and injection conversion is like cutting in line in this sequential queue, and can convert in advance.
Initialization settings:
1 //PC0 FOR ANAGLE SAMPLE 2 static void Protect_ClkInit(void) 3 { 4 RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1RCC_APB2Periph_GPIOC,ENABLE); 5 RCC_ADCCLKConfig(RCC_PCLK2_Div6); 6 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); 7 } 8 9 static void Protect_GPIOInit(void) 10 { 11 GPIO_InitTypeDef GPIO_InitStructure; 12 13 /*GPIO PhaseA_H initialization*/ 14 GPIO_InitStructure.GPIO_Pin = ADC_PIN; 15 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; 16 GPIO_Init(TIMER_GPIO_AH_PORT, &GPIO_InitStructure); 17 } 18 19 static void Protect_AdcInit(void) 20 { 21 ADC_InitTypeDef ADC_InitStructure; twenty two 23 ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; 24 ADC_InitStructure.ADC_ScanConvMode = ENABLE; 25 ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; 26 ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; 27 ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; 28 ADC_InitStructure.ADC_NbrOfChannel = 3; 29 ADC_Init(ADC1, &ADC_InitStructure); 30 31 ADC_TempSensorVrefintCmd(ENABLE); 32 ADC_RegularChannelConfig(ADC1,ADC_Channel_10,1,ADC_SampleTime_7Cycles5); 33 ADC_RegularChannelConfig(ADC1,ADC_Channel_TempSensor,2,ADC_SampleTime_7Cycles5); 34 ADC_RegularChannelConfig(ADC1,ADC_Channel_Vrefint,3,ADC_SampleTime_7Cycles5); 35 36 ADC_DMACmd(ADC1, ENABLE); 37 /* Enable ADC1 external trigger */ 38 ADC_ExternalTrigConvCmd(ADC1, DISABLE); 39 40 ADC_Cmd(ADC1, ENABLE); 41 42 ADC_ResetCalibration(ADC1); 43 44 while(ADC_GetResetCalibrationStatus(ADC1)); 45 46 ADC_StartCalibration(ADC1); 47 48 while(ADC_GetCalibrationStatus(ADC1)); 49 50 } 51 52 static void Protect_DMAInit(void) 53 { 54 55 DMA_InitTypeDef DMA_InitStructure; 56 57 /* DMA1 channel1 configuration -*/ 58 DMA_DeInit(DMA1_Channel1); 59 DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t) & (ADC1->DR); 60 DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&ADCConvertedValue; 61 DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; 62 DMA_InitStructure.DMA_BufferSize = 3; 63 DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; 64 DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; 65 DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; 66 DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; 67 DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; 68 DMA_InitStructure.DMA_Priority = DMA_Priority_High; 69 DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; 70 DMA_Init(DMA1_Channel1, &DMA_InitStructure); 71 72 /* Enable DMA1 channel1 */ 73 DMA_Cmd(DMA1_Channel1, ENABLE); 74 }
After setting up and testing, I found a serious problem. When I adjusted the variable resistor, I found that it would affect the data of the other two sampling channels, and the data changed greatly. I first tested the reference voltage of ADC, namely Vref+ and Vref-, and found no change. Is there a problem with the initialization of sampling? I found a lot of information on the Internet, but none of them showed that there was a problem with my settings. However, I still found a difference, that is, the time of ADC_sampling_time was different. So I set it to:
1 ADC_RegularChannelConfig(ADC1,ADC_Channel_10,1,ADC_SampleTime_239Cycles5); 2 ADC_RegularChannelConfig(ADC1,ADC_Channel_TempSensor,2,ADC_SampleTime_239Cycles5); 3 ADC_RegularChannelConfig(ADC1,ADC_Channel_Vrefint,3,ADC_SampleTime_239Cycles5);
That is the maximum sampling time. It turned out that this was indeed the problem. Later, I tried several other sampling times, and the shortest one had to be ADC_SampleTime_71Cycles5, otherwise the data would be affected. I guess the sampling period cannot be too short, otherwise DMA data transmission may be affected.
Previous article:STM32 UART DMA implements unknown data length reception
Next article:AT91SAM3S serial port UART initialization and data transmission and reception
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Molex leverages SAP solutions to drive smart supply chain collaboration
- Pickering Launches New Future-Proof PXIe Single-Slot Controller for High-Performance Test and Measurement Applications
- Apple faces class action lawsuit from 40 million UK iCloud users, faces $27.6 billion in claims
- Apple faces class action lawsuit from 40 million UK iCloud users, faces $27.6 billion in claims
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
- ASML predicts that its revenue in 2030 will exceed 457 billion yuan! Gross profit margin 56-60%
- Detailed explanation of intelligent car body perception system
- How does ADR1399 perform?
- [NUCLEO-F746ZG Learning] Construction Project-Based on RT-Thread
- I need help from a master who can use ADS software to make filters
- Beijing Excellence Communication is recruiting embedded developers with high salary!!!
- How to assign initial values to a continuous RAM range in C2000 chip
- What is 4G DTU and what are its specific functions?
- CadenceLIVE China 2022 China Online User Conference invites you to attend
- Super detailed summary of receiver sensitivity and equivalent noise bandwidth
- The problem of grounding the output signal of the half-bridge inverter circuit
- Xianyu not only hired someone to do their graduation project, but also tried to "extort" money from the seller. It's a pity for these two students from Xidian University...