我想用TIM1的Update DMA同时更新TIM1_CCR1和TIM1_CCR2寄存器,但只有TIM1_CCR1被更新,而TIM1_CCR2的值不变,请香主帮忙说明如何才能实现同时更新
CCR1和CCR2,谢谢!
设置如下:
#define TIM1_CCR1_Address 0x40012C34
#define Max_Samples 30 //定义最大数组值
uint32_t Sin_Table[Max_Samples];
void DMA_Configuration(void)
{
DMA_InitTypeDef DMA_InitStructure;
/* DMA1 Channel5 Config */
DMA_DeInit(DMA1_Channel5);
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)TIM1_CCR1_Address;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&Sin_Table[0];// SRC1_Buffer;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
DMA_InitStructure.DMA_BufferSize =30;
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_Circular;
DMA_InitStructure.DMA_Priority =DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel5, &DMA_InitStructure);
DMA_Cmd(DMA1_Channel5, ENABLE);
}
int main(void)
{
int i;
unsigned int dwVal;
for( i=0;i<30;i++)
{
dwVal = i*10;
Sin_Table[i]= ((dwVal<<16)|(600-dwVal));
}
RCC_Configuration();
GPIO_Configuration();
DMA_Configuration();
TIM_TimeBaseStructure.TIM_Prescaler =0;
TIM_TimeBaseStructure.TIM_CounterMode =TIM_CounterMode_CenterAligned2;
TIM_TimeBaseStructure.TIM_Period = 600;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_RepetitionCounter =1;// 0;
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OutputNState =TIM_OutputNState_Enable;
TIM_OCInitStructure.TIM_Pulse = (unsigned short)(Sin_Table[0]);
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset;
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Reset;
TIM_OC1Init(TIM1, &TIM_OCInitStructure);
TIM_OCInitStructure.TIM_Pulse = (unsigned short)(Sin_Table[0]>>16);
TIM_OC2Init(TIM1, &TIM_OCInitStructure);
//设置 Burst 模式,分别传输一个HalfWord给TIM1_CCR1和TIM1_CCR2
TIM_DMAConfig(TIM1, TIM_DMABase_CCR1, TIM_DMABurstLength_2Bytes );
TIM_DMACmd(TIM1, TIM_DMA_Update, ENABLE);
TIM_OC1FastConfig(TIM1, TIM_OCFast_Enable );
TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Enable);
TIM_OC2FastConfig(TIM1, TIM_OCFast_Enable );
TIM_OC2PreloadConfig(TIM1, TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM1, ENABLE);//ARR预装载缓冲器
TIM_Cmd(TIM1, ENABLE);
TIM_CtrlPWMOutputs(TIM1, ENABLE);
while (1) ;
} |