当前位置:网站首页>STM32 - DMA notes
STM32 - DMA notes
2022-07-26 03:00:00 【The poorest are beggars and immortals will always come out】
One 、DMA What is it?
DMA Transfer data from a The address space is copied to another address space . When CPU Initialize this transfer action , The transmission action itself is caused by DMA controller To implement and complete . A typical example is moving a block of external memory into the chip faster Memory area . Operations like this don't delay the processor , Instead, it can be rescheduled to deal with other jobs do .DMA There is no need for transmission CPU direct Control transmission , Through hardware for RAM And I/O equipment Open up a path for direct data transmission , Can make CPU Greatly improved the efficiency of .
Two 、DMA The role of
“ Carry ”, Move external data into MCU, There is no need to CPU To do ,CPU You can deal with other things .
3、 ... and 、DMA1 The channel corresponding to “ Portable source ”

Four 、DMA Related configuration of
The first three red boxes are mainly configured , The fourth purple box is selected according to the length of one handling , There is one 8 position 、16 position 、32 position .
u16 ADC1_Value[C_Channel_Sample][C_ADC_Channel] = { 0 }; // DMA Storage place for handling data ( Array )

DMA Configuration of :
void DMA_Init_JX(void)
{
DMA_InitTypeDef DMA_InitStructure;
//NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); // Can make DMA The clock
// DMA_CH1(ADC1) Parameter setting
//--------------------------------------------------------------------------------------------------------------------------
DMA_DeInit(DMA1_Channel1); // take DMA The passage of 1 Register reset to default
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)&ADC1->DR; // DMA peripherals ADC Base address
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)ADC1_Value; // DMA Memory base address
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; // Memory as the destination of data transmission
DMA_InitStructure.DMA_BufferSize = C_ADC_Channel * C_Channel_Sample; // DMA The tunnel DMA Cache size
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; // The peripheral address register remains unchanged
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; // The memory address register is incremented
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; // Data width is 16 position
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; // Data width is 16 position
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; // Working in circular cache mode
DMA_InitStructure.DMA_Priority = DMA_Priority_High; // DMA passageway x Have high priority
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; // DMA passageway x Not set to memory to memory transfer
DMA_Init(DMA1_Channel1, &DMA_InitStructure); // according to DMA_InitStruct The parameter specified in DMA The passage of
//--------------------------------------------------------------------------------------------------------------------------
DMA_Cmd(DMA1_Channel1, ENABLE); // start-up DMA passageway
}ADC Channel configuration :
void ADC1_Rocker_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
ADC_InitTypeDef ADC_InitStructure;
// NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_ADC1, ENABLE); // Can make PA Port and ADC1 The clock
// Analog input :PA1、PA2、PA3、PA6
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; // Analog input pins
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz; // The input mode does not need to set the port speed
GPIO_Init(GPIOA, &GPIO_InitStructure);
// To configure ADC1_CH1、ADC1_CH2、ADC1_CH3、ADC1_CH6
// ADC Working conditions :ADC The clock frequency of <=14MHz && ADC sampling frequency <=1MHz
// ADC Total conversion period of ( must >=1us) = ( Sampling period (1.5~239.5) + 12.5( Fixed conversion period )) / ADC clock frequency
// When :ADC The clock frequency of ==12MHz、 Sampling period ==1.5,ADC Conversion cycle ≈1.17us
//---------------------------------------------------------------------------------------------------------------------
RCC_ADCCLKConfig(RCC_PCLK2_Div6); // ADC The clock 6 frequency division :72M/6=12M
ADC_DeInit(ADC1); // Reset ADC1
// Set up ADC1 Working mode of
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; // ADC Working mode :ADC1 and ADC2 Working in independent mode
ADC_InitStructure.ADC_ScanConvMode = ENABLE; // " Scan conversion mode " Can make . namely :ADC Working in multi-channel mode
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; // " Continuous conversion mode " Disability . namely :ADC Working in single conversion mode
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; // The conversion is initiated by software ( It can also be set as an external trigger )
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; // ADC Data alignment : Right alignment
ADC_InitStructure.ADC_NbrOfChannel = C_ADC_Channel; // Set the order for rule conversion ADC The number of channels
ADC_Init(ADC1, &ADC_InitStructure); // initialization ADC1
// In order to correctly configure each ADC passageway , The user is calling ADC_Init() after ,
// Must call ADC_xxxChannelConfig() To configure the conversion order and sampling time of each used channel .
//--------------------------------------------------------------------
ADC_RegularChannelConfig(ADC1, N_ADC_Channel_1, 1, ADC_SampleTime_239Cycles5); // Parameters :ADC1, To set up ADC Channel serial number , Rule group sampling order , Sampling period
// This function : The configuration is "ADC1" The passage of "1", Its sampling order in the rule group is "1", The sampling period is "ADC_SampleTime_239Cycles5"
ADC_RegularChannelConfig(ADC1, N_ADC_Channel_3, 2, ADC_SampleTime_239Cycles5);
// This function : The configuration is "ADC1" The passage of "3", Its sampling order in the rule group is "2", The sampling period is "ADC_SampleTime_239Cycles5"
//---------------------------------------------------------------------------------------------------------------------
/*
//ADC1 The interrupt NVIC Set up
//---------------------------------------------------------------------------------
NVIC_InitStructure.NVIC_IRQChannel = ADC1_2_IRQn; // ADC1 interrupt
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3; // preemption 3 level
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; // Sub priority 3 level
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; // Can make ADC1_2_IRQn interrupt
NVIC_Init(&NVIC_InitStructure); // initialization NVIC register
ADC_ITConfig(ADC1,ADC_IT_EOC,ENABLE ); // allow ADC1 Of EOC interrupt
//---------------------------------------------------------------------------------
*/
// Turn on ADC Of DMA Support
ADC_DMACmd(ADC1, ENABLE); // To achieve DMA function , Independent configuration is also required DMA Channel and other parameters
ADC_Cmd(ADC1, ENABLE); // Can make ADC1
ADC_ResetCalibration(ADC1); // Can make ADC1 Reset calibration
while(ADC_GetResetCalibrationStatus(ADC1)); // wait for ADC1 Reset calibration is over
ADC_StartCalibration(ADC1); // Turn on ADC1 calibration
while(ADC_GetCalibrationStatus(ADC1)); // wait for ADC1 End of calibration
}ADC collection :
When in the configuration , Configured as software trigger mode . In the use of ADC when , Use the program to enable ADC1 transformation , That's the first sentence .
During handling DMA One move 16 Bit data , front 8 Position as ADC1 passageway 1 Value , Put it in the first column of the two-dimensional array
after 8 Position as ADC1 passageway 3 Value , Put it in the second column of the two-dimensional array
void ADC1_Value_average(void)
{
// Rocker detection
//------------------------------------------------------------------------
ADC_SoftwareStartConvCmd(ADC1, ENABLE); // Software enables ADC1 transformation
// After the conversion ,DMA Automatically move the data to the specified location
//while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC )); // Wait for the conversion to finish
AM_ADC_Channel1_Sample += ADC1_Value[C_ADC_Sample][0]; // obtain
AM_ADC_Channel3_Sample += ADC1_Value[C_ADC_Sample][1];
C_ADC_Sample++ ; // ADC Actual sampling times
// Determine whether samples have been taken 10 Time
if(C_ADC_Sample >= C_Channel_Sample)
{
C_ADC_Sample = 0;
AV_ADC_Channel1_Sample = AM_ADC_Channel1_Sample / C_Channel_Sample; // Seek channel 1 Average value
AM_ADC_Channel1_Sample = 0 ;
AV_ADC_Channel3_Sample = AM_ADC_Channel3_Sample / C_Channel_Sample; // Seek channel 3 Average value
AM_ADC_Channel3_Sample = 0 ;
}
}边栏推荐
- 1.软件测试-----软件测试的基本概念
- Be highly vigilant! Weaponization of smartphone location data on the battlefield
- How to effectively prevent others from wearing the homepage snapshot of the website
- 一篇文章让你理解 云原生 容器化相关
- Chapter 3 business function development (delete clues)
- Continuous delivery and Devops are good friends
- 【C语言】深入理解 整型提升 和 算术转换
- OxyCon 2022 网络抓取前沿大会即将开启!
- MySQL建Websites数据表
- The El table header merges the first four columns into one cell
猜你喜欢

The LAAS protocol elephant of defi 2.0 is the key to revitalizing the development of defi track

1.软件测试-----软件测试的基本概念

多线程编程

重装Win7系统如何进行?

【方向盘】启动命令和IDEA如何传递:VM参数、命令行参数、系统参数、环境变量参数、main方法参数

Win11麦克风权限的开启方法

(pc+wap) dream weaving template vegetable and fruit websites

移位距离和假设的应用

文件操作(一)——文件简介与文件的打开方式和关闭

ShardingSphere数据分片
随机推荐
Article setting top
I hope you can help me with MySQL
基础知识-网络与服务器
Safety margin of mass consumption
【方向盘】工具提效:Sublime Text 4的常用快捷键合集
ES6高级-利用构造函数继承父类属性
朋友刚学完自动化测试就拿25Koffer,我功能测试何时才能到头?
What if the test / development programmer gets old? Lingering cruel facts
pbootcms上传缩略图尺寸自动缩小变模糊
【C语言】深入理解 整型提升 和 算术转换
How to design test cases according to the requirements of login testing?
c语言分层理解(c语言函数)
Win11隐藏输入法状态栏方法
eslint常见报错集合
Be highly vigilant! Weaponization of smartphone location data on the battlefield
Vofa+ serial port debugging assistant
hello world驱动(二)-初级版
[introduction to C language] zzulioj 1006-1010
(PC+WAP)织梦模板蔬菜水果类网站
[steering wheel] use the 60 + shortcut keys of idea to share with you, in order to improve efficiency (live template & postfix completion)