資源描述:
《STM32多通道AD轉(zhuǎn)換》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫(kù)。
1、關(guān)于AD多通道采集的總結(jié)前幾天小試了下,用STM32做了個(gè)萬(wàn)用表,采集電壓電流電阻并液晶顯示。期間遇到一個(gè)最大的問(wèn)題應(yīng)該就是,要開(kāi)啟多個(gè)AD通道,結(jié)合DMA傳輸,小結(jié)下下面是我對(duì)AD的配置,還有DMAvoidDMA_ADC_Config(){/*DMAchannel1configuration----------------------------------------------*/DMA_DeInit(DMA_Channel1);//復(fù)位DMA通道xDMA_InitStructure.DMA_Periphe
2、ralBaseAddr=ADC_DR_Address;//定義DMA通道外設(shè)基地址=ADC1_DR_Address源//AD采集到的數(shù)據(jù)存放的寄存器DMA_InitStructure.DMA_MemoryBaseAddr=(u32)ADC_RegularConvertedValueTab;//定義DMA通道存儲(chǔ)器地址,內(nèi)存中的數(shù)據(jù)目的DMA_InitStructure.DMA_DIR=DMA_DIR_PeripheralSRC;//指定外設(shè)為源地址DMA_InitStructure.DMA_BufferSize=
3、4;//定義DMA緩沖區(qū)大小4,4路AD,最后采集到的數(shù)值放在4位數(shù)組中DMA_InitStructure.DMA_PeripheralInc=DMA_PeripheralInc_Disable;//當(dāng)前外設(shè)寄存器地址不變DMA_InitStructure.DMA_MemoryInc=DMA_MemoryInc_Enable;//當(dāng)前存儲(chǔ)器地址遞增DMA_InitStructure.DMA_PeripheralDataSize=DMA_PeripheralDataSize_HalfWord;//定義外設(shè)數(shù)據(jù)寬度1
4、6位DMA_InitStructure.DMA_MemoryDataSize=DMA_MemoryDataSize_HalfWord;//定義存儲(chǔ)器數(shù)據(jù)寬度16位DMA_InitStructure.DMA_Mode=DMA_Mode_Circular;//DMA通道操作模式位環(huán)形緩沖模式DMA_InitStructure.DMA_Priority=DMA_Priority_High;//DMA通道優(yōu)先級(jí)高DMA_InitStructure.DMA_M2M=DMA_M2M_Disable;//禁止DMA通道存儲(chǔ)器到
5、存儲(chǔ)器傳輸DMA_Init(DMA_Channel1,&DMA_InitStructure);//初始化DMA通道1DMA_Cmd(DMA_Channel1,ENABLE);//使能DMA通道1}voidADC1_config(){/*ADC1configuration------------------------------------------------------*/ADC_InitStructure.ADC_Mode=ADC_Mode_Independent;//AD轉(zhuǎn)換模式ADC_InitStru
6、cture.ADC_ScanConvMode=ENABLE;//使能掃描,多通道ADC_InitStructure.ADC_ContinuousConvMode=ENABLE;//連續(xù)轉(zhuǎn)換ADC_InitStructure.ADC_ExternalTrigConv=ADC_ExternalTrigConv_None;;//有軟件控制轉(zhuǎn)換ADC_InitStructure.ADC_DataAlign=ADC_DataAlign_Right;//數(shù)據(jù)右對(duì)齊ADC_InitStructure.ADC_NbrOfChan
7、nel=4;//轉(zhuǎn)換通道為通道4,4個(gè)通道來(lái)回掃描ADC_Init(ADC1,&ADC_InitStructure);/*ADC1regularchannel14configuration*///ADC1選擇信道14
8、15,采集次序1,采樣時(shí)間55.5個(gè)周期ADC_RegularChannelConfig(ADC1,ADC_Channel_14,1,ADC_SampleTime_55Cycles5);//通道14,PC4掃面順序1ADC_RegularChannelConfig(ADC1,ADC_Channel_
9、15,2,ADC_SampleTime_55Cycles5);ADC_RegularChannelConfig(ADC1,ADC_Channel_6,3,ADC_SampleTime_55Cycles5);ADC_RegularChannelConfig(ADC1,ADC_Channel_4,4,ADC_SampleTime_55Cycles5);}DMA其實(shí)開(kāi)一個(gè)就夠了