看了這個代碼之后終于明白了規則多通道轉換是怎么回事,以及整體如何實現了。附代碼:
/*******************************************************************************
* Function Name : main
* Description : Main program
* Input : None
* Output : None
* Return : None
*******************************************************************************/
int main(void)
{
#ifdef DEBUG
debug();
#endif
/* System clocks configuration ---------------------------------------------*/
RCC_Configuration();
/* NVIC configuration ------------------------------------------------------*/
NVIC_Configuration();
/* GPIO configuration ------------------------------------------------------*/
GPIO_Configuration();
LcdShow_Init();
/* DMA1 channel1 configuration ----------------------------------------------*/
DMA_DeInit(DMA1_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;//外設地址
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)ADC_RCVTab;//內存地址
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;//dma傳輸方向單向
DMA_InitStructure.DMA_BufferSize = 160;//設置DMA在傳輸時緩沖區的長度 word
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;//設置DMA的外設遞增模式,一個外設
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;//設置DMA的內存遞增模式,
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;//外設數據字長
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;//內存數據字長
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;//設置DMA的傳輸模式:連續不斷的循環模式
DMA_InitStructure.DMA_Priority = DMA_Priority_High;//設置DMA的優先級別
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;//設置DMA的2個memory中的變量互相訪問
DMA_Init(DMA1_Channel1, &DMA_InitStructure);
/* Enable DMA1 channel1 */
DMA_Cmd(DMA1_Channel1, ENABLE);
/* ADC1 configuration ------------------------------------------------------*/
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;//獨立工作模式
ADC_InitStructure.ADC_ScanConvMode = ENABLE;//掃描方式
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;//連續轉換
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;//外部觸發禁止
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;//數據右對齊
ADC_InitStructure.ADC_NbrOfChannel = 8;//用于轉換的通道數
ADC_Init(ADC1, &ADC_InitStructure);
/* ADC1 regular channels configuration [規則模式通道配置]*/
ADC_RegularChannelConfig(ADC1, ADC_Channel_8 , 1, ADC_SampleTime_239Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_9 , 2, ADC_SampleTime_239Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 3, ADC_SampleTime_239Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 4, ADC_SampleTime_239Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 5, ADC_SampleTime_239Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_13, 6, ADC_SampleTime_239Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 7, ADC_SampleTime_239Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_15, 8, ADC_SampleTime_239Cycles5);
/* Enable ADC1 DMA [使能ADC1 DMA]*/
ADC_DMACmd(ADC1, ENABLE);
/* Enable ADC1 [使能ADC1]*/
ADC_Cmd(ADC1, ENABLE);
/* Enable ADC1 reset calibaration register */
ADC_ResetCalibration(ADC1);
/* Check the end of ADC1 reset calibration register */
while(ADC_GetResetCalibrationStatus(ADC1));
/* Start ADC1 calibaration */
ADC_StartCalibration(ADC1);
/* Check the end of ADC1 calibration */
while(ADC_GetCalibrationStatus(ADC1));
/* Start ADC1 Software Conversion */
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
}
評論
查看更多