求指导,,,我发现stm32f4能够进入DCMI的读完的中断,,DCMI的数据寄存器内有数据,但是DMA读不到数据!!
void Camera_DMA_Init()
{
DMA_InitTypeDef DMA_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);
DMA_DeInit(DMA2_Stream1);
DMA_InitStructure.DMA_Channel = DMA_Channel_1;
DMA_InitStructure.DMA_PeripheralBaseAddr = 0x50050028;
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)(&pixel_data);
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStructure.DMA_BufferSize =6000;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize= DMA_PeripheralDataSize_Byte;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable;
DMA_InitStructure.DMA_FIFOThreshold =DMA_FIFOThreshold_1QuarterFull;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(DMA2_Stream1, &DMA_InitStructure);
DMA_Cmd(DMA2_Stream1, ENABLE);
}
void DCMI_GPIO_Init()
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC, ENABLE); /* 使能 DCMI GPIOs 时钟 */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource4, GPIO_AF_DCMI); //DCMI_HSYNC
GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_DCMI); //DCMI_PIXCLK
GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_DCMI); //DCMI_D0
GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_DCMI); //DCMI_D1
GPIO_PinAFConfig(GPIOC, GPIO_PinSource8, GPIO_AF_DCMI); //DCMI_D2
GPIO_PinAFConfig(GPIOC, GPIO_PinSource9, GPIO_AF_DCMI); //DCMI_D3
GPIO_PinAFConfig(GPIOC, GPIO_PinSource11,GPIO_AF_DCMI); //DCMI_D4
GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_DCMI); //DCMI_D5
GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_DCMI); //DCMI_VSYNC
GPIO_PinAFConfig(GPIOB, GPIO_PinSource8, GPIO_AF_DCMI); //DCMI_D6
GPIO_PinAFConfig(GPIOB, GPIO_PinSource9, GPIO_AF_DCMI); //DCMI_D7
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 |GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 ;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_11 ;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
void Camera_DCMI_Init()
{
DCMI_InitTypeDef DCMI_InitStructure;
DCMI_GPIO_Init();
DCMI_InitStructure.DCMI_CaptureMode = DCMI_CaptureMode_Continuous; //
DCMI_InitStructure.DCMI_SynchroMode = DCMI_SynchroMode_Hardware; //嵌入式
DCMI_InitStructure.DCMI_PCKPolarity = DCMI_PCKPolarity_Falling ; //下降沿
DCMI_InitStructure.DCMI_VSPolarity = DCMI_VSPolarity_High; //
DCMI_InitStructure.DCMI_HSPolarity = DCMI_HSPolarity_Low; //
DCMI_InitStructure.DCMI_CaptureRate = DCMI_CaptureRate_All_Frame; //帧捕捉频率
DCMI_InitStructure.DCMI_ExtendedDataMode = DCMI_ExtendedDataMode_8b;//指定数据宽度
DCMI_Init(&DCMI_InitStructure);
RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_DCMI, ENABLE);
}
void NIVC_config()
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel = DCMI_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
//DCMI_ITConfig(DCMI_IT_VSYNC, ENABLE);
//DCMI_ITConfig(DCMI_IT_LINE, ENABLE);
DCMI_ITConfig(DCMI_IT_FRAME, ENABLE);
// DCMI_ITConfig(DCMI_IT_OVF, ENABLE);
//DCMI_ITConfig(DCMI_IT_ERR, ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
DMA_ITConfig(DMA2_Stream1, DMA_IT_TC, ENABLE);
DMA_ITConfig(DMA2_Stream1, DMA_IT_TCIF1, ENABLE);
}
void Ov7620_Init()
{
Camera_DCMI_Init();
Camera_DMA_Init();
NIVC_config();
}
int main(void)
{
UART2_Init();
Ov7620_Init();
DCMI_Cmd(ENABLE);
delayms();
delayms();
DCMI_CaptureCmd(ENABLE);
while (1)
{
if(DCMI_flag==1) //成功捕捉一帧图像
{
DCMI_flag=0;
for(pixel_cnt=0;pixel_cnt<12672;pixel_cnt++)
{
USART_SendData(USART2,pixel_data[pixel_cnt]);
delayms();
delayms();
USART_SendData(USART2,DCMI_ReadData());//只发送其低八位数据
delayms();
delayms();
}
}
}
}
此帖出自
小平头技术问答
一周热门 更多>