GPIO_InitType GPIO_InitStructure;
ADC_InitType ADC_InitStructure;
DMA_InitType DMA_InitStructure;
__IO uint16_t ADCConvertedValue[3];
/* System clocks configuration ---------------------------------------------*/
RCC_Configuration();
GPIO_InitStruct(&GPIO_InitStructure);
/* Configure PC0 PC1 as analog input -------------------------*/
GPIO_InitStructure.Pin = GPIO_PIN_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Analog;
GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure);
/* DMA channel1 configuration ----------------------------------------------*/
DMA_DeInit(DMA_CH1);
DMA_InitStructure.PeriphAddr = (uint32_t)&ADC->DAT;
DMA_InitStructure.MemAddr = (uint32_t)ADCConvertedValue;
DMA_InitStructure.Direction = DMA_DIR_PERIPH_SRC;
DMA_InitStructure.BufSize = 3;
DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE;
DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE;
DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_HALFWORD;
DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.CircularMode = DMA_MODE_CIRCULAR;
DMA_InitStructure.Priority = DMA_PRIORITY_HIGH;
DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE;
DMA_Init(DMA_CH1, &DMA_InitStructure);
DMA_RequestRemap(DMA_REMAP_ADC1, DMA, DMA_CH1, ENABLE);
/* Enable DMA channel1 */
DMA_EnableChannel(DMA_CH1, ENABLE);
/* ADC1 configuration ------------------------------------------------------*/
ADC_InitStructure.MultiChEn = ENABLE;
ADC_InitStructure.ContinueConvEn = ENABLE;
ADC_InitStructure.ExtTrigSelect = ADC_EXT_TRIGCONV_NONE;
ADC_InitStructure.DatAlign = ADC_DAT_ALIGN_R;
ADC_InitStructure.ChsNumber = 3;
ADC_Init(ADC, &ADC_InitStructure);
/* ADC1 enable temperature */
ADC_EnableTempSensorVrefint( ENABLE);
/* ADC1 regular channel17 configuration */
ADC_ConfigRegularChannel(ADC, ADC_CH_1_PA0, 1, ADC_SAMP_TIME_239CYCLES5);
ADC_ConfigRegularChannel(ADC, ADC_CH_17, 2, ADC_SAMP_TIME_239CYCLES5);
ADC_ConfigRegularChannel(ADC, ADC_CH_18, 3, ADC_SAMP_TIME_239CYCLES5);
/* Enable ADC DMA */
ADC_EnableDMA(ADC, ENABLE);
(*((uint32_t*)(0x40001800+0x24))) |= 2<<19;//用户手册中找不到的配置位
/* Enable ADC */
ADC_Enable(ADC, ENABLE);
/* Check ADC Ready */
while(ADC_GetFlagStatusNew(ADC,ADC_FLAG_RDY) == RESET)
;
/* Start ADC1 calibration */
ADC_StartCalibration(ADC);
/* Check the end of ADC1 calibration */
while (ADC_GetCalibrationStatus(ADC))
;
/* Start ADC1 Software Conversion */
ADC_EnableSoftwareStartConv(ADC, ENABLE);
/* Config Uart1 as Temperature output */
USART_Config();
while (1)
{
/* */
Delay(5000000);
printf("ADCConvertedValue[0] = %x\r\n",ADCConvertedValue[0]);
Delay(5000000);
TempValue = TempCal(ADCConvertedValue[1]);
printf("Temperature = %.3f C\r\n",TempValue);
Delay(5000000);
printf("ADCConvertedValue[2] = %x\r\n",ADCConvertedValue[2]);
}
|