PWM+DMA发送的占空比中混杂发占空比0的现象
stm32f4 PB5 TIM3 CH2 DMA1_Stream5 ch5
TIM_TimeBaseStructure.TIM_Prescaler= 1-1; //定时器分频
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up; //向上计数模式
TIM_TimeBaseStructure.TIM_Period= 105 - 1;
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseStructure);//初始化定时器3
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //选择定时器模式:TIM脉冲宽度调制模式2
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //比较输出使能
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; //输出极性:TIM输出比较极性低
TIM_OC2Init(TIM3, &TIM_OCInitStructure); //根据指定的参数初始化外设TIM2 OC3
TIM_ARRPreloadConfig(TIM3,ENABLE);//ARPE使能
TIM_OC2PreloadConfig(TIM3, TIM_OCPreload_Enable); //使能TIM2在CCR3上的预装载寄存器
DMA_DeInit(DMA1_Stream5);
DMA_InitStructure.DMA_Channel = DMA_Channel_5; //通道选择
DMA_InitStructure.DMA_PeripheralBaseAddr = ((uint32_t)(&(TIM3->CCR2)));//DMA外设地址
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)headPixelBuffer;//DMA 存储器0地址
DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;//存储器到外设模式
DMA_InitStructure.DMA_BufferSize = HEADPIXELNUM * GRBLen;//数据传输量
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;//外设非增量模式
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;//存储器增量模式
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;//外设数据宽度
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;//存储器数据宽度
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;// 使用模式 普通
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;//存储器突发单次传输
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;//外设突发单次传输
DMA_Init(DMA1_Stream5, &DMA_InitStructure);//初始化DMA Stream
发送函数
TIM_Cmd(TIM3, ENABLE);
DMA_SetCurrDataCounter(DMA1_Stream5, (uint16_t)(HEADPIXELNUM * GRBLen)); //DMA传输数据大小
TIM_DMACmd(TIM3, TIM_DMA_CC2, ENABLE);
DMA_Cmd(DMA1_Stream5, ENABLE);
while(!DMA_GetFlagStatus(DMA1_Stream5 ,DMA_FLAG_TCIF5));
DMA_Cmd(DMA1_Stream5, DISABLE);
DMA_ClearFlag(DMA1_Stream5, DMA_FLAG_TCIF5);
TIM_Cmd(TIM3, DISABLE);