用DMA输出DAC1,当输出数据定义成const uint16_t aEscalator8bit[2],DAC输出正常,定义成 uint16_t aEscalator8bit[2];DAC就没有输出。
测试官方的例程也是一样。不知哪里出了问题?初始化程序如下。
uint16_t aEscalator8bit[2] = {4000, 0};
DAC_HandleTypeDef DacHandle;
DAC_ChannelConfTypeDef sConfig;
void DAC_Config()
{
__HAL_RCC_DAC12_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_DMA1_CLK_ENABLE();
TIM6_Config(i);
DacHandle.Instance = DAC1;
HAL_DAC_DeInit(&DacHandle);
HAL_DAC_Init(&DacHandle);
sConfig.DAC_Trigger = DAC_TRIGGER_T6_TRGO;
sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
HAL_DAC_ConfigChannel(&DacHandle, &sConfig, DAC_CHANNEL_1);
HAL_DAC_Start_DMA(&DacHandle, DAC_CHANNEL_1, (uint32_t *)aEscalator8bit, 2, DAC_ALIGN_12B_R);
}
void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac)
{
DMA_HandleTypeDef hdma_dac1_ch1;
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(hdac->Instance==DAC1)
{
/* USER CODE BEGIN DAC1_MspInit 0 */
/* USER CODE END DAC1_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_DAC12_CLK_ENABLE();
__HAL_RCC_DMA1_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
/**DAC1 GPIO Configuration
PA4 ------> DAC1_OUT1
PA5 ------> DAC1_OUT2
*/
GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* DAC1 DMA Init */
/* DAC1_CH1 Init */
hdma_dac1_ch1.Instance = DMA1_Stream5;
hdma_dac1_ch1.Init.Request = DMA_REQUEST_DAC1;
hdma_dac1_ch1.Init.Direction = DMA_MEMORY_TO_PERIPH;
hdma_dac1_ch1.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_dac1_ch1.Init.MemInc = DMA_MINC_ENABLE;
hdma_dac1_ch1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
hdma_dac1_ch1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
hdma_dac1_ch1.Init.Mode = DMA_CIRCULAR;
hdma_dac1_ch1.Init.Priority = DMA_PRIORITY_HIGH;
HAL_DMA_Init(&hdma_dac1_ch1);
__HAL_LINKDMA(hdac,DMA_Handle1,hdma_dac1_ch1);
}
} |