当前位置:网站首页>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);
}
边栏推荐
- Make a three digit number of all daffodils "recommended collection"
- The correct way to set the bypass route
- Unity 使用Sqlite
- 手动实现function isInstanceOf(child,Parent)
- Using closures to switch toggle by clicking a button
- Pytest Collection (2) - mode de fonctionnement pytest
- MIT|256KB 内存下的设备上训练
- 【STM32】STM32CubeMX教程二–基本使用(新建工程点亮LED灯)
- 【直播回顾】战码先锋首期8节直播完美落幕,下期敬请期待!
- 100年仅6款产品获批,疫苗竞争背后的“佐剂”江湖
猜你喜欢

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

手动实现function isInstanceOf(child,Parent)

十三届蓝桥杯B组国赛

pytest合集(2)— pytest运行方式

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

Icml2022 | interventional contrastive learning based on meta semantic regularization

基于K-means的用户画像聚类模型

最近公共祖先(LCA)在线做法

List announced | outstanding intellectual property service team in China in 2021

Aidl basic use
随机推荐
GaussDB(DWS)主动预防排查
Pytest collection (2) - pytest operation mode
股票手机开户哪个app好,安全性较高的
Airserver mobile phone third-party screen projection computer software
PCB线路板塞孔工艺的那些事儿~
基于三维GIS的不动产管理应用
Basic operation of binary tree
使用闭包实现点击按钮切换 toggle
【直播回顾】战码先锋首期8节直播完美落幕,下期敬请期待!
Aidl basic use
mysql 学习笔记-优化之SQL优化
[noip2013] building block competition [noip2018] road laying greed / difference
require与import的区别和使用
分离字符串中的字母和数字并使得字母在前数组在后
Talking from mlperf: how to lead the next wave of AI accelerator
Use of vscode
News classification based on LSTM model
Go — 相关依赖对应的exe
【智能QbD风险评估工具】上海道宁为您带来LeanQbD介绍、试用、教程
TOPS,处理器运算能力单位、每秒钟可进行一万亿次