各位大佬好
目前仿照網上參考代碼寫了一個adc+dma的代碼
可是程序陷在 HAL_ADC_Start_DMA(&adc_handler,ADC_Value_arr,2); 不出来,死在里边了。请大侠指点。
[mw_shl_code=c,true]#include "adc.h"
#include "delay.h"
ADC_HandleTypeDef adc_handler;
ADC_ChannelConfTypeDef channelConfig;
DMA_HandleTypeDef hdma_adc;
extern uint32_t ADC_Value_arr_buff[2];
uint32_t ADC_Value_arr[2];
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
{
GPIO_InitTypeDef GPIO_Initure;
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_ADC1_CLK_ENABLE();
GPIO_Initure.Pin=GPIO_PIN_4 | GPIO_PIN_6;
GPIO_Initure.Mode=GPIO_MODE_ANALOG;
GPIO_Initure.Pull=GPIO_NOPULL;
HAL_GPIO_Init(GPIOA,&GPIO_Initure);
__HAL_RCC_DMA2_CLK_ENABLE();
hdma_adc.Instance=DMA2_Stream0;
hdma_adc.Init.Channel=DMA_CHANNEL_0;
hdma_adc.Init.Direction=DMA_PERIPH_TO_MEMORY;
hdma_adc.Init.PeriphInc=DMA_PINC_DISABLE;
hdma_adc.Init.MemInc=DMA_MINC_ENABLE;
hdma_adc.Init.PeriphDataAlignment=DMA_PDATAALIGN_HALFWORD;
hdma_adc.Init.MemDataAlignment=DMA_MDATAALIGN_HALFWORD;
hdma_adc.Init.Mode=DMA_CIRCULAR;//DMA_NORMAL;
hdma_adc.Init.Priority=DMA_PRIORITY_HIGH;
hdma_adc.Init.FIFOMode=DMA_FIFOMODE_DISABLE;
hdma_adc.Init.FIFOThreshold=DMA_FIFO_THRESHOLD_HALFFULL;
hdma_adc.Init.MemBurst=DMA_MBURST_SINGLE;
hdma_adc.Init.PeriphBurst=DMA_PBURST_SINGLE;
HAL_DMA_DeInit(&hdma_adc);
HAL_DMA_Init(&hdma_adc);
__HAL_LINKDMA(hadc,DMA_Handle,hdma_adc);
//__HAL_DMA_ENABLE_IT(&hdma_adc,DMA_IT_TC) ;
HAL_NVIC_SetPriority(DMA2_Stream0_IRQn,1,0);
HAL_NVIC_EnableIRQ(DMA2_Stream0_IRQn);
}
void MY_ADC1_Init(void)
{
adc_handler.Instance = ADC1;
adc_handler.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
adc_handler.Init.ContinuousConvMode = ENABLE;
adc_handler.Init.DataAlign = ADC_DATAALIGN_RIGHT;
adc_handler.Init.DiscontinuousConvMode = DISABLE;
adc_handler.Init.DMAContinuousRequests = ENABLE;
adc_handler.Init.EOCSelection = DISABLE;
adc_handler.Init.ExternalTrigConv = ADC_SOFTWARE_START;
adc_handler.Init.NbrOfConversion = 2;
adc_handler.Init.NbrOfDiscConversion = 0;
adc_handler.Init.Resolution = ADC_RESOLUTION_12B;
adc_handler.Init.ScanConvMode = ENABLE;
HAL_ADC_Init(&adc_handler);
channelConfig.Channel=ADC_CHANNEL_4;
channelConfig.Rank=1;
channelConfig.SamplingTime=ADC_SAMPLETIME_56CYCLES;
channelConfig.Offset=0;
HAL_ADC_ConfigChannel(&adc_handler, & channelConfig);
channelConfig.Channel=ADC_CHANNEL_6;
channelConfig.Rank=2;
channelConfig.SamplingTime=ADC_SAMPLETIME_56CYCLES;
channelConfig.Offset=0;
HAL_ADC_ConfigChannel(&adc_handler, & channelConfig);
HAL_ADC_Start_DMA(&adc_handler,ADC_Value_arr,2);
}
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
{
static u8 i;
SCB_DisableDCache();
for(i=0;i<2;i++)
ADC_Value_arr_buff=ADC_Value_arr;
SCB_EnableDCache();
//HAL_ADC_Stop_DMA(&adc_handler);
}
void DMA2_Stream0_IRQHandler(void)
{
HAL_DMA_IRQHandler(&hdma_adc);
}[/mw_shl_code]
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>