完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
【基本情况】CPU:STM32F207IG 利用tiM5的CH2通道产生PWM波,开启DMA,利用TIM5更新事件请求DMA搬运。搬运数组数值到TIM5->ARR寄存器。 目前进不去DMA中断,不知道是哪里配置的问题……
【函数如下】 void TIM5_PWM_Configeration(void) { TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct; TIM_OCInitTypeDef TIM_OCInitStructure; GPIO_InitTypeDef GPIO_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOH,ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ; GPIO_Init(GPIOH, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOH,GPIO_PinSource11,GPIO_AF_TIM5); TIM_DeInit(TIM5); RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5,ENABLE); TIM_TimeBaseInitStruct.TIM_Period =1499; TIM_TimeBaseInitStruct.TIM_Prescaler =CPU_FREQUENCE/F2TIME_PARA-1; TIM_TimeBaseInitStruct.TIM_ClockDivision =TIM_CKD_DIV1; TIM_TimeBaseInitStruct.TIM_CounterMode =TIM_CounterMode_Up; TIM_TimeBaseInitStruct.TIM_RepetitionCounter = 0x0; TIM_TimeBaseInit(TIM5, &TIM_TimeBaseInitStruct); TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = 749; TIM_OC2Init(TIM5, & TIM_OCInitStructure); TIM_OC2PreloadConfig(TIM5, TIM_OCPreload_Enable); Initial_DMA(); TIM_DMACmd(TIM5, TIM_DMA_Update, ENABLE); TIM_ARRPreloadConfig(TIM5,ENABLE); TIM_CtrlPWMOutputs(TIM5,ENABLE); TIM_Cmd(TIM5,ENABLE); } void Initial_DMA(void) { NVIC_InitTypeDef NVIC_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1,ENABLE); DMA_DeInit(DMA1_Stream4); DMA_StructInit(&DMA_InitStructure_M2); DMA_InitStructure_M2.DMA_Channel = DMA_Channel_6; DMA_InitStructure_M2.DMA_PeripheralBaseAddr = (uint32_t)TIM5_ARR_ADDRESS; // 0x40000C2C DMA_InitStructure_M2.DMA_Memory0BaseAddr = (uint32_t)0; DMA_InitStructure_M2.DMA_DIR = DMA_DIR_MemoryToPeripheral; DMA_InitStructure_M2.DMA_BufferSize = 10; DMA_InitStructure_M2.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure_M2.DMA_MemoryInc = DMA_MemoryInc_Disable; DMA_InitStructure_M2.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; DMA_InitStructure_M2.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; DMA_InitStructure_M2.DMA_Mode = DMA_Mode_Circular; DMA_InitStructure_M2.DMA_Priority = DMA_Priority_High; DMA_InitStructure_M2.DMA_FIFOMode = DMA_FIFOMode_Disable; DMA_InitStructure_M2.DMA_FIFOThreshold = DMA_FIFOThreshold_Full; DMA_InitStructure_M2.DMA_MemoryBurst = DMA_MemoryBurst_Single; DMA_InitStructure_M2.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; DMA_Init(DMA1_Stream4, &DMA_InitStructure_M2); DMA_ClearFlag(DMA1_Stream4,DMA_FLAG_TCIF4); DMA_ITConfig(DMA1_Stream4,DMA_IT_TC,ENABLE); DMA_Cmd(DMA1_Stream4, DISABLE); NVIC_InitStructure.NVIC_IRQChannel = DMA1_Stream4_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =PWM2_PreemptionPriority; NVIC_InitStructure.NVIC_IRQChannelSubPriority = PWM2_SubPriority; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } 补充一下,DMA配置函数中 DMA_InitStructure_M2.DMA_Memory0BaseAddr = (uint32_t)0; 并未赋值,在程序启动后进行了如下设置: DMA_Cmd(DMA1_Stream4, DISABLE); DMA_InitStructure_M2.DMA_Memory0BaseAddr = (uint32_t)addr; //搬运的是定时器需要配置的PWM频率数值 DMA_InitStructure_M2.DMA_BufferSize = len; //希望DMA在搬运len长度数据以后进入DMA中断 DMA_Init(DMA1_Stream4, &DMA_InitStructure_M2); DMA_Cmd(DMA1_Stream4, ENABLE); |
|
相关推荐
13个回答
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
感觉F2与F4还有点类似的。
|
|
|
|
长知识了
|
|
|
|
更新:DMA_PeripheralDataSize_HalfWord改为DMA_PeripheralDataSize_Word
DMA_MemoryDataSize_HalfWord改为DMA_MemoryDataSize_Word 同时内存数组也用32bit的来传。 |
|
|
|
更新:PWM出来了,不要更新TIM5->ARR就行。其他一些问题跟这个配置无关,就不贴了。至于配置应该是没有问题了,可以结贴了。网友后面有玩的可以参考一下这个代码,我就留在这里了。
|
|
|
|
额,谢谢楼上两位捧场了,虽然没有解决问题。
更新:咨询了技术支持后,更新时间触发DMA通道有专属的通道,我原先选择的通道是TIM5_CH2的事件通道。 新问题:PWM没了。待续…… |
|
|
|
|
|
|
|
长知识了,谢谢分享!
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
690 浏览 0 评论
735 浏览 1 评论
基于瑞萨FPB-RA4E2智能床头灯项目——1编译环境搭建与点亮驱动ws2812全彩LED
624 浏览 0 评论
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-LCD显示图片编程示例之介绍mmap
1099 浏览 0 评论
《DNESP32S3使用指南-IDF版_V1.6》第二章 常用的C语言知识点
1092 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
11793 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-26 02:44 , Processed in 0.714701 second(s), Total 68, Slave 62 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号