实验平台:Nucleo-STM32G474RE开发板 验证功能:希望利用DMA把数据传到DAC3的DAC_DHR12R1寄存器产生波形,再通过运放的跟随输出到外部管脚 问题描述:DMA没有更新DAC3的DHR12R1寄存器数据,进而无波形产生 DAC3配置: static void MX_DAC3_Init(void) { /* USER CODE BEGIN DAC3_Init 0 */ /* USER CODE END DAC3_Init 0 */ DAC_ChannelConfTypeDef sConfig = {0}; /* USER CODE BEGIN DAC3_Init 1 */ /* USER CODE END DAC3_Init 1 */ /** DAC Initialization */ hdac3.Instance = DAC3; if (HAL_DAC_Init(&hdac3) != HAL_OK) { Error_Handler(); } /** DAC channel OUT1 config */ sConfig.DAC_HighFrequency = DAC_HIGH_FREQUENCY_INTERFACE_MODE_AUTOMATIC; sConfig.DAC_DMADoubleDataMode = DISABLE; sConfig.DAC_SignedFormat = DISABLE; sConfig.DAC_SampleAndHold = DAC_SAMPLEANDHOLD_DISABLE; sConfig.DAC_Trigger = DAC_TRIGGER_T2_TRGO; sConfig.DAC_Trigger2 = DAC_TRIGGER_NONE; sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_DISABLE; sConfig.DAC_ConnectOnChipPeripheral = DAC_CHIPCONNECT_ENABLE; sConfig.DAC_UserTrimming = DAC_TRIMMING_FACTORY; if (HAL_DAC_ConfigChannel(&hdac3, &sConfig, DAC_CHANNEL_1) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN DAC3_Init 2 */ /* USER CODE END DAC3_Init 2 */ } OPAMP1配置 static void MX_OPAMP1_Init(void) { /* USER CODE BEGIN OPAMP1_Init 0 */ /* USER CODE END OPAMP1_Init 0 */ /* USER CODE BEGIN OPAMP1_Init 1 */ /* USER CODE END OPAMP1_Init 1 */ hopamp1.Instance = OPAMP1; hopamp1.Init.PowerMode = OPAMP_POWERMODE_NORMAL; hopamp1.Init.Mode = OPAMP_FOLLOWER_MODE; hopamp1.Init.NonInvertingInput = OPAMP_NONINVERTINGINPUT_DAC; hopamp1.Init.InternalOutput = DISABLE; hopamp1.Init.TimerControlledMuxmode = OPAMP_TIMERCONTROLLEDMUXMODE_DISABLE; hopamp1.Init.UserTrimming = OPAMP_TRIMMING_FACTORY; if (HAL_OPAMP_Init(&hopamp1) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN OPAMP1_Init 2 */ /* USER CODE END OPAMP1_Init 2 */ } TIMER2配置: static void MX_TIM2_Init(void) { /* USER CODE BEGIN TIM2_Init 0 */ /* USER CODE END TIM2_Init 0 */ TIM_ClockConfigTypeDef sClockSourceConfig = {0}; TIM_MasterConfigTypeDef sMasterConfig = {0}; /* USER CODE BEGIN TIM2_Init 1 */ /* USER CODE END TIM2_Init 1 */ htim2.Instance = TIM2; htim2.Init.Prescaler = 0; htim2.Init.CounterMode = TIM_COUNTERMODE_UP; htim2.Init.Period = 169; htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; if (HAL_TIM_Base_Init(&htim2) != HAL_OK) { Error_Handler(); } sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK) { Error_Handler(); } sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE; sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN TIM2_Init 2 */ /* USER CODE END TIM2_Init 2 */ } DMA配置: static void MX_DMA_Init(void) { /* DMA controller clock enable */ __HAL_RCC_DMAMUX1_CLK_ENABLE(); __HAL_RCC_DMA1_CLK_ENABLE(); /* DMA interrupt init */ /* DMA1_Channel1_IRQn interrupt configuration */ HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 0, 0); HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn); } 主程序: /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_DMA_Init(); MX_DAC3_Init(); MX_OPAMP1_Init(); MX_TIM2_Init(); /* USER CODE BEGIN 2 */ for (i=0;i<NUM;i++) { sinetable[i]=(uint16_t)((pow(2,12)-1)*(sin((double)i/NUM*2*Pi))); } HAL_OPAMP_Start(&hopamp1); HAL_TIM_Base_Start(&htim2); HAL_DAC_Start_DMA(&hdac3,DAC_CHANNEL_1,(uint32_t *)sinetable,NUM,DAC_ALIGN_12B_R); 问题:无波形产生,但是用软件设定值的话,可以观察到输出电压有反应,可以定位于DAC的DMA模式不工作,进而调试发现初始化的时候DMA1的EN可以使能,接着程序跑起来后EN一直就为0,如果强制把EN置1,则过后软件马上把EN清0,同时DMA的ISR寄存器中的TEIF1和GIF1被置1,说明有传输错误。请问是DMA哪里配置有问题,忽视了什么吗?谢谢 |
《MCSDK5.X中增加位置环》提及mc_position.c/mc_position.h
STM32G473 DRDY不置位?
stspin32G4这颗mcu里面集成的是哪一款G4?能不能用cubemx来进行配置
STM32G473是否支持硬件AES?
STM32G473VET6同时使用6个片上放大器(OPAMP)的PGA加外部偏置模式,引脚位置让差分信号走线分离,信号有无较大影响?
stm32G474的flash模式如何判定?single bank 和dual bank
STM32G474 ADC无法正常启动转换
STM32G474 HRTIM无法正常触发ADC
STM32G431RB,变量接受不到串口发下去的数据
foc电流环无法正确维持Iq在自己设定的数值。
这句改成 DAC_OUTPUTBUFFER_ENABLE 试试
评分
查看全部评分
谢谢您的回复,可能您不熟悉STM32G4的芯片,DAC3输出不能达到管脚,只有内部连接,如果要输出来,只能从内部接到运放的非反相端,按照跟随器的方式输出,所以这里只能这样的配置