大学生
最后登录1970-1-1
在线时间 小时
注册时间2018-3-13
|
void DAC1_Init(void)
{
DAC_ChannelConfTypeDef DACCH1_Config;
DAC1_Handler.Instance=DAC;
HAL_DAC_Init(&DAC1_Handler); //3õê¼»ˉDAC
DACCH1_Config.DAC_Trigger=DAC_TRIGGER_T4_TRGO; //2»ê1óÃ′¥·¢1|Äü
DACCH1_Config.DAC_OutputBuffer=DAC_OUTPUTBUFFER_DISABLE;//DAC1êä3ö»o3å1رÕ
HAL_DAC_ConfigChannel(&DAC1_Handler,&DACCH1_Config,DAC_CHANNEL_1);//DACí¨μà1ÅäÖÃ
HAL_DAC_Start_DMA(&DAC1_Handler,DAC_CHANNEL_1,(u32*)&DAC->DHR12R1,BUFFERSIZE,DAC_ALIGN_12B_R);
}
//DACμ×2ãÇy¶ˉ£¬ê±ÖóÅäÖã¬òy½Å ÅäÖÃ
//′Ëoˉêy»á±»HAL_DAC_Init()μ÷óÃ
//hdacAC¾ä±ú
void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac)
{
GPIO_InitTypeDef GPIO_Initure;
__HAL_RCC_DAC_CLK_ENABLE(); //ê1ÄüDACê±Öó
__HAL_RCC_GPIOA_CLK_ENABLE(); //¿aÆôGPIOAê±Öó
GPIO_Initure.Pin=GPIO_PIN_4; //PA4
GPIO_Initure.Mode=GPIO_MODE_ANALOG; //Ä£Äa
GPIO_Initure.Pull=GPIO_NOPULL; //2»′øéÏÏÂà-
HAL_GPIO_Init(GPIOA,&GPIO_Initure);
}
void MYDAC1DMA_Config(void)
{
__HAL_RCC_DMA1_CLK_ENABLE();//DMA2ê±Öóê1Äü
__HAL_LINKDMA(&DAC1_Handler,DMA_Handle1,DAC1DMA_Handler); //½«DMAóëUSART1áaÏμÆeà′(·¢ËíDMA)
//Tx DMAÅäÖÃ
DAC1DMA_Handler.Instance=DMA1_Stream5; //êy¾Yá÷Ñ¡Ôñ
DAC1DMA_Handler.Init.Channel=DMA_CHANNEL_7; //í¨μàÑ¡Ôñ
DAC1DMA_Handler.Init.Direction=DMA_MEMORY_TO_PERIPH; //′æ′¢Æ÷μ½íaéè
DAC1DMA_Handler.Init.PeriphInc=DMA_PINC_DISABLE; //íaéè·ÇÔöá¿Ä£ê½
DAC1DMA_Handler.Init.MemInc=DMA_MINC_ENABLE; //′æ′¢Æ÷Ôöá¿Ä£ê½
DAC1DMA_Handler.Init.PeriphDataAlignment=DMA_PDATAALIGN_HALFWORD; //íaéèêy¾Y3¤¶è:16λ
DAC1DMA_Handler.Init.MemDataAlignment=DMA_PDATAALIGN_HALFWORD; //′æ′¢Æ÷êy¾Y3¤¶è:16λ
DAC1DMA_Handler.Init.Mode=DMA_CIRCULAR; //Ñ-»·Ä£ê½
DAC1DMA_Handler.Init.Priority=DMA_PRIORITY_HIGH; //¸ßóÅÏ輶
DAC1DMA_Handler.Init.FIFOMode=DMA_FIFOMODE_DISABLE;
DAC1DMA_Handler.Init.FIFOThreshold=DMA_FIFO_THRESHOLD_HALFFULL;
DAC1DMA_Handler.Init.MemBurst=DMA_MBURST_SINGLE; //′æ′¢Æ÷í»·¢μ¥′Î′«êä
DAC1DMA_Handler.Init.PeriphBurst=DMA_PBURST_SINGLE; //íaéèí»·¢μ¥′Î′«êä
HAL_DMA_DeInit(&DAC1DMA_Handler);
HAL_DMA_Init(&DAC1DMA_Handler);
//********DMAË«»o3åéèÖÿaê¼********
__HAL_UNLOCK(&DAC1DMA_Handler);
HAL_DMAEx_MultiBufferStart(&DAC1DMA_Handler,(u32)&DAC->DHR12R1,(u32)buf2,(u32)buf3,BUFFERSIZE);//¿aÆôË«»o3å //10usÑóê±£¬·àÖ1-O2óÅ»ˉ3öÎêìa
__HAL_DMA_ENABLE_IT(&DAC1DMA_Handler,DMA_IT_TC); //¿aÆô′«êäíê3éÖD¶Ï
//********DMAË«»o3åéèÖýáêø********
HAL_NVIC_SetPriority(DMA1_Stream5_IRQn, 0, 1);
HAL_NVIC_EnableIRQ(DMA1_Stream5_IRQn);
}
如上图,寄存器S0CR始终为0,
配置的是DMA1和ADC1
|
|