本帖最后由 ywp125 于 2016-5-3 22:46 编辑
void DMA_Configuration(void)
{
DMA_InitTypeDef DMA_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE); // dma1时钟使能
DMA_DeInit(DMA1_Channel2); // DMA复位
DMA_StructInit(&DMA_InitStructure);// DMA缺省的参数
///---------------------------------------------
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; //dma传输方向,单向 到外设
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;//设置DMA的外设递增模式,一个外设
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;//设置DMA的内存递增模式,
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; //外设数据字长
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; //内存数据字长
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; //设置DMA的传输模式
DMA_InitStructure.DMA_Priority = DMA_Priority_High; //设置DMA的优先级别
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; //设置DMA的2个memory中的变量互相访问
///------------TIM2_--通道2
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&GPIOA->ODR ; //外设地址
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)Gpio_data;//内存地址
DMA_InitStructure.DMA_BufferSize = 200; //设置DMA在传输时缓冲区的长度
DMA_Init(DMA1_Channel2, &DMA_InitStructure);
DMA_ITConfig(DMA1_Channel2, DMA_IT_TC | DMA_IT_HT | DMA_IT_TE, ENABLE);
DMA_Cmd(DMA1_Channel2, ENABLE);
/*////--------------------------------------------------------TIM2_CH2--通道7
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&GPIOA->ODR; //外设地址
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)GPIOB_Buffer;//内存地址
DMA_InitStructure.DMA_BufferSize = sizeof(GPIOB_Buffer)/2; //设置DMA在传输时缓冲区的长度
DMA_Init(DMA1_Channel7, &DMA_InitStructure);
DMA_ITConfig(DMA1_Channel7, DMA_IT_TC | DMA_IT_HT | DMA_IT_TE, ENABLE);
DMA_Cmd(DMA1_Channel7, ENABLE);
//--------------------------------TIM2_CH3--通道1
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&GPIOA->ODR; //外设地址
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)GPIOB_Buffer;//内存地址
DMA_InitStructure.DMA_BufferSize = sizeof(GPIOB_Buffer)/2; //设置DMA在传输时缓冲区的长度
DMA_Init(DMA1_Channel1, &DMA_InitStructure);
DMA_ITConfig(DMA1_Channel1, DMA_IT_TC | DMA_IT_HT | DMA_IT_TE, ENABLE);
DMA_Cmd(DMA1_Channel1, ENABLE);
*/
}
void DMA1_Channel2_IRQHandler(void)
{if(DMA1->ISR & DMA1_IT_HT2)//半传
{DMA1->IFCR =DMA1_IT_HT2;
}
if(DMA1->ISR & DMA1_IT_TC2)
{DMA1->IFCR =DMA1_IT_TC2; //传完
}
}
进入半传后,传一个数据来一个半传中断,全传不会,搞了几天都找不到原因
|