我将定时器配置为输入捕捉模式,并将DMA2通道6流1配置为将数据从GPIOC传输到frame_buffer。它有效,但是只有一次-首次使用后有数据,在下一次传输中只有零。要使其再次工作,我必须加载另一个项目,然后加载该项目。似乎是标志的问题-以前我有DMA中断,程序无法摆脱它
我正在使用STM32F411发现板
我的标志可能做错了,但是我找不到问题所在
这是我的代码:
DMA和计时器配置:
void TimerAndDMAConfigure(void){
GPIO_InitTypeDef gpioPCLK;
TIM_ICInitTypeDef icTIM1;
DMA_InitTypeDef dmaPerToMem;
NVIC_InitTypeDef nvic;
//GPIOE config
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
gpioPCLK.GPIO_Mode = GPIO_Mode_AF;
gpioPCLK.GPIO_OType = GPIO_OType_OD;
gpioPCLK.GPIO_Pin = GPIO_Pin_9;
gpioPCLK.GPIO_PuPd = GPIO_PuPd_NOPULL;
gpioPCLK.GPIO_Speed = GPIO_High_Speed;
GPIO_Init(GPIOE, &gpioPCLK);
GPIO_PinAFConfig(GPIOE, GPIO_PinSource9, GPIO_AF_TIM1);
//Timer config
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
icTIM1.TIM_Channel = TIM_Channel_1;
icTIM1.TIM_ICPolarity = TIM_ICPolarity_Rising;
icTIM1.TIM_ICSelection = TIM_ICSelection_DirectTI;
icTIM1.TIM_ICPrescaler = TIM_ICPSC_DIV1;
icTIM1.TIM_ICFilter = 0;
TIM_ICInit(TIM1, &icTIM1);
TIM_CtrlPWMOutputs(TIM1, ENABLE);
TIM_SelectOutputTrigger(TIM8 , TIM_TRGOSource_Reset);
TIM_Cmd(TIM1, ENABLE);
TIM_DMAConfig(TIM1, TIM_DMABase_CCR1, TIM_DMABurstLength_1Transfer);
TIM_DMACmd(TIM1, TIM_DMA_CC1, ENABLE);
//DMA config - peripheral to memory
//DMA2 Stream 1 Channel 6
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);
DMA_DeInit(DMA2_Stream1);
dmaPerToMem.DMA_BufferSize = 174*2;
dmaPerToMem.DMA_Channel = DMA_Channel_6;
dmaPerToMem.DMA_DIR=DMA_DIR_PeripheralToMemory;
dmaPerToMem.DMA_FIFOMode = DMA_FIFOMode_Disable;
dmaPerToMem.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
dmaPerToMem.DMA_Memory0BaseAddr = (uint32_t) frame_buffer;
dmaPerToMem.DMA_MemoryBurst = DMA_MemoryBurst_Single;
dmaPerToMem.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
dmaPerToMem.DMA_MemoryInc = DMA_MemoryInc_Enable;
dmaPerToMem.DMA_Mode = DMA_Mode_Normal;
dmaPerToMem.DMA_PeripheralBaseAddr = (uint32_t) (&GPIOC->IDR);
dmaPerToMem.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
dmaPerToMem.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
dmaPerToMem.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
dmaPerToMem.DMA_Priority = DMA_Priority_Medium;
DMA_Init(DMA2_Stream1, &dmaPerToMem);
DMA_ITConfig(DMA2_Stream1, DMA_IT_TC, ENABLE);
//DMA_Cmd(DMA2_Stream1, ENABLE);
//DMA2 - Interrupt
//nvic.NVIC_IRQChannel = DMA2_Stream1_IRQn;
//nvic.NVIC_IRQChannelCmd = ENABLE;
//nvic.NVIC_IRQChannelPreemptionPriority = 10;
//nvic.NVIC_IRQChannelSubPriority = 10;
//NVIC_Init(&nvic);
}
和主循环:
int main(void)
{
SystemInit();
uint8_t value = 10;
uint8_t next = 0;
uint8_t k = 0;
TimerAndDMAConfigure();
DMA_Cmd(DMA2_Stream2, DISABLE);
while (DMA2_Stream2->CR & DMA_SxCR_EN);
DMA_Cmd(DMA2_Stream1, ENABLE);
while(1){
DMA_Cmd(DMA2_Stream1, ENABLE);
while(DMA_GetFlagStatus(DMA2_Stream1, DMA_FLAG_TCIF1) == RESET){
continue;
}
for(int i = k; i<k + 10; i++){
value = frame_buffer[i];
next = value;
}
k+=1;
if(k==18)k=0;
DMA_ClearFlag(DMA2_Stream1, DMA_FLAG_FEIF1|DMA_FLAG_DMEIF1|DMA_FLAG_TEIF1|DMA_FLAG_HTIF1|DMA_FLAG_TCIF1);
DMA_Cmd(DMA2_Stream2, DISABLE);
while (DMA2_Stream2->CR & DMA_SxCR_EN);
Delay(10);
}
}