我是这样设置的。
__IO uint8_t PHOTO_BUFF[ROW][COLUMN]; //图像原始数据
DMA_InitTypeDef DMA_InitStruct;
TIM_ICInitTypeDef TIM_ICInitStruct;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStruct;
void DMA_Config()
{
DMA_DeInit(DMA1_Channel6);
DMA_InitStruct.DMA_PeripheralBaseAddr = (uint32_t)&GPIOD->IDR; //该参数用以定义DMA外设基地址
DMA_InitStruct.DMA_MemoryBaseAddr = (uint32_t) PHOTO_BUFF; //该参数用以定义DMA内存基地址
DMA_InitStruct.DMA_DIR = DMA_DIR_PeripheralSRC; //规定了外设是作为数据传输的目的地还是来源
DMA_InitStruct.DMA_BufferSize = 100; //用以定义指定DMA通道的DMA缓存的大小,单位为数据单位
DMA_InitStruct.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //用来设定外设地址寄存器递增与否
DMA_InitStruct.DMA_MemoryInc =DMA_MemoryInc_Disable;// DMA_MemoryInc_Enable;//用来设定内存地址寄存器递增与否
DMA_InitStruct.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; //设定了外设数据宽度
DMA_InitStruct.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; //设定了内存数据宽度
DMA_InitStruct.DMA_Mode = DMA_Mode_Circular; //设置了CAN的工作模式
DMA_InitStruct.DMA_Priority = DMA_Priority_VeryHigh; //设定DMA通道x的软件优先级
DMA_InitStruct.DMA_M2M = DMA_M2M_Disable; //使能DMA通道的内存到内存传输
DMA_Init(DMA1_Channel6, &DMA_InitStruct);
DMA_ITConfig(DMA1_Channel6,DMA_IT_TC,ENABLE);
DMA_Cmd(DMA1_Channel6, ENABLE);
}
/* TIM3 Configuration ------------------------------------------------------*/
/* TIM3CLK = 72 MHz, Prescaler = 0, TIM3 counter clock = 72 MHz */
/* Time base configuration */
void Timer3_Init() //PC6
{ TIM_TimeBaseStruct.TIM_Period =255; //设置了在下一个更新事件装入活动的自动重装载寄存器周期的值
TIM_TimeBaseStruct.TIM_Prescaler = 0; //设置了用来作为TIMx时钟频率除数的预分频值
TIM_TimeBaseStruct.TIM_ClockDivision = 0; //设置了时钟分割
TIM_TimeBaseStruct.TIM_CounterMode = TIM_CounterMode_Up; //选择了计数器模式
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStruct);
/* Input Capture Mode configuration: Channel1 */ //选择了TIM输入捕获模式
TIM_ICInitStruct.TIM_Channel = TIM_Channel_1; //选择通道
TIM_ICInitStruct.TIM_ICPolarity = TIM_ICPolarity_Rising; //输入活动沿
TIM_ICInitStruct.TIM_ICSelection = TIM_ICSelection_DirectTI; //选择输入
TIM_ICInitStruct.TIM_ICPrescaler = TIM_ICPSC_DIV1; //设置输入捕获预分频器
TIM_ICInitStruct.TIM_ICFilter = 0; //选择输入比较滤波器
TIM_ICInit(TIM3, &TIM_ICInitStruct);
//TIM_ETRConfig(TIM3,TIM_ExtTRGPSC_OFF, TIM_ExtTRGPolarity_Inverted,0);
TIM_TIxExternalClockConfig(TIM3,TIM_TIxExternalCLK1Source_TI2, TIM_ICPolarity_Rising,0); //选择触发为外部时钟
TIM_ETRClockMode2Config(TIM3,TIM_ExtTRGPSC_OFF, TIM_ExtTRGPolarity_NonInverted, 0); //外部时钟配置2
/* Enable TIM3 DMA */
TIM_DMACmd(TIM3, TIM_DMA_Trigger, ENABLE);
/* Enable TIM3 counter */
TIM_Cmd(TIM3, ENABLE);
} |