本人用STM32F334实现了DAC采用DMA方式输出正弦波,用定时器控制频率。后来我用STM32H750芯片尝试,发现DAC和定时器都是正常工作,DMA输出不了数据,看了好多遍H750的手册,DMA的配置以我现有的水平看不出有任何问题。想请各位前辈来看看我这出了什么问题。 正弦信号输出程序: void sin_Generation(void) { uint16_t n; for(n=0;n<tableSize;n++) { sinTable[n] = (sin(2*PI*n/tableSize)+1)*2047; } } 主函数部分: int main(void) { HAL_Init(); SystemClock_Config(); sin_Generation(); MX_GPIO_Init(); MX_DMA_Init(); MX_DAC1_Init(); MX_TIM6_Init(); HAL_DAC_Start_DMA(&hdac1,DAC_CHANNEL_1,sinTable,tableSize,DAC_ALIGN_12B_R); while (1) { } } DAC的初始化函数: static void MX_DAC1_Init(void) { DAC_ChannelConfTypeDef sConfig = {0}; hdac1.Instance = DAC1; if (HAL_DAC_Init(&hdac1) != HAL_OK) { Error_Handler(); } sConfig.DAC_SampleAndHold = DAC_SAMPLEANDHOLD_DISABLE; sConfig.DAC_Trigger = DAC_TRIGGER_T6_TRGO; sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE; sConfig.DAC_ConnectOnChipPeripheral = DAC_CHIPCONNECT_DISABLE; sConfig.DAC_UserTrimming = DAC_TRIMMING_FACTORY; if (HAL_DAC_ConfigChannel(&hdac1, &sConfig, DAC_CHANNEL_1) != HAL_OK) { Error_Handler(); } } 定时器6的初始化: static void MX_TIM6_Init(void) { TIM_MasterConfigTypeDef sMasterConfig = {0}; htim6.Instance = TIM6; htim6.Init.Prescaler = 2; htim6.Init.CounterMode = TIM_COUNTERMODE_UP; htim6.Init.Period = 99; htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; if (HAL_TIM_Base_Init(&htim6) != HAL_OK) { Error_Handler(); } sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE; sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; if (HAL_TIMEx_MasterConfigSynchronization(&htim6, &sMasterConfig) != HAL_OK) { Error_Handler(); } HAL_TIM_Base_Start(&htim6); } DMA的时钟开启: static void MX_DMA_Init(void) { __HAL_RCC_DMA1_CLK_ENABLE(); HAL_NVIC_SetPriority(DMA1_Stream0_IRQn, 0, 0); HAL_NVIC_EnableIRQ(DMA1_Stream0_IRQn); HAL_NVIC_SetPriority(DMAMUX1_OVR_IRQn, 0, 0); HAL_NVIC_EnableIRQ(DMAMUX1_OVR_IRQn); } 到此main.c文件结束,DMA的配置和DAC的IO口配置在msp.c文件中 void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac) { GPIO_InitTypeDef GPIO_InitStruct = {0}; if(hdac->Instance==DAC1) { __HAL_RCC_DAC12_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); //PA4 ------> DAC1_OUT1 GPIO_InitStruct.Pin = GPIO_PIN_4; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); hdma_dac1_ch1.Instance = DMA1_Stream1; 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_WORD; hdma_dac1_ch1.Init.MemDataAlignment = DMA_MDATAALIGN_WORD; hdma_dac1_ch1.Init.Mode = DMA_CIRCULAR; hdma_dac1_ch1.Init.Priority = DMA_PRIORITY_MEDIUM; hdma_dac1_ch1.Init.FIFOMode = DMA_FIFOMODE_DISABLE; if (HAL_DMA_Init(&hdma_dac1_ch1) != HAL_OK) { Error_Handler(); } __HAL_LINKDMA(hdac,DMA_Handle1,hdma_dac1_ch1); } } 相关代码已经附上,求教DMA为何不通。 |
STM32H750内部flash读写
STM32H743采用flash swap 进行IAP升级,reset后启动不了
STM32双核H7核间通信的方法
STM32H743IIC,HAL库驱动硬件I2C,hi2c2.state一直是busy. 为什么?
H747 DSI 模块的官方例程跑不通
MAC回环或以太网PHY芯片回环怎么实现?
STM32745/747芯片固件升级问题
H743 DAC通道缓冲器的校准问题
STM32H750更改时钟后,程序无法运行
疑似STM32CUBEIDE出现BUG
hdma_dac1_ch1.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
改成半字试试
我都试过了,后来发现是DMA数据流的使能位没有置1,这个位我怎么都置不了1,我直接配置寄存器的位都不行,不知道出什么问题了。
DMA2_Stream7->CR|=1<<0;
这两句话都不能将EN位使能置一,有没有人遇到过这种情况?
兄弟,你回复帖子用等待审核吗
STM32H750 RAM起始地址0x20000000无法被DMA访问,把RAM2 0x24000000打勾即可