本帖最后由 mei326 于 2013-7-5 10:53 编辑
通过DMA读取ADC的转换结果,不过这转换值着实不解~大伙帮忙看看问题到底出在哪里!!
- #define ADC1_DR_Address ((uint32_t)0x4001244C) //ADC1 DR¼Ä´æÆ÷»ùµØÖ·
- ADC_InitTypeDef ADC_InitStructure; //ADC³õʼ»¯½á¹¹ÌåÉùÃ÷
- DMA_InitTypeDef DMA_InitStructure; //DMA³õʼ»¯½á¹¹ÌåÉùÃ÷
- // ×¢£ºADCΪ12λģÊýת»»Æ÷£¬Ö»ÓÐADCConvertedValueµÄµÍ12λÓÐЧ
- __IO uint16_t ADCConvertedValue;
- /**
- * [url=home.php?mod=space&uid=247401]@brief[/url] Configures the different GPIO ports.
- * @param None
- * @retval None//
- */
- void ADC_GPIO_Configuration(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- /* Configure PB.00 (ADC Channel0) as analog input -------------------------*/
- /*PB0 ×÷ΪģÄâͨµÀ0ÊäÈëÒý½Å */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- }
- /**
- * @}
- */
- void STM_EVAL_ADCConfig(void)
- {
- /* Enable DMA1 clock */
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
-
- /* DMA1 channel1 configuration ----------------------------------------------*/
- DMA_DeInit(DMA1_Channel1);
- DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address; //DMA¶ÔÓ¦µÄÍâÉè»ùµØÖ·
- DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&ADCConvertedValue; //ÄÚ´æ´æ´¢»ùµØÖ·
- DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; //DMAµÄת»»Ä£Ê½ÎªSRCģʽ£¬ÓÉÍâÉè°áÒÆµ½ÄÚ´æ
- DMA_InitStructure.DMA_BufferSize = 1; //DMA»º´æ´óС£¬1¸ö,µ¥Î»ÎªDMA_MemoryDataSize
- DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //½ÓÊÕÒ»´ÎÊý¾Ýºó£¬É豸µØÖ·½ûÖ¹ºóÒÆ
- DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable; //¹Ø±Õ½ÓÊÕÒ»´ÎÊý¾Ýºó£¬Ä¿±êÄÚ´æµØÖ·ºóÒÆ
- DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;//¶¨ÒåÍâÉèÊý¾Ý¿í¶ÈΪ16λ
- DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; //DMA°áÊý¾Ý³ß´ç£¬HalfWord¾ÍÊÇΪ16λ
- DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; //ת»»Ä£Ê½£¬Ñ­»·»º´æÄ£Ê½¡£
- DMA_InitStructure.DMA_Priority = DMA_Priority_High; //DMAÓÅÏȼ¶¸ß
- DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; //M2Mģʽ½ûÓÃ
- DMA_Init(DMA1_Channel1, &DMA_InitStructure);
-
- /* Enable DMA1 channel1 */
- DMA_Cmd(DMA1_Channel1, ENABLE);
- /* Enable ADC1 and GPIOC clock */
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_GPIOB, 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Íⲿ¿ª¹Ø£¬¹Ø±Õ״̬
- ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; //¶ÔÆë·½Ê½,ADCΪ12λÖУ¬ÓÒ¶ÔÆë·½Ê½
- ADC_InitStructure.ADC_NbrOfChannel = 1; //¿ªÆôͨµÀÊý£¬1¸ö
- ADC_Init(ADC1, &ADC_InitStructure);
- /* ADC1 regular channel10 configuration ADCͨµÀ×飬 µÚ10¸öͨµÀ ²ÉÑù˳Ðò1£¬×ª»»Ê±¼ä */
- ADC_RegularChannelConfig(ADC1, ADC_Channel_8, 1, ADC_SampleTime_1Cycles5);
- /* Enable ADC1 DMA */
- ADC_DMACmd(ADC1, ENABLE); //ADCÃüÁʹÄÜ
- /* Enable ADC1 */
- ADC_Cmd(ADC1, ENABLE); //¿ªÆôADC1
-
- /* 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); //Á¬Ðø×ª»»¿ªÊ¼£¬ADCͨ¹ýDMA·½Ê½²»¶ÏµÄ¸üÐÂRAMÇø¡£
- }
- /**
- * @}
- */
- uint16_t GetAdc_Value(void)
- {
- return ADCConvertedValue;
- }
[
|