最近用hal库写了ADC和DMA使用的程序,但是调用 HAL_DMA_Init(&ADC1TxDMA_Handler);这个函数就出现问题了,死机,芯片是STM32F4xx的,原子哥能帮看看配置出什么问题了吗?
#include "adc.h"
#include "main.h"
ADC_HandleTypeDef ADC1_Handler; //ADC¾ä±ú
DMA_HandleTypeDef ADC1TxDMA_Handler; //DMA¾ä±ú
//ch: ADC_channels
//ͨµÀÖµ 0~16È¡Öµ·¶Î§Îª£ºADC_CHANNEL_0~ADC_CHANNEL_16
void MY_ADC_Init(void)
{
ADC1_Handler.Instance=ADC1;
ADC1_Handler.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4; //4·ÖƵ ADCʱÖÓΪ25M
ADC1_Handler.Init.Resolution = ADC_RESOLUTION_12B; //12λģʽ
ADC1_Handler.Init.DataAlign = ADC_DATAALIGN_RIGHT; //ÓÒ¶ÔÆë
ADC1_Handler.Init.ScanConvMode = DISABLE; //·ÇɨÃèģʽ
ADC1_Handler.Init.EOCSelection = DISABLE; //¹Ø±ÕEOCÖжÏ
ADC1_Handler.Init.ContinuousConvMode = ENABLE; //¹Ø±ÕÁ¬Ðøת»»
ADC1_Handler.Init.NbrOfConversion = 1; //1¸öת»»ÔÚ¹æÔòÐòÁÐÖÐ Ò²¾ÍÊÇֻת»»¹æÔòÐòÁÐ1
ADC1_Handler.Init.DiscontinuousConvMode = DISABLE; //½ûÖ¹²»Á¬Ðø²ÉÑùģʽ
ADC1_Handler.Init.NbrOfDiscConversion = 0; //²»Á¬Ðø²ÉÑùͨµÀÊýΪ0
ADC1_Handler.Init.ExternalTrigConv = ADC_SOFTWARE_START; //Èí¼þ´¥·¢
ADC1_Handler.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;//ÎÞÍⲿ´¥·¢×ª»»
ADC1_Handler.Init.DMAContinuousRequests = ENABLE; //¹Ø±ÕDMAÇëÇó
ADC1_Handler.Init.EOCSelection = DISABLE;
HAL_ADC_Init(&ADC1_Handler); //³õʼ»¯
}
//ADCµ×²ãÇý¶¯£¬Òý½ÅÅäÖã¬Ê±ÖÓʹÄÜ
//´Ëº¯Êý»á±»HAL_ADC_Init()µ÷ÓÃ
//hadc:ADC¾ä±ú
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
{
GPIO_InitTypeDef GPIO_Initure;
__HAL_RCC_ADC1_CLK_ENABLE(); //ʹÄÜADC1ʱÖÓ
__HAL_RCC_GPIOC_CLK_ENABLE(); //¿ªÆôGPIOCʱÖÓ
GPIO_Initure.Pin = GPIO_PIN_0; //PC0
GPIO_Initure.Mode = GPIO_MODE_ANALOG; //Ä£Äâ
GPIO_Initure.Pull = GPIO_NOPULL; //²»´øÉÏÏÂÀ­
HAL_GPIO_Init(GPIOC,&GPIO_Initure);
}
void MY_DMA_Config(void)
{
__HAL_RCC_DMA2_CLK_ENABLE(); //DMA2ʱÖÓʹÄÜ
__HAL_LINKDMA(&ADC1_Handler,DMA_Handle,ADC1TxDMA_Handler); //½«DMAÓëADC1ÁªÏµÆðÀ´(·¢ËÍDMA)
ADC1TxDMA_Handler.Instance = DMA2_Stream0; //Êý¾ÝÁ÷Ñ¡Ôñ
ADC1TxDMA_Handler.Init.Channel = DMA_CHANNEL_0; //ͨµÀÑ¡Ôñ
ADC1TxDMA_Handler.Init.Direction = DMA_PERIPH_TO_MEMORY; //ÍâÉèµ½´¢´æÆ÷
ADC1TxDMA_Handler.Init.PeriphInc = DMA_PINC_DISABLE; //ÍâÉè·ÇÔöÁ¿Ä£Ê½
ADC1TxDMA_Handler.Init.MemInc = DMA_MINC_DISABLE; //´æ´¢Æ÷ÔöÁ¿Ä£Ê½
ADC1TxDMA_Handler.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; //ÍâÉèÊý¾Ý³¤¶È:16λ
ADC1TxDMA_Handler.Init.MemDataAlignment = DMA_PDATAALIGN_HALFWORD; //´æ´¢Æ÷Êý¾Ý³¤¶È:16λ
ADC1TxDMA_Handler.Init.Mode = DMA_CIRCULAR; //Ñ­»·Ä£Ê½
ADC1TxDMA_Handler.Init.Priority = DMA_PRIORITY_MEDIUM; //¸ßÓÅÏȼ¶
ADC1TxDMA_Handler.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
ADC1TxDMA_Handler.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_HALFFULL;
ADC1TxDMA_Handler.Init.MemBurst = DMA_MBURST_SINGLE; //´æ´¢Æ÷Í»·¢µ¥´Î´«Êä
ADC1TxDMA_Handler.Init.PeriphBurst = DMA_PBURST_SINGLE; //ÍâÉèÍ»·¢µ¥´Î´«
// HAL_DMA_DeInit(&ADC1TxDMA_Handler);
HAL_DMA_Init(&ADC1TxDMA_Handler);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
我说的是传输个数
一周热门 更多>