当前位置:网站首页>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);
}
边栏推荐
猜你喜欢

PMP证书真的有用吗?

100年仅6款产品获批,疫苗竞争背后的“佐剂”江湖

编程英语生词笔记本
![[noip2013] building block competition [noip2018] road laying greed / difference](/img/d1/a56231cd4eb3cc1d91d8a55048ccfe.png)
[noip2013] building block competition [noip2018] road laying greed / difference

js如何获取集合对象中某元素列表

Significance and measures of security encryption of industrial control equipment

杰理之蓝牙耳机品控和生产技巧【篇】

最近公共祖先离线做法(tarjan)

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

杰理之、产线装配环节【篇】
随机推荐
Go - exe corresponding to related dependency
Go — 相关依赖对应的exe
Using closures to switch toggle by clicking a button
灵动微 MM32 多路ADC-DMA配置
MySQL learning notes - SQL optimization of optimization
MQ学习笔记
能升职加薪?PMP证书含金量浅析
Aidl basic use
Manually implement function isinstanceof (child, parent)
ngnix基础知识
"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
基于K-means的用户画像聚类模型
杰理之蓝牙耳机品控和生产技巧【篇】
【MySQL】索引的创建、查看和删除
《QTreeView+QAbstractItemModel自定义模型》:系列教程之三[通俗易懂]
小 P 周刊 Vol.11
使用闭包实现点击按钮切换 toggle
Little p weekly Vol.11
[commercial terminal simulation solution] Shanghai daoning brings you Georgia introduction, trial and tutorial
【生态伙伴】鲲鹏系统工程师培训