之前第二组读不出值来。。现在好了,贴不删了。。代码可用。和我一样的菜鸟把第二通运算出温度就可以了。。<div class="blockcode"><div id="code_Obh">
- #include &quot;adcdma.h&quot;
- // __IO uint16_t ADCDATA;
- //__IO uint16_t ADCDATA[10][2];
- __IO u16 ADCDATA[2];
- __IO float ADCDONE[2];
- void GPIO_Conf()
- {
- GPIO_InitTypeDef GPIO_Conf;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO | RCC_APB2Periph_ADC1,ENABLE);
- GPIO_Conf.GPIO_Pin = GPIO_Pin_1;
- GPIO_Conf.GPIO_Mode = GPIO_Mode_AIN;
- GPIO_Init(GPIOC,&GPIO_Conf);
- GPIO_Conf.GPIO_Pin = GPIO_Pin_9;
- GPIO_Conf.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_Conf.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOA,&GPIO_Conf);
- }
- void DMA_Conf()
- {
- DMA_InitTypeDef DMA_Conf;
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE);
- DMA_DeInit(DMA1_Channel1);
- DMA_Conf.DMA_PeripheralBaseAddr = (u32)&ADC1->DR;
- DMA_Conf.DMA_MemoryBaseAddr = (u32)ADCDATA;
- DMA_Conf.DMA_DIR = DMA_DIR_PeripheralSRC;
- DMA_Conf.DMA_BufferSize =2;
- DMA_Conf.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
- DMA_Conf.DMA_MemoryInc = DMA_MemoryInc_Enable;
- DMA_Conf.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
- DMA_Conf.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
- DMA_Conf.DMA_Mode = DMA_Mode_Circular;
- DMA_Conf.DMA_Priority = DMA_Priority_High;
- DMA_Conf.DMA_M2M = DMA_M2M_Disable;
- DMA_Init(DMA1_Channel1,&DMA_Conf);
- DMA_Cmd(DMA1_Channel1,ENABLE);
- }
- void USART_Conf()
- {
- USART_InitTypeDef USART_Conf;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
- USART_Conf.USART_BaudRate = 9600;
- USART_Conf.USART_WordLength = USART_WordLength_8b;
- USART_Conf.USART_StopBits = USART_StopBits_1;
- USART_Conf.USART_Parity = USART_Parity_No;
- USART_Conf.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
- USART_Conf.USART_Mode = USART_Mode_Tx;
- USART_Init(USART1,&USART_Conf);
-
- USART_Cmd(USART1,ENABLE);
-
- }
- void ADC_Conf()
- {
- ADC_InitTypeDef ADC_Conf;
-
- ADC_Conf.ADC_Mode = ADC_Mode_Independent;
- ADC_Conf.ADC_ScanConvMode = ENABLE;
- ADC_Conf.ADC_ContinuousConvMode = ENABLE;
- ADC_Conf.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
- ADC_Conf.ADC_DataAlign = ADC_DataAlign_Right ;
- ADC_Conf.ADC_NbrOfChannel = 2;
- ADC_Init(ADC1,&ADC_Conf);
-
-
-
- RCC_ADCCLKConfig(RCC_PCLK2_DiARM);
- ADC_RegularChannelConfig(ADC1,ADC_Channel_11,1,ADC_SampleTime_55Cycles5 );
- ADC_RegularChannelConfig(ADC1,ADC_Channel_16,2,ADC_SampleTime_55Cycles5 );
-
- ADC_DMACmd(ADC1,ENABLE);
- ADC_TempSensorVrefintCmd(ENABLE);
- ADC_Cmd(ADC1,ENABLE);
-
- ADC_ResetCalibration(ADC1);
- while(ADC_GetResetCalibrationStatus(ADC1));
- ADC_StartCalibration(ADC1);
- while(ADC_GetCalibrationStatus(ADC1));
- ADC_SoftwareStartConvCmd(ADC1,ENABLE);
- while(ADC_GetSoftwareStartConvStatus(ADC1));
-
-
- }
- float getvol(u16 advol)
- {
- return (float)advol/4096*3.3;
- }
- void datacomp()
- {
- u8 i;
- for(i=0; i<2; i++)
- {
- ADCDONE = getvol(ADCDATA);
- }
- }
- void CALL_SET()
- {
- GPIO_Conf();
- DMA_Conf();
- USART_Conf();
- ADC_Conf();}
|