当前位置:网站首页>Smart micro mm32 multi-channel adc-dma configuration
Smart micro mm32 multi-channel adc-dma configuration
2022-07-01 22:25:00 【Cocoa core Italy】
One 、 problem
Recently, I have been using smart MM32, When using multiplex ADC-DMA when , There are some problems , So record it here
Sum up , The following problems have been solved ( The problem here is to get the latest SDK package , Reference resources example There's no way to solve it )
- Corresponding to multiple channels DMA Memory is ambiguous , for example CH0 Corresponding DMA The second byte of ,CH1 But it corresponds to the first byte
- The values of multiple channels are close
Two 、 resolvent
Use any channel
ADC_ANY_NUM_Config(ADC1,3);// altogether 4 passageway ADC1->ANYCR |= ADC_ANY_CR_CHANY_MDEN;// Open any channel /// Set the order of channels ADC_ANY_CH_Config(ADC1,0,ADC_Channel_0); ADC_ANY_CH_Config(ADC1,1,ADC_Channel_1); ADC_ANY_CH_Config(ADC1,2,ADC_Channel_2); ADC_ANY_CH_Config(ADC1,3,ADC_Channel_Vrefint);This problem , Because the pin is suspended , for instance , if PA1 There is an exact level , PA2 PA3
In the air , be PA2 PA3 The obtained data will follow PA1 change , It's just a little different ( Nuances )
3、 ... and 、 The overall code
void adc_dma_init()
{
DMA_InitTypeDef DMA_InitStruct;
RCC_AHBPeriphClockCmd(RCC_AHBENR_DMA1, ENABLE);
DMA_DeInit(DMA1_Channel1);
DMA_StructInit(&DMA_InitStruct);
//DMA transfer peripheral address
DMA_InitStruct.DMA_PeripheralBaseAddr = (u32) & (ADC1->DR);
//DMA transfer memory address
DMA_InitStruct.DMA_MemoryBaseAddr = (u32)&adcBuf;
//DMA transfer direction from peripheral to memory
DMA_InitStruct.DMA_DIR = DMA_DIR_PeripheralSRC;
//DMA cache size
DMA_InitStruct.DMA_BufferSize = ADC_DMA_BUF_SIZE;
//After receiving the data, the peripheral address is forbidden to move
//backward
DMA_InitStruct.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
//After receiving the data, the memory address is shifted backward
DMA_InitStruct.DMA_MemoryInc = DMA_MemoryInc_Enable;
//Define the peripheral data width to 16 bits
DMA_InitStruct.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
//Define the memory data width to 16 bits
DMA_InitStruct.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
//Cycle conversion mode
DMA_InitStruct.DMA_Mode = DMA_Mode_Circular;
//DMA priority is high
DMA_InitStruct.DMA_Priority = DMA_Priority_High;
//M2M mode is disabled
DMA_InitStruct.DMA_M2M = DMA_M2M_Disable;
DMA_InitStruct.DMA_Auto_reload = DMA_Auto_Reload_Disable;
DMA_Init(DMA1_Channel1, &DMA_InitStruct);
DMA_Cmd(DMA1_Channel1, ENABLE);
ADC_InitTypeDef ADC_InitStruct;
ADC_StructInit(&ADC_InitStruct);
//Initialize PA1 to analog input mode
//Enable ADC clock
RCC_APB2PeriphClockCmd(RCC_APB2ENR_ADC1, ENABLE);
ADC_InitStruct.ADC_Resolution = ADC_Resolution_12b;
//ADC prescale factor
ADC_InitStruct.ADC_PRESCARE = ADC_PCLK2_PRESCARE_17;
//Set ADC mode to continuous conversion mode
ADC_InitStruct.ADC_Mode = ADC_Mode_Continue;
//AD data right-justified
ADC_InitStruct.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStruct.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1;
ADC_Init(ADC1, &ADC_InitStruct);
GPIO_InitTypeDef GPIO_InitStruct;
RCC_AHBPeriphClockCmd(RCC_AHBENR_GPIOA, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBENR_GPIOC, ENABLE);
GPIO_StructInit(&GPIO_InitStruct);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOA, &GPIO_InitStruct);
//PC3 ADC_IN13
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_3;
GPIO_Init(GPIOC, &GPIO_InitStruct);
//Enable the channel
ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 0, ADC_Samctl_240_5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 0, ADC_Samctl_240_5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 0, ADC_Samctl_240_5);
// ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 0, ADC_Samctl_240_5);
// ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 0, ADC_Samctl_240_5);
//ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 0, ADC_Samctl_240_5);
//ADC_RegularChannelConfig(ADC1, ADC_Channel_6, 0, ADC_Samctl_240_5);
// ADC_RegularChannelConfig(ADC1, 13, 0, ADC_Samctl_240_5);// passageway 13
ADC_RegularChannelConfig(ADC1, ADC_Channel_Vrefint, 0, ADC_Samctl_240_5);
ADC_ANY_CH_Config(ADC1,0,ADC_Channel_0);
ADC_ANY_CH_Config(ADC1,1,ADC_Channel_1);
ADC_ANY_CH_Config(ADC1,2,ADC_Channel_2);
ADC_ANY_CH_Config(ADC1,3,ADC_Channel_Vrefint);
ADC_ANY_NUM_Config(ADC1,3);//
ADC1->ANYCR |= ADC_ANY_CR_CHANY_MDEN;// Open any channel
ADC_TempSensorVrefintCmd(ENABLE);
//Enable ADCDMA
ADC_DMACmd(ADC1, ENABLE);
//Enable AD conversion
ADC_Cmd(ADC1, ENABLE);
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
}
边栏推荐
- Pytest collection (2) - pytest operation mode
- 手动实现function isInstanceOf(child,Parent)
- 能升职加薪?PMP证书含金量浅析
- Show member variables and methods in classes in idea
- String类型转换BigDecimal、Date类型
- One of the basic learning of function
- Use of vscode
- matlab遍历图像、字符串数组等基本操作
- 微软、哥伦比亚大学|GODEL:目标导向对话的大规模预训练
- 【智能QbD风险评估工具】上海道宁为您带来LeanQbD介绍、试用、教程
猜你喜欢

首席信息官对高绩效IT团队定义的探讨和分析

Microsoft, Columbia University | Godel: large scale pre training of goal oriented dialogue

编程英语生词笔记本

Pytest Collection (2) - mode de fonctionnement pytest

从MLPerf谈起:如何引领AI加速器的下一波浪潮

基于三维GIS的不动产管理应用

AirServer2022最新版功能介绍及下载

Significance and measures of security encryption of industrial control equipment

【智能QbD风险评估工具】上海道宁为您带来LeanQbD介绍、试用、教程
![[deep learning] use deep learning to monitor your girlfriend's wechat chat?](/img/03/ecf50eacc91c0633b0d9689cdad2c2.png)
[deep learning] use deep learning to monitor your girlfriend's wechat chat?
随机推荐
能升职加薪?PMP证书含金量浅析
[intelligent QBD risk assessment tool] Shanghai daoning brings you leanqbd introduction, trial and tutorial
"The silk road is in its youth and looks at Fujian" is in the hot collection of works in the Fujian foreign youth short video competition
[live broadcast review] the first 8 live broadcasts of battle code Pioneer have come to a perfect end. Please look forward to the next one!
Interview question: what is the difference between MySQL's Union all and union, and how many join methods MySQL has (Alibaba interview question) [easy to understand]
最近公共祖先(LCA)在线做法
Make a three digit number of all daffodils "recommended collection"
TOPS,处理器运算能力单位、每秒钟可进行一万亿次
Do you want to make up for the suspended examination in the first half of the year? Including ten examinations for supervision engineers, architects, etc
基于LSTM模型实现新闻分类
同花顺股票开户选哪个券商好手机开户是安全么?
GaussDB(DWS)主动预防排查
股票手机开户哪个app好,安全性较高的
焱融看 | 混合云时代下,如何制定多云策略
使用闭包实现点击按钮切换 toggle
Unity 使用Sqlite
Medium pen test questions: flip the string, such as ABCD, print out DCBA
Spark面试题
企业架构与项目管理的关联和区别
MySQL系列之事务日志Redo log学习笔记