11-STM32F7 的AD轉換和DMA傳輸
阿新 • • 發佈:2018-12-10
#include "adc.h" #include "stdio.h" #include "dma.h" #include "stm32f7xx_hal.h" #include "stm32f7xx_hal_adc.h" ADC_HandleTypeDef adc1; ADC_ChannelConfTypeDef chan1; void Adc_Config(void){ HAL_ADC_MspInit(&adc1); GPIO_InitTypeDef GPIO_InitStruct; __HAL_RCC_SYSCFG_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); GPIO_InitStruct.Pin = GPIO_PIN_2; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); //GPIO Config __HAL_RCC_ADC1_CLK_ENABLE(); adc1.Instance=ADC1; adc1.Init.ClockPrescaler=ADC_CLOCK_SYNC_PCLK_DIV4; adc1.Init.Resolution=ADC_RESOLUTION_12B; adc1.Init.ScanConvMode=ADC_SCAN_DISABLE; adc1.Init.DMAContinuousRequests=ENABLE; adc1.Init.ExternalTrigConv=ADC_SOFTWARE_START; adc1.Init.ExternalTrigConvEdge=ADC_SOFTWARE_START; adc1.Init.DataAlign=ADC_DATAALIGN_LEFT; adc1.Init.EOCSelection=ADC_EOC_SEQ_CONV; adc1.Init.EOCSelection=ADC_EOC_SINGLE_CONV; chan1.Channel=ADC_CHANNEL_5; chan1.Rank=ADC_REGULAR_RANK_1; chan1.SamplingTime=ADC_SAMPLETIME_144CYCLES; chan1.Offset=0; HAL_ADC_ConfigChannel(&adc1,&chan1); HAL_ADC_Init(&adc1); // HAL_ADC_Start_IT(&adc1); // HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_1); // HAL_NVIC_SetPriority(ADC_IRQn,1,1); // HAL_NVIC_EnableIRQ(ADC_IRQn); HAL_ADC_Start_DMA(&adc1,pdata,12800); }
#include "dma.h" #include "adc.h" #include "stm32f7xx_hal_dma.h" #include "stm32f7xx_hal.h" #include "stm32f7xx_hal_adc.h" DMA_HandleTypeDef mydma2; void Dma_Config(void){ HAL_DMA_DeInit(&mydma2); __HAL_RCC_DMA2_CLK_ENABLE(); mydma2.Instance=DMA1_Stream0; mydma2.Init.Channel=DMA_CHANNEL_0; mydma2.Init.Direction=DMA_PERIPH_TO_MEMORY; mydma2.Init.PeriphInc=DMA_PINC_DISABLE; mydma2.Init.MemInc=DMA_MINC_ENABLE; mydma2.Init.MemDataAlignment= DMA_PDATAALIGN_WORD; mydma2.Init.PeriphDataAlignment=DMA_PDATAALIGN_WORD; mydma2.Init.Mode=DMA_CIRCULAR; mydma2.Init.Priority=DMA_PRIORITY_HIGH; mydma2.Init.FIFOMode=DMA_FIFOMODE_DISABLE; mydma2.Init.PeriphBurst=DMA_PBURST_SINGLE; HAL_DMA_Init(&mydma2); HAL_DMA_Start(&mydma2,ADC_CHANNEL_5,DMA_CHANNEL_0,1200); }