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

杰理之烧录都使用 VBAT 供电,供电电压 4.2V【篇】

Sonic云真机学习总结6 - 1.4.1服务端、agent端部署
![[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?

Icml2022 | interventional contrastive learning based on meta semantic regularization

九章云极DataCanvas公司蝉联中国机器学习平台市场TOP 3

杰理之烧录上层版物料需要【篇】

企业架构与项目管理的关联和区别

Go - exe corresponding to related dependency

MIT|256KB 内存下的设备上训练

指标陷阱:IT领导者易犯的七个KPI错误
随机推荐
PCB线路板塞孔工艺的那些事儿~
测试撤销1
统计字符中每个字符出现的个数
Application of real estate management based on 3D GIS
焱融看 | 混合云时代下,如何制定多云策略
多种智能指针
Business visualization - make your flowchart'run'up
ngnix基础知识
News classification based on LSTM model
编程英语生词笔记本
Yan Rong looks at how to formulate a multi cloud strategy in the era of hybrid cloud
杰理之、产线装配环节【篇】
Separate the letters and numbers in the string so that the letters come first and the array comes last
Show member variables and methods in classes in idea
AirServer2022最新版功能介绍及下载
基于YOLOv5的口罩佩戴检测方法
Qtreeview+qabstractitemmodel custom model: the third of a series of tutorials [easy to understand]
杰理之关于长按开机检测抬起问题【篇】
linux下清理系统缓存并释放内存
The correct way to set the bypass route