void Adc_Init(void)
{
ADC_InitTypeDef ADC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |RCC_APB2Periph_ADC1 , ENABLE ); //ê1ÄüADC1í¨μàê±Öó
//RCC_ADCCLKConfig(RCC_PCLK2_Div8); //éèÖÃADC·ÖÆμòò×ó6 72M/6=12,ADC×î′óê±¼ä2»Äü3¬1y14M
// //PA0--ADC_IN0 PA1--ADC_IN1 PA2--ADC_IN2 PA3--ADC_IN3 PA4--ADC_IN4 PA5--ADC_IN5
//PA1 ×÷ÎaÄ£Äaí¨μàêäèëòy½Å
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; //Ä£Äaêäèëòy½Å
GPIO_Init(GPIOA, &GPIO_InitStructure);
ADC_DeInit(ADC1); //¸′λADC1
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; //ADC1¤×÷Ä£ê½:ADC1oíADC21¤×÷Ôú¶àá¢Ä£ê½
ADC_InitStructure.ADC_ScanConvMode = DISABLE; //μ¥í¨μà1رÕ
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; //1رÕá¬Dø×a»»
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T3_CC1; //×a»»óéTIM3′¥·¢
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; //ADCêy¾Yóò¶ÔÆë
ADC_InitStructure.ADC_NbrOfChannel =1; //Ë3Dò½øDD1æÔò×a»»μÄADCí¨μàμÄêyÄ¿£¬′Ë′|1¸öDÅμࣨ¿é¿aμÄÎa1~16£©
ADC_Init(ADC1, &ADC_InitStructure); //¸ù¾YADC_InitStructÖDÖ¸¶¨μÄ2Îêy3õê¼»ˉíaéèADCxμļÄ′æÆ÷
//ADC3£1æDÅμàÅäÖÃ
//ADC1,ADCí¨μàx,1æÔò2éÑùË3DòÖμÎay,2éÑùê±¼äÎa55.5ÖüÆú
ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_1Cycles5 );
// ¿aÆôADCμÄDMAÖ§3Ö£¨òaêμÏÖDMA1|Äü£¬»1Dè¶àá¢ÅäÖÃDMAí¨μàμè2Îêy£©
ADC_DMACmd(ADC1, ENABLE); //ê1ÄüADC1μÄDMA′«êä
ADC_Cmd(ADC1, ENABLE); //ê1ÄüÖ¸¶¨μÄADC1
ADC_ResetCalibration(ADC1); //ê1Äü¸′λD£×¼
while(ADC_GetResetCalibrationStatus(ADC1)); //μè′y¸′λD£×¼½áêø
ADC_StartCalibration(ADC1); //¿aÆôADD£×¼
while(ADC_GetCalibrationStatus(ADC1)); //μè′yD£×¼½áêø
// ADC_SoftwareStartConvCmd(ADC1, ENABLE); //ê1ÄüÖ¸¶¨μÄADC1μÄèí¼t×a»»Æô¶ˉ1|Äü
}
void TIM3_Int_Init(u16 arr,u16 psc)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); //ê±Öóê1Äü
TIM_TimeBaseStructure.TIM_Period = arr; //éèÖÃÔúÏÂò»¸ö¸üDÂê¼t×°èë»î¶ˉμÄ×Ô¶ˉÖØ×°ÔؼÄ′æÆ÷ÖüÆúμÄÖμ ¼Æêyμ½5000Îa500ms
TIM_TimeBaseStructure.TIM_Prescaler =psc; //éèÖÃóÃà′×÷ÎaTIMxê±ÖóÆμÂê3yêyμÄÔ¤·ÖÆμÖμ 10KhzμļÆêyÆμÂê
TIM_TimeBaseStructure.TIM_ClockDivision = 0; //éèÖÃê±Öó·Ö¸î:TDTS = Tck_tim
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //TIMÏòéϼÆêyÄ£ê½
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); //¸ù¾YTIM_TimeBaseInitStructÖDÖ¸¶¨μÄ2Îêy3õê¼»ˉTIMxμÄê±¼ä»ùêyμ¥λ
TIM_ITConfig( //ê1Äü»òÕßê§ÄüÖ¸¶¨μÄTIMÖD¶Ï
TIM3, //TIM2
TIM_IT_Update ,
ENABLE //ê1Äü
);
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; //TIM3ÖD¶Ï
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //ÏèÕ¼óÅÏ輶0¼¶
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //′óóÅÏ輶3¼¶
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQí¨μà±»ê1Äü
NVIC_Init(&NVIC_InitStructure); //¸ù¾YNVIC_InitStructÖDÖ¸¶¨μÄ2Îêy3õê¼»ˉíaéèNVIC¼Ä′æÆ÷
TIM_Cmd(TIM3, ENABLE); //ê1ÄüTIMxíaéè
}
void MYDMA_Config(DMA_Channel_TypeDef* DMA_CHx,u32 cpar,u32 cmar,u16 cndtr)
{
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); //ê1ÄüDMA′«êä
DMA_DeInit(DMA_CHx); //½«DMAμÄí¨μà1¼Ä′æÆ÷ÖØéèÎaè±ê¡Öμ
// DMA1_MEM_LEN=cndtr;
DMA_InitStructure.DMA_PeripheralBaseAddr = cpar; //DMAíaéè»ùμØÖ·
DMA_InitStructure.DMA_MemoryBaseAddr = cmar; //DMAÄú′æ»ùμØÖ·
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; //êy¾Y′«êä·½Ïò£¬′óíaéèADC·¢Ëíμ½Äú′æ¶áè¡
DMA_InitStructure.DMA_BufferSize = cndtr; //DMAí¨μàμÄDMA»o′æμÄ′óD¡
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //íaéèμØÖ·¼Ä′æÆ÷2»±ä
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; //Äú′æμØÖ·¼Ä′æÆ÷μYÔö
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; //êy¾Y¿í¶èÎa16λ
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; //êy¾Y¿í¶èÎa16λ
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; //Ñ-»·1¤×÷Ä£ê½
DMA_InitStructure.DMA_Priority = DMA_Priority_High; //DMAí¨μà xóμóD¸ßóÅÏ輶
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; //DMAí¨μàxûóDéèÖÃÎaÄú′æμ½Äú′æ′«êä
DMA_Init(DMA_CHx, &DMA_InitStructure); //¸ù¾YDMA_InitStructÖDÖ¸¶¨μÄ2Îêy3õê¼»ˉDMAμÄí¨μàUSART1_Tx_DMA_ChannelËù±êê¶μļÄ′æÆ÷
}
就差TIM3的中断函数怎么写了-。-
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>