- 我利用基本定时器6的更新事件触发DMA,然后从内存到外设更新tim6->ARR。问题是DMA没有搬运数据到ARR中。现在的情况是tim6正常产生了更新中断,并且ARR也能手动更新,但是DMA不起作用。
- 实在想不明白,新人第一次发帖,希望各位大佬求助。
- uint16_t fbuff;
- void DMA_CONFIG(vioid)
- {
- TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
- NVIC_IniitTypeDef NVIC_InitStructure;
- DMA_InitTYpeDef DMA_InitStruct;
- uint32_t padr = (uint32_t)&TIM6->ARR;
- uint32_t madr = (uint32_t)&fbuff;
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6,ENABLE);
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1,ENABLE);
- TIM_TimeBaseStructure.TIM_Period = 10-1;
- TIM_TimeBaseStructure.TIM_Prescaler = 8400 -1;
- TIM_TimeBaseStructure.TIM_ClockDivision = 0;
- TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
- TIM_TimeBaseInit(TIM6,&TIM_TimeBaseStructure);
- TIM_DMACmd(TIM6,TIM_DMA_Update,ENABLE);
- TIM_ITConfig(TIM6,TIM_IT_Update,ENABLE);//打开更新DMA请求
- NVIC_InitStructure.NVIC_IRQChannel = TIM6_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 8;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- DMA_DeInit(DMA1_Stream1);
- DMA_Cmd(DMA1_Stream1,DISABLE);
- DMA_InitStruct.DMA_Channel = 7;
- DMA_InitStruct.DMA_PeripheralBaseAddr = padr;
- DMA_InitStruct.DMA_Memory0BaseAddr = madr;
- DMA_InitStruct.DMA_DIR = DMA_DIR_MemoryToPeripherl;
- DMA_InitStruct.DMA_BufferSize = 1;
- DMA_InitStruct.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
- DMA_InitStruct.DMA_MemoryInc = DMA_MemoryInc_Disable;
- DMA_InitStruct.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
- DMA_InitStruct.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
- DMA_InitStruct.DMA_Mode = DMA_Mode_Normal;
- DMA_InitStruct.DMA_Priority = DMA_Priority_VeryHigh;
- DMA_InitStruct.DMA_FIFOMode = DMA_FIFOMode_Disable;
- DMA_InitStruct.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
- DMA_InitStruct.DMA_MemoryBurst =DMA_MemoryBurst_Single;
- DMA_InitStruct.DMA_PeripheralBurst =DMA_PeripheralBurst_Single;
- DMA_Init(DMA1_Stream1,&DMA_InitStruct);
- TIM_Cmd(TIM6,ENABLE);
- }
- void TIME6_IRQHandler(void)
- {
- if(TIM_GetITStatus(TIM6,TIM_IT_Update) !=RESET)
- TIM_ClearITPendingBit(TIM6,TIM_IT_Update);
- }
- void main(void)
- {
- u16 input;
- DMA_CONFIG();
- while(1)
- {
- fbuff = 10 + input; //input为外部可控输入
- if(Key_Scan(0) == 1)
- {
- DMA1_Stream1->CR &= 0xFFFFFFFE;
- DMA1_Stream1->NDTR = 1;
- DMA1_Stream1->CR |=0x00000001;//进行一次DMA传输
- }
- }
- }
[color=rgb(51, 102, 153) !important]复制代码
[color=rgb(51, 102, 153) !important]
|