adc配置:
void MY_ADC_Init(void)
{
ADC_ChannelConfTypeDef ADC1_ChanConf;
ADC1_Handler.Instance = ADC1;
ADC1_Handler.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2;
ADC1_Handler.Init.Resolution = ADC_RESOLUTION_12B;
ADC1_Handler.Init.DataAlign = ADC_DATAALIGN_RIGHT;
ADC1_Handler.Init.ScanConvMode = ADC_SCAN_ENABLE;
ADC1_Handler.Init.EOCSelection = DISABLE;
ADC1_Handler.Init.ContinuousConvMode = ENABLE;
ADC1_Handler.Init.DiscontinuousConvMode = DISABLE;
ADC1_Handler.Init.NbrOfConversion = 2;
ADC1_Handler.Init.NbrOfDiscConversion = 0;
ADC1_Handler.Init.ExternalTrigConv = ADC_SOFTWARE_START;
ADC1_Handler.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
ADC1_Handler.Init.LowPowerAutoWait = DISABLE;
ADC1_Handler.Init.DMAContinuousRequests = ENABLE;
ADC1_Handler.Init.Overrun = ADC_OVR_DATA_PRESERVED;
ADC1_Handler.Init.OversamplingMode = DISABLE;
ADC1_ChanConf.Channel = ADC_CHANNEL_1;
ADC1_ChanConf.Rank = ADC_REGULAR_RANK_1;
ADC1_ChanConf.SamplingTime = ADC_SAMPLETIME_47CYCLES_5;
ADC1_ChanConf.SingleDiff = ADC_SINGLE_ENDED;
ADC1_ChanConf.OffsetNumber = ADC_OFFSET_NONE;
ADC1_ChanConf.Offset = 0;
HAL_ADC_ConfigChannel(&ADC1_Handler, &ADC1_ChanConf);
ADC1_ChanConf.Channel = ADC_CHANNEL_2;
ADC1_ChanConf.Rank = ADC_REGULAR_RANK_2;
ADC1_ChanConf.SamplingTime = ADC_SAMPLETIME_47CYCLES_5;
ADC1_ChanConf.SingleDiff = ADC_SINGLE_ENDED;
ADC1_ChanConf.OffsetNumber = ADC_OFFSET_NONE;
ADC1_ChanConf.Offset = 0;
ADC1_Handler.Init.DMAContinuousRequests = ENABLE;
HAL_ADC_Init(&ADC1_Handler);
HAL_ADC_Start(&ADC1_Handler);
}
DMA配置
void MYDMA_Config(DMA_Channel_TypeDef *DMA_Channel, u32 seq)//
{
__HAL_RCC_DMA1_CLK_ENABLE();
ADC1DMA_Handler.Instance = DMA1_Channel1;
ADC1DMA_Handler.Init.Request = seq;
ADC1DMA_Handler.Init.Direction = DMA_PERIPH_TO_MEMORY;
ADC1DMA_Handler.Init.PeriphInc = DMA_PINC_DISABLE;
ADC1DMA_Handler.Init.MemInc = DMA_MINC_ENABLE;
ADC1DMA_Handler.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
ADC1DMA_Handler.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
ADC1DMA_Handler.Init.Mode = DMA_CIRCULAR;
ADC1DMA_Handler.Init.Priority = DMA_PRIORITY_HIGH;
HAL_DMA_Init(&ADC1DMA_Handler);
HAL_DMA_DeInit(&ADC1DMA_Handler);
__HAL_LINKDMA(&ADC1_Handler, DMA_Handle, ADC1DMA_Handler);
}
main中调用
HAL_ADC_Start_DMA(&ADC1_Handler, (uint32_t*)&AD_DMA, 2);
但AD_DMA中的数为0,不知道哪里出问题了,求大神帮忙看下 |
|
我也不知道为啥是黑色背景
我也不知道为啥是黑色背景
不好意思,不知道背景怎么是黑色,问题已解决,谢谢