高中生
最后登录1970-1-1
在线时间 小时
注册时间2016-7-21
|
引脚和摄像头是连对的,而且示波器上也测过,摄像头寄存器配置也成功。
void DMA_Config(uint32_t DMA_Memory0BaseAddr,uint16_t DMA_BufferSize)
{
DMA_InitTypeDef DMA_InitStructure;
//NVIC_InitTypeDef NVIC_InitStructure;
/* ÅäÖÃDMA′óDCMIÖD»ñè¡êy¾Y*/
/* ê1ÄüDMA*/
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);
DMA_Cmd(DMA2_Stream1,DISABLE);
while (DMA_GetCmdStatus(DMA2_Stream1) != DISABLE){}
DMA_DeInit(DMA2_Stream1);
DMA_InitStructure.DMA_Channel = DMA_Channel_1;
DMA_InitStructure.DMA_PeripheralBaseAddr = DCMI_DR_ADDRESS; //DCMIêy¾Y¼Ä′æÆ÷μØÖ·
DMA_InitStructure.DMA_Memory0BaseAddr = DMA_Memory0BaseAddr; //DMA′«êäμÄÄ¿μÄμØÖ·(′«èëμÄ2Îêy)
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStructure.DMA_BufferSize =DMA_BufferSize; //′«êäμÄêy¾Y′óD¡(′«èëμÄ2Îêy)
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; //′æ′¢Æ÷μØÖ·×Ô¶ˉμYÔö
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
DMA_InitStructure.DMA_MemoryDataSize = DMA_PeripheralDataSize_Word;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; //Ñ-»·Ä£ê½
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;//DMA_MemoryBurst_INC8 DMA_MemoryBurst_Single
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
/*DMA3õê¼»ˉ */
DMA_Init(DMA2_Stream1, &DMA_InitStructure);
DMA_ITConfig(DMA2_Stream1,DMA_IT_TC,ENABLE);//′«êäíê3éÖD¶Ï
}
void MT_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/***DCMIòy½ÅÅäÖÃ***/
/* ê1ÄüDCMIê±Öó */
RCC_AHB1PeriphClockCmd(DCMI_VSYNC_GPIO_CLK | DCMI_PIXCLK_GPIO_CLK|DCMI_HSYNC_GPIO_CLK |
DCMI_D0_GPIO_CLK| DCMI_D1_GPIO_CLK| DCMI_D2_GPIO_CLK| DCMI_D3_GPIO_CLK|
DCMI_D4_GPIO_CLK| DCMI_D5_GPIO_CLK| DCMI_D6_GPIO_CLK| DCMI_D7_GPIO_CLK, ENABLE);
/*¿ØÖÆ/í¬2½DÅoÅÏß*/
GPIO_InitStructure.GPIO_Pin = DCMI_VSYNC_GPIO_PIN;
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_PuPd_DOWN GPIO_PuPd_UP
GPIO_Init(DCMI_VSYNC_GPIO_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(DCMI_VSYNC_GPIO_PORT, DCMI_VSYNC_PINSOURCE, DCMI_VSYNC_AF);
GPIO_InitStructure.GPIO_Pin = DCMI_HSYNC_GPIO_PIN ;
GPIO_Init(DCMI_HSYNC_GPIO_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(DCMI_HSYNC_GPIO_PORT, DCMI_HSYNC_PINSOURCE, DCMI_HSYNC_AF);
GPIO_InitStructure.GPIO_Pin = DCMI_PIXCLK_GPIO_PIN ;
GPIO_Init(DCMI_PIXCLK_GPIO_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(DCMI_PIXCLK_GPIO_PORT, DCMI_PIXCLK_PINSOURCE, DCMI_PIXCLK_AF);
/*êy¾YDÅoÅ*/
GPIO_InitStructure.GPIO_Pin = DCMI_D0_GPIO_PIN ;
GPIO_Init(DCMI_D0_GPIO_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(DCMI_D0_GPIO_PORT, DCMI_D0_PINSOURCE, DCMI_D0_AF);
GPIO_InitStructure.GPIO_Pin = DCMI_D1_GPIO_PIN ;
GPIO_Init(DCMI_D1_GPIO_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(DCMI_D1_GPIO_PORT, DCMI_D1_PINSOURCE, DCMI_D1_AF);
GPIO_InitStructure.GPIO_Pin = DCMI_D2_GPIO_PIN ;
GPIO_Init(DCMI_D2_GPIO_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(DCMI_D2_GPIO_PORT, DCMI_D2_PINSOURCE, DCMI_D2_AF);
GPIO_InitStructure.GPIO_Pin = DCMI_D3_GPIO_PIN ;
GPIO_Init(DCMI_D3_GPIO_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(DCMI_D3_GPIO_PORT, DCMI_D3_PINSOURCE, DCMI_D3_AF);
GPIO_InitStructure.GPIO_Pin = DCMI_D4_GPIO_PIN ;
GPIO_Init(DCMI_D4_GPIO_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(DCMI_D4_GPIO_PORT, DCMI_D4_PINSOURCE, DCMI_D4_AF);
GPIO_InitStructure.GPIO_Pin = DCMI_D5_GPIO_PIN ;
GPIO_Init(DCMI_D5_GPIO_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(DCMI_D5_GPIO_PORT, DCMI_D5_PINSOURCE, DCMI_D5_AF);
GPIO_InitStructure.GPIO_Pin = DCMI_D6_GPIO_PIN ;
GPIO_Init(DCMI_D6_GPIO_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(DCMI_D6_GPIO_PORT, DCMI_D6_PINSOURCE, DCMI_D6_AF);
GPIO_InitStructure.GPIO_Pin = DCMI_D7_GPIO_PIN ;
GPIO_Init(DCMI_D7_GPIO_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(DCMI_D7_GPIO_PORT, DCMI_D7_PINSOURCE, DCMI_D7_AF);
}
void Camera_Init()
{
DCMI_InitTypeDef DCMI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
while(MT9V034_Init()==0)//¼Ä′æÆ÷ÅäÖÃ
MT_GPIO_Init();
RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_DCMI, ENABLE);
/* DCMI ÅäÖÃ*/
DCMI_DeInit();
DCMI_InitStructure.DCMI_CaptureMode = DCMI_CaptureMode_Continuous;
DCMI_InitStructure.DCMI_SynchroMode = DCMI_SynchroMode_Hardware;
DCMI_InitStructure.DCMI_PCKPolarity = DCMI_PCKPolarity_Rising;
DCMI_InitStructure.DCMI_VSPolarity = DCMI_VSPolarity_High;//DCMI_VSPolarity_High
DCMI_InitStructure.DCMI_HSPolarity = DCMI_VSPolarity_High;//DCMI_HSPolarity_Low
DCMI_InitStructure.DCMI_CaptureRate = DCMI_CaptureRate_All_Frame;
DCMI_InitStructure.DCMI_ExtendedDataMode = DCMI_ExtendedDataMode_8b;
DCMI_Init(&DCMI_InitStructure);
DCMI_ITConfig (DCMI_IT_FRAME,ENABLE);
//ÅäÖÃDMA′«ê䣬ֱ½óÅäÖÃÑ-»·′«êä¼′¿é
DMA_Config((uint32_t)&Image_Data,IMAGE_DATA);
/* ÅäÖÃÖD¶Ï */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = DCMI_IRQn ; //Ö¡ÖD¶Ï
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void Camera_Start()
{
DCMI_CaptureCmd(ENABLE);
DCMI_Cmd(ENABLE);
DMA_Cmd(DMA2_Stream1, ENABLE);
}
下面是两个中断函数
void DCMI_IRQHandler(void)
{
if(DCMI_GetITStatus(DCMI_IT_FRAME)!=RESET)//???????
{
DCMI_ClearITPendingBit(DCMI_IT_FRAME);//??????
}
}
void DMA2_Stream1_IRQHandler(void)
{
if(DMA_GetITStatus(DMA2_Stream1,DMA_IT_TCIF1)==SET)//DMA2_Stream1????
{
GPIO_ToggleBits(LED1_GPIO_PORT,LED1_PIN);
Get_Use_Image();
DMA_ClearITPendingBit(DMA2_Stream1,DMA_IT_TCIF1);//????????
}
}
|
|