STM32F407discovery DCMI驱动OV7670问题?

2019-07-20 17:39发布

用论坛上的一个大神

的DCMI相机程序,移植到手头上的STM32F407discovery,摄像头出来的信号是下图所示的.
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
8条回答
chenweigang
1楼-- · 2019-07-20 21:18
回复【楼主位】chenweigang:
---------------------------------
不知道是怎么回事 上程序:
  GPIO_InitTypeDef GPIO_InitStructure;
   DCMI_InitTypeDef DCMI_InitStructure;
   DMA_InitTypeDef  DMA_InitStructure;

   RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_DCMI, ENABLE);//DCMI 
   RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);//DMA2
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | 
                           RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOE, ENABLE);//使能DCMI的GPIO时钟

GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_MCO); //MCO1A8
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
   GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
   GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;  
   GPIO_Init(GPIOA, &GPIO_InitStructure);      
    RCC_MCO2Config(RCC_MCO1Source_PLLCLK, RCC_MCO1Div_3); //168/3=56M XCLCK

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; //PE5WRDOWN
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; 
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; 
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ; 
    GPIO_Init(GPIOE, &GPIO_InitStructure);
GPIO_ResetBits(GPIOE, GPIO_Pin_5); //power on

    GPIO_PinAFConfig(GPIOA, GPIO_PinSource4, GPIO_AF_DCMI); //DCMI_HSYNC  -PA4
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_DCMI); //DCMI_PIXCLK -PA6
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_DCMI); //DCMI_D5    -PB6   
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_DCMI); //DCMI_VSYNC  -PB7
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource8, GPIO_AF_DCMI); //DCMI_D6 -PB8
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource9, GPIO_AF_DCMI); //DCMI_D7 -PB9   
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_DCMI); //DCMI_D0 -PC6
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_DCMI); //DCMI_D1 -PC7   
    GPIO_PinAFConfig(GPIOE, GPIO_PinSource0, GPIO_AF_DCMI); //DCMI_D2 -PE0
    GPIO_PinAFConfig(GPIOE, GPIO_PinSource1, GPIO_AF_DCMI); //DCMI_D3 -PE1
    GPIO_PinAFConfig(GPIOE, GPIO_PinSource4, GPIO_AF_DCMI); //DCMI_D4 -PE4

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
    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(GPIOC, &GPIO_InitStructure); 

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4; 
    GPIO_Init(GPIOE, &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_4 | GPIO_Pin_6; 
    GPIO_Init(GPIOA, &GPIO_InitStructure);
CSPin_init(); //拉高SPI1的所有片选信号,以避免干扰.  

DCMI_DeInit();
   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_High;
   DCMI_InitStructure.DCMI_CaptureRate = DCMI_CaptureRate_All_Frame;
   DCMI_InitStructure.DCMI_ExtendedDataMode = DCMI_ExtendedDataMode_8b;
   DCMI_Init(&DCMI_InitStructure);
DCMI_NVIC_Config();
DCMI_ITConfig(DCMI_IT_FRAME,ENABLE);//DCMI中断

   DMA_DeInit(DMA2_Stream1);
   DMA_InitStructure.DMA_Channel = DMA_Channel_1;  
   DMA_InitStructure.DMA_PeripheralBaseAddr = DCMI_DR_ADDRESS;
   DMA_InitStructure.DMA_Memory0BaseAddr = FSMC_LCD_ADDRESS;
   DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
   DMA_InitStructure.DMA_BufferSize = 1;
   DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
   DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;
   DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
   DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
   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_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;  
   DMA_Init(DMA2_Stream1, &DMA_InitStructure);   

摄像头OV7670初始化
static const u8 OV7670_reg[OV7670_REG_NUM][2]=
{  
  
{0x3a, 0x0c},
        {0x40, 0xd0},
        {0x12, 0x14},

        {0x32, 0x80},
        {0x17, 0x16},
        {0x18, 0x04},
        {0x19, 0x02},//ó°?ì
        {0x1a, 0x7a},//0x7a,
        {0x03, 0x03},//ó°?ì
        {0x3e, 0x00},//

        {0x70, 0x00},
        {0x71, 0x00},
        {0x72, 0x11},
        {0x73, 0x00},//
        {0xa2, 0x02},
        {0x11, 0x00},
        {0x7a, 0x20},
        {0x7b, 0x1c},
        {0x7c, 0x28},
        {0x7d, 0x3c},
        {0x7e, 0x55},
        {0x7f, 0x68},
        {0x80, 0x76},
        {0x81, 0x80},
        {0x82, 0x88},
        {0x83, 0x8f},
        {0x84, 0x96},
        {0x85, 0xa3},
        {0x86, 0xaf},
        {0x87, 0xc4},
        {0x88, 0xd7},
        {0x89, 0xe8},
        {0x13, 0xe7},
        {0x00, 0x00},//AGC
        {0x10, 0x00},
        {0x0d, 0x00},
        {0x14, 0x31},//0x38, limit the max gain
        {0xa5, 0x05},
        {0xab, 0x07},
        {0x24, 0x75},
        {0x25, 0x63},
        {0x26, 0xA5},
        {0x9f, 0x78},
        {0xa0, 0x68},
        {0xa1, 0x03},
        {0xa6, 0xdf},
        {0xa7, 0xdf},
        {0xa8, 0xf0},
        {0xa9, 0x90},
        {0xaa, 0x94},
        {0x13, 0xe7},
        {0x0e, 0x61},
        {0x0f, 0x82},
        {0x16, 0x02},
        {0x1e, 0x07},
        {0x21, 0x02},
        {0x22, 0x91},
        {0x29, 0x07},
        {0x33, 0x0b},
        {0x35, 0x0b},
        {0x37, 0x1d},
        {0x38, 0x71},
        {0x39, 0x2a},//
        {0x3c, 0x78},
        {0x4d, 0x40},
        {0x4e, 0x20},
        {0x69, 0x0c},
        {0x6b, 0x00},//PLL
        {0x74, 0x19},
        {0x8d, 0x4f},
        {0x8e, 0x00},
        {0x8f, 0x00},
        {0x90, 0x00},
        {0x91, 0x00},
        {0x92, 0x00},
        {0x96, 0x00},
        {0x9a, 0x80},
        {0xb0, 0x84},
        {0xb1, 0x0c},
        {0xb2, 0x0e},
        {0xb3, 0x82},
        {0xb8, 0x0a},
        {0x43, 0x14},
        {0x44, 0xf0},
        {0x45, 0x34},
        {0x46, 0x58},
        {0x47, 0x28},
        {0x48, 0x3a},
        {0x59, 0x88},
        {0x5a, 0x88},
        {0x5b, 0x44},
        {0x5c, 0x67},
        {0x5d, 0x49},
        {0x5e, 0x0e},
        {0x64, 0x04},
        {0x65, 0x20},
        {0x66, 0x05},
        {0x94, 0x04},
        {0x95, 0x08},
        {0x6c, 0x0a},
        {0x6d, 0x55},
        {0x6e, 0x11},
        {0x6f, 0x9f},//0x9e for advance AWB
        {0x6a, 0x40},
        {0x01, 0x40},
        {0x02, 0x40},
        {0x13, 0xe7},
        {0x15, 0x18},
        {0x4f, 0x80},
        {0x50, 0x80},
        {0x51, 0x00},
        {0x52, 0x22},
        {0x53, 0x5e},
        {0x54, 0x80},
        {0x58, 0x9e},        
        {0x41, 0x08},
        {0x3f, 0x00},
        {0x75, 0x05},
        {0x76, 0xe1},
        {0x4c, 0x00},
        {0x77, 0x01},
        {0x3d, 0xc0},
        {0x4b, 0x09},
        {0xc9, 0x60},
        {0x41, 0x38},
        {0x56, 0x40},        
        {0x34, 0x11},
        {0x3b, 0x12},
        {0xa4, 0x89},
        {0x96, 0x00},
        {0x97, 0x30},
        {0x98, 0x20},
        {0x99, 0x30},
        {0x9a, 0x84},
        {0x9b, 0x29},
        {0x9c, 0x03},
        {0x9d, 0x4c},
        {0x9e, 0x3f},
        {0x78, 0x04},        
        {0x79, 0x01},
        {0xc8, 0xf0},
        {0x79, 0x0f},
        {0xc8, 0x00},
        {0x79, 0x10},
        {0xc8, 0x7e},
        {0x79, 0x0a},
        {0xc8, 0x80},
        {0x79, 0x0b},
        {0xc8, 0x01},
        {0x79, 0x0c},
        {0xc8, 0x0f},
        {0x79, 0x0d},
        {0xc8, 0x20},
        {0x79, 0x09},
        {0xc8, 0x80},
        {0x79, 0x02},
        {0xc8, 0xc0},
        {0x79, 0x03},
        {0xc8, 0x40},
        {0x79, 0x05},
        {0xc8, 0x30},
        {0x79, 0x26},
        {0x09, 0x03},
        {0x55, 0x00},
        {0x56, 0x40},        
        {0x3b, 0x42},
        {0x07, 0x08},
        {0x10, 0x80},  

};
supereally
2楼-- · 2019-07-21 01:16
我也是这样的花屏,问下原子哥如何设置OV7670的分辨率,如我需要120*160 和240*320的分辨率怎么设置,
还有如何调用这个函数 void OV7670_HW(u16 hstart,u16 vstart,u16 hstop,u16 vstop)  。。
正点原子
3楼-- · 2019-07-21 01:44
 精彩回答 2  元偷偷看……
刺客mfl
4楼-- · 2019-07-21 06:47
 精彩回答 2  元偷偷看……
麦田稻草
5楼-- · 2019-07-21 07:16
试一下我的吧,很多时候是初始化问题,下面寄存器初始化数组在我的板上运行没问题。

#define OV7670_REG_NUM   sizeof(OV7670_reg)/2

static const u8 OV7670_reg[][2]=
{  
{0x3a, 0x04},
        {0x40, 0xd0},
        {0x12, 0x14}, //COM7
        {0x32, 0x80},
        {0x17, 0x16},
        {0x18, 0x04},
        {0x19, 0x02},
       {0x1a, 0x7a},//0x7a, 
{0x03, 0x05},//0x0a, 
{0x0c, 0x00}, 
{0x3e, 0x00},// 
{0x70, 0x00}, 
{0x71, 0x01}, 
{0x72, 0x11}, 
{0x73, 0x00},// 
{0xa2, 0x02}, 
{0x11, 0x81}, 
{0x7a, 0x20}, 
{0x7b, 0x1c}, 
{0x7c, 0x28}, 
{0x7d, 0x3c}, 
{0x7e, 0x55}, 
{0x7f, 0x68}, 
{0x80, 0x76}, 
{0x81, 0x80}, 
{0x82, 0x88}, 
{0x83, 0x8f}, 
{0x84, 0x96}, 
{0x85, 0xa3}, 
{0x86, 0xaf}, 
{0x87, 0xc4}, 
{0x88, 0xd7}, 
{0x89, 0xe8}, 
{0x13, 0xe0}, 
{0x00, 0x00},//AGC 
{0x10, 0x00}, 
{0x0d, 0x00}, 
        {0x14, 0x28},//0x38, limit the max gain
        {0xa5, 0x05},
        {0xab, 0x07},
        {0x24, 0x75},
        {0x25, 0x63},
        {0x26, 0xA5},
        {0x9f, 0x78},
        {0xa0, 0x68},
        {0xa1, 0x03},//0x0b,
        {0xa6, 0xdf},//0xd8,
        {0xa7, 0xdf},//0xd8,
        {0xa8, 0xf0},
        {0xa9, 0x90},
        {0xaa, 0x94},
        {0x13, 0xe5},
        {0x0e, 0x61},
        {0x0f, 0x4b},
        {0x16, 0x02},
        {0x1e, 0x07},//0x07,  
        {0x21, 0x02},
        {0x22, 0x91},
        {0x29, 0x07},
        {0x33, 0x0b},
        {0x35, 0x0b},
        {0x37, 0x1d},
        {0x38, 0x71},
        {0x39, 0x2a},
        {0x3c, 0x78},
        {0x4d, 0x40},
        {0x4e, 0x20},
        {0x69, 0x55},
        {0x6b, 0x0a},//PLL 重要参数 0x0a:不倍频,0x4a:4倍频
        {0x74, 0x19},
        {0x8d, 0x4f},
        {0x8e, 0x00},
        {0x8f, 0x00},
        {0x90, 0x00},
        {0x91, 0x00},
        {0x92, 0x00},//0x19,//0x66
        {0x96, 0x00},
        {0x9a, 0x80},
        {0xb0, 0x84},
        {0xb1, 0x0c},
        {0xb2, 0x0e},
        {0xb3, 0x82},
        {0xb8, 0x0a},
        {0x43, 0x14},
        {0x44, 0xf0},
        {0x45, 0x34},
        {0x46, 0x58},
        {0x47, 0x28},
        {0x48, 0x3a},
        {0x59, 0x88},
        {0x5a, 0x88},
        {0x5b, 0x44},
        {0x5c, 0x67},
        {0x5d, 0x49},
        {0x5e, 0x0e},
        {0x64, 0x04},
        {0x65, 0x20},
        {0x66, 0x05},
        {0x94, 0x04},
        {0x95, 0x08},
        {0x6c, 0x0a},
        {0x6d, 0x55},
        {0x6e, 0x11},
        {0x6f, 0x9f},//0x9e for advance AWB
        {0x6a, 0x40},
        {0x01, 0x40},
        {0x02, 0x40},
        {0x13, 0xe7},
        {0x15, 0x08}, //重要参数  
        {0x4f, 0x80},
        {0x50, 0x80},
        {0x51, 0x00},
        {0x52, 0x22},
        {0x53, 0x5e},
        {0x54, 0x80},
{0x55, 0x0A},//亮度
{0x56, 0x4f},//对比度  
        {0x58, 0x9e},        
        {0x41, 0x08},
        {0x3f, 0x05},//边缘增强调整
        {0x75, 0x05},
        {0x76, 0xe1},
        {0x4c, 0x0F},//噪声抑制强度
        {0x77, 0x0a},
        {0x3d, 0xc2},//0xc0,
        {0x4b, 0x09},
        {0xc9, 0x60},
        {0x41, 0x38},
        {0x34, 0x11},
        {0x3b, 0x0A},//0x00,//0x02,
        {0xa4, 0x89},//0x88,
        {0x96, 0x00},
        {0x97, 0x30},
        {0x98, 0x20},
        {0x99, 0x30},
        {0x9a, 0x84},
        {0x9b, 0x29},
        {0x9c, 0x03},
        {0x9d, 0x4c},
        {0x9e, 0x3f},
        {0x78, 0x04},        
        {0x79, 0x01},
        {0xc8, 0xf0},
        {0x79, 0x0f},
        {0xc8, 0x00},
        {0x79, 0x10},
        {0xc8, 0x7e},
        {0x79, 0x0a},
        {0xc8, 0x80},
        {0x79, 0x0b},
        {0xc8, 0x01},
        {0x79, 0x0c},
        {0xc8, 0x0f},
        {0x79, 0x0d},
        {0xc8, 0x20},
        {0x79, 0x09},
        {0xc8, 0x80},
        {0x79, 0x02},
        {0xc8, 0xc0},
        {0x79, 0x03},
        {0xc8, 0x40},
        {0x79, 0x05},
        {0xc8, 0x30},
        {0x79, 0x26},
        {0x09, 0x02},
        {0x3b, 0x42},//0x82,//0xc0,//0xc2,        //night mode

};
刺客mfl
6楼-- · 2019-07-21 10:41
回复【6楼】麦田稻草:
---------------------------------
谢谢    我的是SCCB没有应答 具体问题http://www.openedv.com/posts/list/42915.htm  能麻烦给看下吗   小弟感激不尽   这两天被OV7670弄的头都大了  谢谢

一周热门 更多>