现在用英蓓特的stm32f107板子做TIM3启动DMA1读取GPIOD的数据的试验,配置好tim3和dma ,得到的是一个串口接收到的是一个0xF8CF定值。GPIOD设置成悬浮输入,在pa0.0接1k,1m,5m,10m的方波,都是0xF8CF,版主拍砖。
AN2548:使用DMA实现GPIO快速数据传输
这个例子示范了如何将不同的外设用于DMA请求和数据传输,这个机制允许在没有使用CPU的情况下实现简单的快速并行同步接口。
定时器3和连接到TIM3_CC1 的DMA通道6,用来实现获取数据的接口。在GPIO的端口上可以获取16位并行数据。一个外部时钟信号作用在定时器3的外部触发器输入端,在外部触发器上升沿,定时器产生一个DMA请求。由于GPIO数据寄存器地址已设置到DMA通道6的外设地址,DMA控制器在每一次DMA请求时从GPIO端口读取数据,并把它存储到SRAM的缓冲器中。
/* DMA Channel6 Configuration ----------------------------------------------*/
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&GPIOD->IDR;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t) Parallel_Data_Buffer;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = 512;
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_VeryHigh;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel6, &DMA_InitStructure);
/* Enable DMA Channel6 */
DMA_Cmd(DMA1_Channel6, ENABLE);
/* TIM3 Configuration ------------------------------------------------------*/
/* TIM3CLK = 72 MHz, Prescaler = 0, TIM3 counter clock = 72 MHz */
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = 256;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
/* Input Capture Mode configuration: Channel1 */
TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
TIM_ICInitStructure.TIM_ICFilter = 0;
TIM_ICInit(TIM3, &TIM_ICInitStructure);
/* Enable TIM3 DMA */
TIM_DMACmd(TIM3, TIM_DMA_CC1, ENABLE);
/* Enable TIM3 counter */
TIM_Cmd(TIM3, ENABLE);
while (1)
{
/* Trigger TIM3 IC event => DMA request by toggling PA.06 */
GPIO_ResetBits(GPIOA, GPIO_Pin_6);
GPIO_SetBits(GPIOA, GPIO_Pin_6);
}
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* GPIOA Configuration: PA6 GPIO Output -> TIM3 Channel1 in Input */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
} |