STM32F4驱动OV2640获取JPG图片和RGB565格式图片-下位机

2023-12-22 18:40

本文主要是介绍STM32F4驱动OV2640获取JPG图片和RGB565格式图片-下位机,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

目录

 

 

1 环境

2 相关硬件

2.1 DCMI

2.2 按键

3 STM32CubeMX配置

3.1 SWD仿真接口

3.2 时钟配置

3.2.1 引脚

3.2.2 时钟树

3.3 I2C

3.4 DCMI

3.4.1 基本配置

3.4.2 配置DCMI的引脚

3.4.3 开启DCMI的DMA模式

3.4.4 开启中断

3.5 USART3

3.6 工程配置

3.7 生成代码

4. 增加相关代码

4.1 ov2640.c

4.2 ov2640.h

4.3 ov2640cfg.h

 4.4 main.c


 

1 环境

Win10,

STM32CubeMX 5.3.0

STM32CubeF4 1.24.1

STM32CubeIDE 1.0.2

Waveshare Open407V-C开发板

2 相关硬件

2.1 DCMI

2.2 按键

3 STM32CubeMX配置

3.1 SWD仿真接口

3.2 时钟配置

3.2.1 引脚

3.2.2 时钟树

3.3 I2C

默认配置即可,引脚要选择PB10、PB11

3.4 DCMI

3.4.1 基本配置

要配置为Active on Rising edge,同时jpeg mode选择enabled

 

 

3.4.2 配置DCMI的引脚

另外PA8也需要的。

3.4.3 开启DCMI的DMA模式

3.4.4 开启中断

3.5 USART3

准备将图片通过USART3发送到PC端。因此,要初始化。

这里有两个步骤,1是在USART3的Mode中选择Asynchronous,2是在PC10和PC11选择USART3。

其他参数不变。

3.6 工程配置

 

 h

 这里可以配置工程路径,自行输入工程名字,IDE选择STM32CubeIDE。Heap size和stack size适当增加一点。我增加Heap size到0x500。Stack size到0x1000。(暂时未有根据要多少的size)

点击code generator中的generate perpherial initialization as a pair f .c/.h files per periherial

3.7 生成代码

点generate code

4. 增加相关代码

4.1 ov2640.c

/********************************************************************************* @file    ov2640.c* @author  MCD Application Team* @version V1.0.2* @date    02-December-2014* @brief   This file provides the OV2640 camera driver******************************************************************************* @attention** <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>** Redistribution and use in source and binary forms, with or without modification,* are permitted provided that the following conditions are met:*   1. Redistributions of source code must retain the above copyright notice,*      this list of conditions and the following disclaimer.*   2. Redistributions in binary form must reproduce the above copyright notice,*      this list of conditions and the following disclaimer in the documentation*      and/or other materials provided with the distribution.*   3. Neither the name of STMicroelectronics nor the names of its contributors*      may be used to endorse or promote products derived from this software*      without specific prior written permission.** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.********************************************************************************/ /* Includes ------------------------------------------------------------------*/
#include "ov2640.h"
#include "ov2640cfg.h"
/** @addtogroup BSP* @{*/ /** @addtogroup Components* @{*/ /** @defgroup OV2640_Private_TypesDefinitions* @{*/ /*** @}*/ /** @defgroup OV2640_Private_Defines* @{*//*** @}*/ /** @defgroup OV2640_Private_Macros* @{*//*** @}*/  /** @defgroup OV2640_Private_FunctionPrototypes* @{*/
//static uint32_t ov2640_ConvertValue(uint32_t feature, uint32_t value);
/*** @}*/ /** @defgroup OV2640_Private_Variables* @{*/        /* Initialization sequence for 480x272 resolution */
const unsigned char OV2640_480x272[][2]=
{{0xff, 0x00},  /* Device control register list Table 12 */{0x2c, 0xff},  /* Reserved                              */{0x2e, 0xdf},  /* Reserved                              */{0xff, 0x01},  /* Device control register list Table 13 */{0x3c, 0x32},  /* Reserved                              */{0x11, 0x00},  /* Clock Rate Control                    */{0x09, 0x02},  /* Common control 2                      */{0x04, 0xA8},  /* Mirror                                */{0x13, 0xe5},  /* Common control 8                      */{0x14, 0x48},  /* Common control 9                      */{0x2c, 0x0c},  /* Reserved                              */{0x33, 0x78},  /* Reserved                              */{0x3a, 0x33},  /* Reserved                              */{0x3b, 0xfB},  /* Reserved                              */{0x3e, 0x00},  /* Reserved                              */{0x43, 0x11},  /* Reserved                              */{0x16, 0x10},  /* Reserved                              */{0x4a, 0x81},  /* Reserved                              */{0x21, 0x99},  /* Reserved                              */{0x24, 0x40},  /* Luminance signal High range           */{0x25, 0x38},  /* Luminance signal low range            */{0x26, 0x82},  /*                                       */{0x5c, 0x00},  /* Reserved                              */{0x63, 0x00},  /* Reserved                              */{0x46, 0x3f},  /* Frame length adjustment               */{0x0c, 0x3c},  /* Common control 3                      */{0x61, 0x70},  /* Histogram algo low level              */{0x62, 0x80},  /* Histogram algo high level             */{0x7c, 0x05},  /* Reserved                              */{0x20, 0x80},  /* Reserved                              */{0x28, 0x30},  /* Reserved                              */{0x6c, 0x00},  /* Reserved                              */{0x6d, 0x80},  /* Reserved                              */{0x6e, 0x00},  /* Reserved                              */{0x70, 0x02},  /* Reserved                              */{0x71, 0x94},  /* Reserved                              */{0x73, 0xc1},  /* Reserved                              */{0x3d, 0x34},  /* Reserved                              */{0x5a, 0x57},  /* Reserved                              */{0x12, 0x00},  /* Common control 7                      */{0x11, 0x00},  /* Clock Rate Control                   2*/{0x17, 0x11},  /* Horiz window start MSB 8bits          */{0x18, 0x75},  /* Horiz window end MSB 8bits            */{0x19, 0x01},  /* Vert window line start MSB 8bits      */{0x1a, 0x97},  /* Vert window line end MSB 8bits        */{0x32, 0x36},{0x03, 0x0f},{0x37, 0x40},{0x4f, 0xbb},{0x50, 0x9c},{0x5a, 0x57},{0x6d, 0x80},{0x6d, 0x38},{0x39, 0x02},{0x35, 0x88},{0x22, 0x0a},{0x37, 0x40},{0x23, 0x00},{0x34, 0xa0},{0x36, 0x1a},{0x06, 0x02},{0x07, 0xc0},{0x0d, 0xb7},{0x0e, 0x01},{0x4c, 0x00},{0xff, 0x00},{0xe5, 0x7f},{0xf9, 0xc0},{0x41, 0x24},{0xe0, 0x14},{0x76, 0xff},{0x33, 0xa0},{0x42, 0x20},{0x43, 0x18},{0x4c, 0x00},{0x87, 0xd0},{0x88, 0x3f},{0xd7, 0x03},{0xd9, 0x10},{0xd3, 0x82},{0xc8, 0x08},{0xc9, 0x80},{0x7d, 0x00},{0x7c, 0x03},{0x7d, 0x48},{0x7c, 0x08},{0x7d, 0x20},{0x7d, 0x10},{0x7d, 0x0e},{0x90, 0x00},{0x91, 0x0e},{0x91, 0x1a},{0x91, 0x31},{0x91, 0x5a},{0x91, 0x69},{0x91, 0x75},{0x91, 0x7e},{0x91, 0x88},{0x91, 0x8f},{0x91, 0x96},{0x91, 0xa3},{0x91, 0xaf},{0x91, 0xc4},{0x91, 0xd7},{0x91, 0xe8},{0x91, 0x20},{0x92, 0x00},{0x93, 0x06},{0x93, 0xe3},{0x93, 0x02},{0x93, 0x02},{0x93, 0x00},{0x93, 0x04},{0x93, 0x00},{0x93, 0x03},{0x93, 0x00},{0x93, 0x00},{0x93, 0x00},{0x93, 0x00},{0x93, 0x00},{0x93, 0x00},{0x93, 0x00},{0x96, 0x00},{0x97, 0x08},{0x97, 0x19},{0x97, 0x02},{0x97, 0x0c},{0x97, 0x24},{0x97, 0x30},{0x97, 0x28},{0x97, 0x26},{0x97, 0x02},{0x97, 0x98},{0x97, 0x80},{0x97, 0x00},{0x97, 0x00},{0xc3, 0xef},{0xff, 0x00},{0xba, 0xdc},{0xbb, 0x08},{0xb6, 0x24},{0xb8, 0x33},{0xb7, 0x20},{0xb9, 0x30},{0xb3, 0xb4},{0xb4, 0xca},{0xb5, 0x43},{0xb0, 0x5c},{0xb1, 0x4f},{0xb2, 0x06},{0xc7, 0x00},{0xc6, 0x51},{0xc5, 0x11},{0xc4, 0x9c},{0xbf, 0x00},{0xbc, 0x64},{0xa6, 0x00},{0xa7, 0x1e},{0xa7, 0x6b},{0xa7, 0x47},{0xa7, 0x33},{0xa7, 0x00},{0xa7, 0x23},{0xa7, 0x2e},{0xa7, 0x85},{0xa7, 0x42},{0xa7, 0x33},{0xa7, 0x00},{0xa7, 0x23},{0xa7, 0x1b},{0xa7, 0x74},{0xa7, 0x42},{0xa7, 0x33},{0xa7, 0x00},{0xa7, 0x23},{0xc0, 0xc8},{0xc1, 0x96},{0x8c, 0x00},{0x86, 0x3d},{0x50, 0x92},{0x51, 0x90},{0x52, 0x2c},{0x53, 0x00},{0x54, 0x00},{0x55, 0x88},{0x5a, 0x50},{0x5b, 0x3c},{0x5c, 0x00},{0xd3, 0x04},{0x7f, 0x00},{0xda, 0x00},{0xe5, 0x1f},{0xe1, 0x67},{0xe0, 0x00},{0xdd, 0x7f},{0x05, 0x00},{0xff, 0x00},{0xe0, 0x04},{0xc0, 0xc8},{0xc1, 0x96},{0x86, 0x3d},{0x50, 0x92},{0x51, 0x90},{0x52, 0x2c},{0x53, 0x00},{0x54, 0x00},{0x55, 0x88},{0x57, 0x00},{0x5a, 0x50},{0x5b, 0x3c},{0x5c, 0x00},{0xd3, 0x04},{0xe0, 0x00},{0xFF, 0x00},{0x05, 0x00},{0xDA, 0x08},{0xda, 0x09},{0x98, 0x00},{0x99, 0x00},{0x00, 0x00},{0xff, 0x00},{0xe0, 0x04},{0xc0, 0xc8},{0xc1, 0x96},{0x86, 0x35},{0x50, 0x80},{0x51, 0x90},{0x52, 0x2c},{0x53, 0x00},{0x54, 0x00},{0x55, 0x88},{0x57, 0x00},{0x5a, 0x78},{0x5b, 0x44},{0x5c, 0x00},{0xd3, 0x04},{0xe0, 0x00},
};/* Initialization sequence for VGA resolution (640x480)*/
const unsigned char OV2640_VGA[][2]=
{{0xff, 0x00},  /* Device control register list Table 12 */{0x2c, 0xff},  /* Reserved                              */{0x2e, 0xdf},  /* Reserved                              */{0xff, 0x01},  /* Device control register list Table 13 */{0x3c, 0x32},  /* Reserved                              */{0x11, 0x00},  /* Clock Rate Control                    */{0x09, 0x02},  /* Common control 2                      */{0x04, 0xA8},  /* Mirror                                */{0x13, 0xe5},  /* Common control 8                      */{0x14, 0x48},  /* Common control 9                      */{0x2c, 0x0c},  /* Reserved                              */{0x33, 0x78},  /* Reserved                              */{0x3a, 0x33},  /* Reserved                              */{0x3b, 0xfB},  /* Reserved                              */{0x3e, 0x00},  /* Reserved                              */{0x43, 0x11},  /* Reserved                              */{0x16, 0x10},  /* Reserved                              */{0x4a, 0x81},  /* Reserved                              */{0x21, 0x99},  /* Reserved                              */{0x24, 0x40},  /* Luminance signal High range           */{0x25, 0x38},  /* Luminance signal low range            */{0x26, 0x82},  /*                                       */{0x5c, 0x00},  /* Reserved                              */{0x63, 0x00},  /* Reserved                              */{0x46, 0x3f},  /* Frame length adjustment               */{0x0c, 0x3c},  /* Common control 3                      */{0x61, 0x70},  /* Histogram algo low level              */{0x62, 0x80},  /* Histogram algo high level             */{0x7c, 0x05},  /* Reserved                              */{0x20, 0x80},  /* Reserved                              */{0x28, 0x30},  /* Reserved                              */{0x6c, 0x00},  /* Reserved                              */{0x6d, 0x80},  /* Reserved                              */{0x6e, 0x00},  /* Reserved                              */{0x70, 0x02},  /* Reserved                              */{0x71, 0x94},  /* Reserved                              */{0x73, 0xc1},  /* Reserved                              */{0x3d, 0x34},  /* Reserved                              */{0x5a, 0x57},  /* Reserved                              */{0x12, 0x00},  /* Common control 7                      */{0x11, 0x00},  /* Clock Rate Control                   2*/{0x17, 0x11},  /* Horiz window start MSB 8bits          */{0x18, 0x75},  /* Horiz window end MSB 8bits            */{0x19, 0x01},  /* Vert window line start MSB 8bits      */{0x1a, 0x97},  /* Vert window line end MSB 8bits        */{0x32, 0x36},{0x03, 0x0f},{0x37, 0x40},{0x4f, 0xbb},{0x50, 0x9c},{0x5a, 0x57},{0x6d, 0x80},{0x6d, 0x38},{0x39, 0x02},{0x35, 0x88},{0x22, 0x0a},{0x37, 0x40},{0x23, 0x00},{0x34, 0xa0},{0x36, 0x1a},{0x06, 0x02},{0x07, 0xc0},{0x0d, 0xb7},{0x0e, 0x01},{0x4c, 0x00},{0xff, 0x00},{0xe5, 0x7f},{0xf9, 0xc0},{0x41, 0x24},{0xe0, 0x14},{0x76, 0xff},{0x33, 0xa0},{0x42, 0x20},{0x43, 0x18},{0x4c, 0x00},{0x87, 0xd0},{0x88, 0x3f},{0xd7, 0x03},{0xd9, 0x10},{0xd3, 0x82},{0xc8, 0x08},{0xc9, 0x80},{0x7d, 0x00},{0x7c, 0x03},{0x7d, 0x48},{0x7c, 0x08},{0x7d, 0x20},{0x7d, 0x10},{0x7d, 0x0e},{0x90, 0x00},{0x91, 0x0e},{0x91, 0x1a},{0x91, 0x31},{0x91, 0x5a},{0x91, 0x69},{0x91, 0x75},{0x91, 0x7e},{0x91, 0x88},{0x91, 0x8f},{0x91, 0x96},{0x91, 0xa3},{0x91, 0xaf},{0x91, 0xc4},{0x91, 0xd7},{0x91, 0xe8},{0x91, 0x20},{0x92, 0x00},{0x93, 0x06},{0x93, 0xe3},{0x93, 0x02},{0x93, 0x02},{0x93, 0x00},{0x93, 0x04},{0x93, 0x00},{0x93, 0x03},{0x93, 0x00},{0x93, 0x00},{0x93, 0x00},{0x93, 0x00},{0x93, 0x00},{0x93, 0x00},{0x93, 0x00},{0x96, 0x00},{0x97, 0x08},{0x97, 0x19},{0x97, 0x02},{0x97, 0x0c},{0x97, 0x24},{0x97, 0x30},{0x97, 0x28},{0x97, 0x26},{0x97, 0x02},{0x97, 0x98},{0x97, 0x80},{0x97, 0x00},{0x97, 0x00},{0xc3, 0xef},{0xff, 0x00},{0xba, 0xdc},{0xbb, 0x08},{0xb6, 0x24},{0xb8, 0x33},{0xb7, 0x20},{0xb9, 0x30},{0xb3, 0xb4},{0xb4, 0xca},{0xb5, 0x43},{0xb0, 0x5c},{0xb1, 0x4f},{0xb2, 0x06},{0xc7, 0x00},{0xc6, 0x51},{0xc5, 0x11},{0xc4, 0x9c},{0xbf, 0x00},{0xbc, 0x64},{0xa6, 0x00},{0xa7, 0x1e},{0xa7, 0x6b},{0xa7, 0x47},{0xa7, 0x33},{0xa7, 0x00},{0xa7, 0x23},{0xa7, 0x2e},{0xa7, 0x85},{0xa7, 0x42},{0xa7, 0x33},{0xa7, 0x00},{0xa7, 0x23},{0xa7, 0x1b},{0xa7, 0x74},{0xa7, 0x42},{0xa7, 0x33},{0xa7, 0x00},{0xa7, 0x23},{0xc0, 0xc8},{0xc1, 0x96},{0x8c, 0x00},{0x86, 0x3d},{0x50, 0x92},{0x51, 0x90},{0x52, 0x2c},{0x53, 0x00},{0x54, 0x00},{0x55, 0x88},{0x5a, 0x50},{0x5b, 0x3c},{0x5c, 0x00},{0xd3, 0x04},{0x7f, 0x00},{0xda, 0x00},{0xe5, 0x1f},{0xe1, 0x67},{0xe0, 0x00},{0xdd, 0x7f},{0x05, 0x00},{0xff, 0x00},{0xe0, 0x04},{0xc0, 0xc8},{0xc1, 0x96},{0x86, 0x3d},{0x50, 0x92},{0x51, 0x90},{0x52, 0x2c},{0x53, 0x00},{0x54, 0x00},{0x55, 0x88},{0x57, 0x00},{0x5a, 0x50},{0x5b, 0x3c},{0x5c, 0x00},{0xd3, 0x04},{0xe0, 0x00},{0xFF, 0x00},{0x05, 0x00},{0xDA, 0x08},{0xda, 0x09},{0x98, 0x00},{0x99, 0x00},{0x00, 0x00},{0xff, 0x00},{0xe0, 0x04},{0xc0, 0xc8},{0xc1, 0x96},{0x86, 0x3d},{0x50, 0x89},{0x51, 0x90},{0x52, 0x2c},{0x53, 0x00},{0x54, 0x00},{0x55, 0x88},{0x57, 0x00},{0x5a, 0xA0},{0x5b, 0x78},{0x5c, 0x00},{0xd3, 0x02},{0xe0, 0x00},
};/* Initialization sequence for QVGA resolution (320x240) */
const unsigned char OV2640_QVGA[][2]=
{{0xff, 0x00},{0x2c, 0xff},{0x2e, 0xdf},{0xff, 0x01},{0x3c, 0x32},{0x11, 0x00},{0x09, 0x02},{0x04, 0xA8},{0x13, 0xe5},{0x14, 0x48},{0x2c, 0x0c},{0x33, 0x78},{0x3a, 0x33},{0x3b, 0xfB},{0x3e, 0x00},{0x43, 0x11},{0x16, 0x10},{0x4a, 0x81},{0x21, 0x99},{0x24, 0x40},{0x25, 0x38},{0x26, 0x82},{0x5c, 0x00},{0x63, 0x00},{0x46, 0x3f},{0x0c, 0x3c},{0x61, 0x70},{0x62, 0x80},{0x7c, 0x05},{0x20, 0x80},{0x28, 0x30},{0x6c, 0x00},{0x6d, 0x80},{0x6e, 0x00},{0x70, 0x02},{0x71, 0x94},{0x73, 0xc1},{0x3d, 0x34},{0x5a, 0x57},{0x12, 0x00},{0x11, 0x00},{0x17, 0x11},{0x18, 0x75},{0x19, 0x01},{0x1a, 0x97},{0x32, 0x36},{0x03, 0x0f},{0x37, 0x40},{0x4f, 0xbb},{0x50, 0x9c},{0x5a, 0x57},{0x6d, 0x80},{0x6d, 0x38},{0x39, 0x02},{0x35, 0x88},{0x22, 0x0a},{0x37, 0x40},{0x23, 0x00},{0x34, 0xa0},{0x36, 0x1a},{0x06, 0x02},{0x07, 0xc0},{0x0d, 0xb7},{0x0e, 0x01},{0x4c, 0x00},{0xff, 0x00},{0xe5, 0x7f},{0xf9, 0xc0},{0x41, 0x24},{0xe0, 0x14},{0x76, 0xff},{0x33, 0xa0},{0x42, 0x20},{0x43, 0x18},{0x4c, 0x00},{0x87, 0xd0},{0x88, 0x3f},{0xd7, 0x03},{0xd9, 0x10},{0xd3, 0x82},{0xc8, 0x08},{0xc9, 0x80},{0x7d, 0x00},{0x7c, 0x03},{0x7d, 0x48},{0x7c, 0x08},{0x7d, 0x20},{0x7d, 0x10},{0x7d, 0x0e},{0x90, 0x00},{0x91, 0x0e},{0x91, 0x1a},{0x91, 0x31},{0x91, 0x5a},{0x91, 0x69},{0x91, 0x75},{0x91, 0x7e},{0x91, 0x88},{0x91, 0x8f},{0x91, 0x96},{0x91, 0xa3},{0x91, 0xaf},{0x91, 0xc4},{0x91, 0xd7},{0x91, 0xe8},{0x91, 0x20},{0x92, 0x00},{0x93, 0x06},{0x93, 0xe3},{0x93, 0x02},{0x93, 0x02},{0x93, 0x00},{0x93, 0x04},{0x93, 0x00},{0x93, 0x03},{0x93, 0x00},{0x93, 0x00},{0x93, 0x00},{0x93, 0x00},{0x93, 0x00},{0x93, 0x00},{0x93, 0x00},{0x96, 0x00},{0x97, 0x08},{0x97, 0x19},{0x97, 0x02},{0x97, 0x0c},{0x97, 0x24},{0x97, 0x30},{0x97, 0x28},{0x97, 0x26},{0x97, 0x02},{0x97, 0x98},{0x97, 0x80},{0x97, 0x00},{0x97, 0x00},{0xc3, 0xef},{0xff, 0x00},{0xba, 0xdc},{0xbb, 0x08},{0xb6, 0x24},{0xb8, 0x33},{0xb7, 0x20},{0xb9, 0x30},{0xb3, 0xb4},{0xb4, 0xca},{0xb5, 0x43},{0xb0, 0x5c},{0xb1, 0x4f},{0xb2, 0x06},{0xc7, 0x00},{0xc6, 0x51},{0xc5, 0x11},{0xc4, 0x9c},{0xbf, 0x00},{0xbc, 0x64},{0xa6, 0x00},{0xa7, 0x1e},{0xa7, 0x6b},{0xa7, 0x47},{0xa7, 0x33},{0xa7, 0x00},{0xa7, 0x23},{0xa7, 0x2e},{0xa7, 0x85},{0xa7, 0x42},{0xa7, 0x33},{0xa7, 0x00},{0xa7, 0x23},{0xa7, 0x1b},{0xa7, 0x74},{0xa7, 0x42},{0xa7, 0x33},{0xa7, 0x00},{0xa7, 0x23},{0xc0, 0xc8},{0xc1, 0x96},{0x8c, 0x00},{0x86, 0x3d},{0x50, 0x92},{0x51, 0x90},{0x52, 0x2c},{0x53, 0x00},{0x54, 0x00},{0x55, 0x88},{0x5a, 0x50},{0x5b, 0x3c},{0x5c, 0x00},{0xd3, 0x04},{0x7f, 0x00},{0xda, 0x00},{0xe5, 0x1f},{0xe1, 0x67},{0xe0, 0x00},{0xdd, 0x7f},{0x05, 0x00},{0xff, 0x00},{0xe0, 0x04},{0xc0, 0xc8},{0xc1, 0x96},{0x86, 0x3d},{0x50, 0x92},{0x51, 0x90},{0x52, 0x2c},{0x53, 0x00},{0x54, 0x00},{0x55, 0x88},{0x57, 0x00},{0x5a, 0x50},{0x5b, 0x3C},{0x5c, 0x00},{0xd3, 0x08},{0xe0, 0x00},{0xFF, 0x00},{0x05, 0x00},{0xDA, 0x08},{0xda, 0x09},{0x98, 0x00},{0x99, 0x00},{0x00, 0x00},
};/* Initialization sequence for QQVGA resolution (160x120) */
const char OV2640_QQVGA[][2]=
{{0xff, 0x00},{0x2c, 0xff},{0x2e, 0xdf},{0xff, 0x01},{0x3c, 0x32},{0x11, 0x00},{0x09, 0x02},{0x04, 0xA8},{0x13, 0xe5},{0x14, 0x48},{0x2c, 0x0c},{0x33, 0x78},{0x3a, 0x33},{0x3b, 0xfB},{0x3e, 0x00},{0x43, 0x11},{0x16, 0x10},{0x4a, 0x81},{0x21, 0x99},{0x24, 0x40},{0x25, 0x38},{0x26, 0x82},{0x5c, 0x00},{0x63, 0x00},{0x46, 0x3f},{0x0c, 0x3c},{0x61, 0x70},{0x62, 0x80},{0x7c, 0x05},{0x20, 0x80},{0x28, 0x30},{0x6c, 0x00},{0x6d, 0x80},{0x6e, 0x00},{0x70, 0x02},{0x71, 0x94},{0x73, 0xc1},{0x3d, 0x34},{0x5a, 0x57},{0x12, 0x00},{0x11, 0x00},{0x17, 0x11},{0x18, 0x75},{0x19, 0x01},{0x1a, 0x97},{0x32, 0x36},{0x03, 0x0f},{0x37, 0x40},{0x4f, 0xbb},{0x50, 0x9c},{0x5a, 0x57},{0x6d, 0x80},{0x6d, 0x38},{0x39, 0x02},{0x35, 0x88},{0x22, 0x0a},{0x37, 0x40},{0x23, 0x00},{0x34, 0xa0},{0x36, 0x1a},{0x06, 0x02},{0x07, 0xc0},{0x0d, 0xb7},{0x0e, 0x01},{0x4c, 0x00},{0xff, 0x00},{0xe5, 0x7f},{0xf9, 0xc0},{0x41, 0x24},{0xe0, 0x14},{0x76, 0xff},{0x33, 0xa0},{0x42, 0x20},{0x43, 0x18},{0x4c, 0x00},{0x87, 0xd0},{0x88, 0x3f},{0xd7, 0x03},{0xd9, 0x10},{0xd3, 0x82},{0xc8, 0x08},{0xc9, 0x80},{0x7d, 0x00},{0x7c, 0x03},{0x7d, 0x48},{0x7c, 0x08},{0x7d, 0x20},{0x7d, 0x10},{0x7d, 0x0e},{0x90, 0x00},{0x91, 0x0e},{0x91, 0x1a},{0x91, 0x31},{0x91, 0x5a},{0x91, 0x69},{0x91, 0x75},{0x91, 0x7e},{0x91, 0x88},{0x91, 0x8f},{0x91, 0x96},{0x91, 0xa3},{0x91, 0xaf},{0x91, 0xc4},{0x91, 0xd7},{0x91, 0xe8},{0x91, 0x20},{0x92, 0x00},{0x93, 0x06},{0x93, 0xe3},{0x93, 0x02},{0x93, 0x02},{0x93, 0x00},{0x93, 0x04},{0x93, 0x00},{0x93, 0x03},{0x93, 0x00},{0x93, 0x00},{0x93, 0x00},{0x93, 0x00},{0x93, 0x00},{0x93, 0x00},{0x93, 0x00},{0x96, 0x00},{0x97, 0x08},{0x97, 0x19},{0x97, 0x02},{0x97, 0x0c},{0x97, 0x24},{0x97, 0x30},{0x97, 0x28},{0x97, 0x26},{0x97, 0x02},{0x97, 0x98},{0x97, 0x80},{0x97, 0x00},{0x97, 0x00},{0xc3, 0xef},{0xff, 0x00},{0xba, 0xdc},{0xbb, 0x08},{0xb6, 0x24},{0xb8, 0x33},{0xb7, 0x20},{0xb9, 0x30},{0xb3, 0xb4},{0xb4, 0xca},{0xb5, 0x43},{0xb0, 0x5c},{0xb1, 0x4f},{0xb2, 0x06},{0xc7, 0x00},{0xc6, 0x51},{0xc5, 0x11},{0xc4, 0x9c},{0xbf, 0x00},{0xbc, 0x64},{0xa6, 0x00},{0xa7, 0x1e},{0xa7, 0x6b},{0xa7, 0x47},{0xa7, 0x33},{0xa7, 0x00},{0xa7, 0x23},{0xa7, 0x2e},{0xa7, 0x85},{0xa7, 0x42},{0xa7, 0x33},{0xa7, 0x00},{0xa7, 0x23},{0xa7, 0x1b},{0xa7, 0x74},{0xa7, 0x42},{0xa7, 0x33},{0xa7, 0x00},{0xa7, 0x23},{0xc0, 0xc8},{0xc1, 0x96},{0x8c, 0x00},{0x86, 0x3d},{0x50, 0x92},{0x51, 0x90},{0x52, 0x2c},{0x53, 0x00},{0x54, 0x00},{0x55, 0x88},{0x5a, 0x50},{0x5b, 0x3c},{0x5c, 0x00},{0xd3, 0x04},{0x7f, 0x00},{0xda, 0x00},{0xe5, 0x1f},{0xe1, 0x67},{0xe0, 0x00},{0xdd, 0x7f},{0x05, 0x00},{0xff, 0x00},{0xe0, 0x04},{0xc0, 0xc8},{0xc1, 0x96},{0x86, 0x3d},{0x50, 0x92},{0x51, 0x90},{0x52, 0x2c},{0x53, 0x00},{0x54, 0x00},{0x55, 0x88},{0x57, 0x00},{0x5a, 0x28}, {0x5b, 0x1E}, {0x5c, 0x00},{0xd3, 0x08},{0xe0, 0x00},{0xFF, 0x00},{0x05, 0x00},{0xDA, 0x08},{0xda, 0x09},{0x98, 0x00},{0x99, 0x00},{0x00, 0x00},
};
/* JPG 320x240 */
const unsigned char OV2640_320x240_JPEG[][2]=
{{0xff, 0x01},{0x11, 0x01},{0x12, 0x00}, // Bit[6:4]: Resolution selection//0x02����{0x17, 0x11}, // HREFST[10:3]{0x18, 0x75}, // HREFEND[10:3]{0x32, 0x36}, // Bit[5:3]: HREFEND[2:0]; Bit[2:0]: HREFST[2:0]{0x19, 0x01}, // VSTRT[9:2]{0x1a, 0x97}, // VEND[9:2]{0x03, 0x0f}, // Bit[3:2]: VEND[1:0]; Bit[1:0]: VSTRT[1:0]{0x37, 0x40},{0x4f, 0xbb},{0x50, 0x9c},{0x5a, 0x57},{0x6d, 0x80},{0x3d, 0x34},{0x39, 0x02},{0x35, 0x88},{0x22, 0x0a},{0x37, 0x40},{0x34, 0xa0},{0x06, 0x02},{0x0d, 0xb7},{0x0e, 0x01},/*//176*1440xff,      0x00,0xc0,      0xC8,0xc1,      0x96,0x8c,      0x00,0x86,      0x3D,0x50,      0x9B,0x51,      0x90,0x52,      0x2C,0x53,      0x00,0x54,      0x00,0x55,      0x88,0x5a,      0x2C,0x5b,      0x24,0x5c,      0x00,0xd3,      0x7F,*/
/*//320*2400xff,      0x00,0xe0,      0x04,0xc0,      0xc8,0xc1,      0x96,0x86,      0x3d,0x50,      0x92,0x51,      0x90,0x52,      0x2c,0x53,      0x00,0x54,      0x00,0x55,      0x88,0x57,      0x00,0x5a,      0x50,0x5b,      0x3c,0x5c,      0x00,0xd3,      0x7F,0xe0,      0x00,///
*//*
0xff,      0x00,0xe0,      0x04,0xc0,      0xc8,0xc1,      0x96,0x86,      0x35,0x50,      0x92,0x51,      0x90,0x52,      0x2c,0x53,      0x00,0x54,      0x00,0x55,      0x88,0x57,      0x00,0x5a,      0x58,0x5b,      0x48,0x5c,      0x00,0xd3,      0x08,0xe0,      0x00
*///640*480	  0xff,      0x00,0xe0,      0x04,0xc0,      0xc8,0xc1,      0x96,0x86,      0x3d,0x50,      0x89,0x51,      0x90,0x52,      0x2c,0x53,      0x00,0x54,      0x00,0x55,      0x88,0x57,      0x00,0x5a,      0xa0,0x5b,      0x78,0x5c,      0x00,0xd3,      0x04,0xe0,      0x00///800*600
//			{0xff,      0x00},
//      {0xe0,      0x04},
//      {0xc0,      0xc8},
//      {0xc1,      0x96},
//      {0x86,      0x35},
//      {0x50,      0x89},
//      {0x51,      0x90},
//      {0x52,      0x2c},
//      {0x53,      0x00},
//      {0x54,      0x00},
//      {0x55,      0x88},
//      {0x57,      0x00},
//      {0x5a,      0xc8},
//      {0x5b,      0x96},
//      {0x5c,      0x00},
//      {0xd3,      0x02},
//      {0xe0,      0x00},//1280*1024//			0xff,      0x00,
//      0xe0,      0x04,
//      0xc0,      0xc8,
//      0xc1,      0x96,
//      0x86,      0x3d,
//      0x50,      0x00,
//      0x51,      0x90,
//      0x52,      0x2c,
//      0x53,      0x00,
//      0x54,      0x00,
//      0x55,      0x88,
//      0x57,      0x00,
//      0x5a,      0x40,
//      0x5b,      0xf0,
//      0x5c,      0x01,
//      0xd3,      0x02,
//      0xe0,      0x00///1600*1200
/*0xff,      0x00,0xe0,      0x04,0xc0,      0xc8,0xc1,      0x96,0x86,      0x3d,0x50,      0x00,0x51,      0x90,0x52,      0x2c,0x53,      0x00,0x54,      0x00,0x55,      0x88,0x57,      0x00,0x5a,      0x90,0x5b,      0x2C,0x5c,      0x05,//bit2->1;bit[1:0]->10xd3,      0x00,0xe0,      0x00
*////1024*768
//	   0xff,      0x00,
//      0xc0,      0xC8,
//      0xc1,      0x96,
//      0x8c,      0x00,
//      0x86,      0x3D,
//      0x50,      0x00,
//      0x51,      0x90,
//      0x52,      0x2C,
//      0x53,      0x00,
//      0x54,      0x00,
//      0x55,      0x88,
//      0x5a,      0x00,
//      0x5b,      0xC0,
//      0x5c,      0x01,
//      0xd3,      0x02
};const unsigned char OV2640_JPEG_INIT[][2]=
{0xff, 0x00,0x2c, 0xff,0x2e, 0xdf,0xff, 0x01,0x3c, 0x32,0x11, 0x00,0x09, 0x02,0x04, 0x28,0x13, 0xe5,0x14, 0x48,0x2c, 0x0c,0x33, 0x78,0x3a, 0x33,0x3b, 0xfB,0x3e, 0x00,0x43, 0x11,0x16, 0x10,0x39, 0x92,0x35, 0xda,0x22, 0x1a,0x37, 0xc3,0x23, 0x00,0x34, 0xc0,0x36, 0x1a,0x06, 0x88,0x07, 0xc0,0x0d, 0x87,0x0e, 0x41,0x4c, 0x00,0x48, 0x00,0x5B, 0x00,0x42, 0x03,0x4a, 0x81,0x21, 0x99,0x24, 0x40,0x25, 0x38,0x26, 0x82,0x5c, 0x00,0x63, 0x00,0x61, 0x70,0x62, 0x80,0x7c, 0x05,0x20, 0x80,0x28, 0x30,0x6c, 0x00,0x6d, 0x80,0x6e, 0x00,0x70, 0x02,0x71, 0x94,0x73, 0xc1,0x12, 0x40,//0x400x17, 0x11,0x18, 0x43,0x19, 0x00,0x1a, 0x4b,0x32, 0x09,0x37, 0xc0,0x4f, 0x60,0x50, 0xa8,0x6d, 0x00,0x3d, 0x38,0x46, 0x3f,0x4f, 0x60,0x0c, 0x3c,0xff, 0x00,0xe5, 0x7f,0xf9, 0xc0,0x41, 0x24,0xe0, 0x14,0x76, 0xff,0x33, 0xa0,0x42, 0x20,0x43, 0x18,0x4c, 0x00,0x87, 0xd5,0x88, 0x3f,0xd7, 0x03,0xd9, 0x10,0xd3, 0x82,0xc8, 0x08,0xc9, 0x80,0x7c, 0x00,0x7d, 0x00,0x7c, 0x03,0x7d, 0x48,0x7d, 0x48,0x7c, 0x08,0x7d, 0x20,0x7d, 0x10,0x7d, 0x0e,0x90, 0x00,0x91, 0x0e,0x91, 0x1a,0x91, 0x31,0x91, 0x5a,0x91, 0x69,0x91, 0x75,0x91, 0x7e,0x91, 0x88,0x91, 0x8f,0x91, 0x96,0x91, 0xa3,0x91, 0xaf,0x91, 0xc4,0x91, 0xd7,0x91, 0xe8,0x91, 0x20,0x92, 0x00,0x93, 0x06,0x93, 0xe3,0x93, 0x05,0x93, 0x05,0x93, 0x00,0x93, 0x04,0x93, 0x00,0x93, 0x00,0x93, 0x00,0x93, 0x00,0x93, 0x00,0x93, 0x00,0x93, 0x00,0x96, 0x00,0x97, 0x08,0x97, 0x19,0x97, 0x02,0x97, 0x0c,0x97, 0x24,0x97, 0x30,0x97, 0x28,0x97, 0x26,0x97, 0x02,0x97, 0x98,0x97, 0x80,0x97, 0x00,0x97, 0x00,0xc3, 0xed,0xa4, 0x00,0xa8, 0x00,0xc5, 0x11,0xc6, 0x51,0xbf, 0x80,0xc7, 0x10,0xb6, 0x66,0xb8, 0xA5,0xb7, 0x64,0xb9, 0x7C,0xb3, 0xaf,0xb4, 0x97,0xb5, 0xFF,0xb0, 0xC5,0xb1, 0x94,0xb2, 0x0f,0xc4, 0x5c,0xc0, 0x64,0xc1, 0x4B,0x8c, 0x00,0x86, 0x3D,0x50, 0x00,0x51, 0xC8,0x52, 0x96,0x53, 0x00,0x54, 0x00,0x55, 0x00,0x5a, 0xC8,0x5b, 0x96,0x5c, 0x00,0xd3, 0x7f,0xc3, 0xed,0x7f, 0x00,0xda, 0x00,0xe5, 0x1f,0xe1, 0x67,0xe0, 0x00,0xdd, 0x7f,0x05, 0x00,0x12, 0x40,//0x400xd3, 0x7f,0xc0, 0x16,0xC1, 0x12,0x8c, 0x00,0x86, 0x3d,0x50, 0x00,0x51, 0x2C,0x52, 0x24,0x53, 0x00,0x54, 0x00,0x55, 0x00,0x5A, 0x2c,0x5b, 0x24,0x5c, 0x00,
};const unsigned char OV2640_YUV422[][2]= 
{0xFF, 0x00,0x05, 0x00,0xDA, 0x10,0xD7, 0x03,0xDF, 0x00,0x33, 0x80,0x3C, 0x40,0xe1, 0x77,0x00, 0x00,
};const unsigned char OV2640_JPEG[][2]=
{0xe0, 0x14,0xe1, 0x77,0xe5, 0x1f,0xd7, 0x03,0xda, 0x10,0xe0, 0x00,0xFF, 0x01,0x04, 0x08,
};/*** @}*//** @defgroup OV2640_Private_Functions* @{*/ /*** @brief  Camera writes single data.* @param  Addr: I2C address* @param  Reg: Register address * @param  Value: Data to be written* @retval None*/
void DCMI_SingleRandomWrite(uint8_t Reg, uint8_t Data)
{HAL_I2C_Mem_Write(&hi2c2, CAMERA_I2C_ADDRESS, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, &Data, 1, 100); 
}
void CAMERA_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value)
{HAL_I2C_Mem_Write(&hi2c2, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, &Value, 1, 100); 
}/*** @brief  Camera reads single data.* @param  Addr: I2C address* @param  Reg: Register address * @retval Read data*/
uint8_t CAMERA_IO_Read(uint8_t Addr, uint8_t Reg)
{uint8_t Value = 0;HAL_I2C_Mem_Read(&hi2c2, Addr, Reg, I2C_MEMADD_SIZE_8BIT, &Value, 1, 1000);return Value;  
}/*** @brief  Initializes the OV2640 CAMERA component.* @param  DeviceAddr: Device address on communication Bus.* @param  resolution: Camera resolution* @retval None*/
//void ov2640_Init(uint16_t DeviceAddr, uint32_t resolution)
//{
//  uint32_t index;  
//  
//  /* Prepare the camera to be configured */
//  CAMERA_IO_Write(DeviceAddr, OV2640_DSP_RA_DLMT, 0x01);
//  CAMERA_IO_Write(DeviceAddr, OV2640_SENSOR_COM7, 0x80);
//  HAL_Delay(200);//  
//  /* Initialize OV2640 */
//  switch (resolution)
//  {
//  case CAMERA_R160x120:
//    {
//      for(index=0; index<(sizeof(OV2640_QQVGA)/2); index++)
//      {
//        CAMERA_IO_Write(DeviceAddr, OV2640_QQVGA[index][0], OV2640_QQVGA[index][1]);
//        HAL_Delay(1);
//      } 
//      break;
//    }    
//  case CAMERA_R320x240:
//    {
//      for(index=0; index<(sizeof(OV2640_320x240_JPEG)/2); index++)
//      {
//        CAMERA_IO_Write(DeviceAddr, OV2640_320x240_JPEG[index][0], OV2640_320x240_JPEG[index][1]);
//        HAL_Delay(1);
//      } 
//      break;
//    }
//  case CAMERA_R480x272:
//    {
//      for(index=0; index<(sizeof(OV2640_480x272)/2); index++)
//      {
//        CAMERA_IO_Write(DeviceAddr, OV2640_480x272[index][0], OV2640_480x272[index][1]);
//        HAL_Delay(2);
//      }
//      break;
//    }
//  case CAMERA_R640x480:
//    {
//      for(index=0; index<(sizeof(OV2640_VGA)/2); index++)
//      {
//        CAMERA_IO_Write(DeviceAddr, OV2640_VGA[index][0], OV2640_VGA[index][1]);
//        HAL_Delay(2);
//      }
//      break;
//    }    
//  default:
//    {
//      break;
//    }
//  }
//	/* Prepare the sensor to read the Camera ID */
//  CAMERA_IO_Write(DeviceAddr, OV2640_DSP_RA_DLMT, 0x01);
//  
//  /* Get the camera ID */
//  if(CAMERA_IO_Read(DeviceAddr, OV2640_SENSOR_PIDH) == OV2640_ID)
//	{
// 		//printf(" OV2640 ID : 0x%x\r\n",OV2640_ID);
//	}
//	else
//	{
// 		printf(" OV2640 ID is Error!\r\n");
//	}		
//}/*** @brief  Configures the OV2640 camera feature.* @param  DeviceAddr: Device address on communication Bus.* @param  feature: Camera feature to be configured* @param  value: Value to be configured* @param  brightness_value: Brightness value to be configured* @retval None*/
//void ov2640_Config(uint16_t DeviceAddr, uint32_t feature, uint32_t value, uint32_t brightness_value)
//{
//  uint8_t value1, value2;
//  uint32_t value_tmp;
//  uint32_t br_value;
//  
//  /* Convert the input value into ov2640 parameters */
//  value_tmp = ov2640_ConvertValue(feature, value); 
//  br_value = ov2640_ConvertValue(CAMERA_CONTRAST_BRIGHTNESS, brightness_value); 
//    
//  switch(feature)
//  {
//  case CAMERA_BLACK_WHITE:
//    {  
//      CAMERA_IO_Write(DeviceAddr, 0xff, 0x00);
//      CAMERA_IO_Write(DeviceAddr, 0x7c, 0x00);
//      CAMERA_IO_Write(DeviceAddr, 0x7d, value_tmp);
//      CAMERA_IO_Write(DeviceAddr, 0x7c, 0x05);
//      CAMERA_IO_Write(DeviceAddr, 0x7d, 0x80);
//      CAMERA_IO_Write(DeviceAddr, 0x7d, 0x80);
//      break;
//    }
//  case CAMERA_CONTRAST_BRIGHTNESS:
//    {
//      value1 = (uint8_t)(value_tmp);
//      value2 = (uint8_t)(value_tmp >> 8);
//      CAMERA_IO_Write(DeviceAddr, 0xff, 0x00);     
//      CAMERA_IO_Write(DeviceAddr, 0x7c, 0x00);
//      CAMERA_IO_Write(DeviceAddr, 0x7d, 0x04);
//      CAMERA_IO_Write(DeviceAddr, 0x7c, 0x07);
//      CAMERA_IO_Write(DeviceAddr, 0x7d, br_value);
//      CAMERA_IO_Write(DeviceAddr, 0x7d, value1);
//      CAMERA_IO_Write(DeviceAddr, 0x7d, value2);
//      CAMERA_IO_Write(DeviceAddr, 0x7d, 0x06);
//      break;
//    }
//  case CAMERA_COLOR_EFFECT:
//    {     
//      value1 = (uint8_t)(value_tmp);
//      value2 = (uint8_t)(value_tmp >> 8);
//      CAMERA_IO_Write(DeviceAddr, 0xff, 0x00);
//      CAMERA_IO_Write(DeviceAddr, 0x7c, 0x00);
//      CAMERA_IO_Write(DeviceAddr, 0x7d, 0x18);
//      CAMERA_IO_Write(DeviceAddr, 0x7c, 0x05);
//      CAMERA_IO_Write(DeviceAddr, 0x7d, value1);
//      CAMERA_IO_Write(DeviceAddr, 0x7d, value2);
//      break;
//    }     
//  default:
//    {
//      break;
//    }
//  }
//}void OV2640_JPEGConfig(ImageFormat_TypeDef ImageFormat)
{uint32_t i;// ov2640 resetDCMI_SingleRandomWrite(OV2640_DSP_RA_DLMT, 0x01);DCMI_SingleRandomWrite(OV2640_SENSOR_COM7, 0x80);HAL_Delay(200);//for(i=0; i<(sizeof(OV2640_JPEG_INIT)/2); i++){DCMI_SingleRandomWrite(OV2640_JPEG_INIT[i][0], OV2640_JPEG_INIT[i][1]);HAL_Delay(1);}for(i=0; i<(sizeof(OV2640_YUV422)/2); i++){DCMI_SingleRandomWrite(OV2640_YUV422[i][0], OV2640_YUV422[i][1]);HAL_Delay(1);}DCMI_SingleRandomWrite(0xff, 0x01);DCMI_SingleRandomWrite(0x15, 0x00);for(i=0; i<(sizeof(OV2640_JPEG)/2); i++){DCMI_SingleRandomWrite(OV2640_JPEG[i][0], OV2640_JPEG[i][1]);HAL_Delay(1);}HAL_Delay(100);for(i=0; i<(sizeof(OV2640_320x240_JPEG)/2); i++){DCMI_SingleRandomWrite(OV2640_320x240_JPEG[i][0], OV2640_320x240_JPEG[i][1]);HAL_Delay(1);}}
void OV2640_Init(void)
{uint32_t i;DCMI_SingleRandomWrite(OV2640_DSP_RA_DLMT, 0x01);	//操作sensor寄存器DCMI_SingleRandomWrite(OV2640_SENSOR_COM7, 0x80);	//软复位OV2640HAL_Delay(200);//初始化 OV2640,采用SXGA分辨率(1600*1200)for(i=0;i<sizeof(ov2640_uxga_init_reg_tbl)/2;i++){DCMI_SingleRandomWrite(ov2640_uxga_init_reg_tbl[i][0],ov2640_uxga_init_reg_tbl[i][1]);HAL_Delay(1);}
}
void OV2640_RGB565_Mode(void)
{uint16_t i=0;//设置:RGB565输出for(i=0;i<(sizeof(ov2640_rgb565_reg_tbl)/2);i++){DCMI_SingleRandomWrite(ov2640_rgb565_reg_tbl[i][0],ov2640_rgb565_reg_tbl[i][1]);HAL_Delay(1);}
}
void OV2640_JPEG_Mode(void)
{uint16_t i=0;//设置:YUV422格式for(i=0;i<(sizeof(ov2640_yuv422_reg_tbl)/2);i++){DCMI_SingleRandomWrite(ov2640_yuv422_reg_tbl[i][0],ov2640_yuv422_reg_tbl[i][1]);HAL_Delay(1);}//设置:输出JPEG数据for(i=0;i<(sizeof(ov2640_jpeg_reg_tbl)/2);i++){DCMI_SingleRandomWrite(ov2640_jpeg_reg_tbl[i][0],ov2640_jpeg_reg_tbl[i][1]);HAL_Delay(1);}
}
//设置图像输出大小
//OV2640输出图像的大小(分辨率),完全由该函数确定
//width,height:宽度(对应:horizontal)和高度(对应:vertical),width和height必须是4的倍数
//返回值:0,设置成功
//    其他,设置失败
uint8_t OV2640_OutSize_Set(uint16_t width,uint16_t height)
{uint16_t outh;uint16_t outw;uint8_t temp;if(width%4)return 1;if(height%4)return 2;outw=width/4;outh=height/4;DCMI_SingleRandomWrite(0XFF,0X00);DCMI_SingleRandomWrite(0XE0,0X04);DCMI_SingleRandomWrite(0X5A,outw&0XFF);		//设置OUTW的低八位DCMI_SingleRandomWrite(0X5B,outh&0XFF);		//设置OUTH的低八位temp=(outw>>8)&0X03;temp|=(outh>>6)&0X04;DCMI_SingleRandomWrite(0X5C,temp);				//设置OUTH/OUTW的高位DCMI_SingleRandomWrite(0XE0,0X00);return 0;
}
void SCCB_WriteRegs(const uint8_t* pbuf)
{while(1){if((*pbuf == 0) && (*(pbuf + 1) == 0)){break;}else{DCMI_SingleRandomWrite(*pbuf++, *pbuf++);}}
}const static uint8_t OV2640_AUTOEXPOSURE_LEVEL0[]=
{0xFF,	0x01,	0xff,0x24,	0x20,	0xff,0x25,	0x18,	0xff,0x26,	0x60,	0xff,0x00,	0x00,	0x00
};const static uint8_t OV2640_AUTOEXPOSURE_LEVEL1[]=
{0xFF,	0x01,	0xff,0x24,	0x34,	0xff,0x25,	0x1c,	0xff,0x26,	0x70,	0xff,0x00,	0x00,	0x00
};
const static uint8_t OV2640_AUTOEXPOSURE_LEVEL2[]=
{0xFF,	0x01,	0xff,0x24,	0x3e,	0xff,0x25,	0x38,	0xff,0x26,	0x81,	0xff,0x00,	0x00,	0x00
};
const static uint8_t OV2640_AUTOEXPOSURE_LEVEL3[]=
{0xFF,	0x01,	0xff,0x24,	0x48,	0xff,0x25,	0x40,	0xff,0x26,	0x81,	0xff,0x00,	0x00,	0x00
};
const static uint8_t OV2640_AUTOEXPOSURE_LEVEL4[]=
{0xFF,	0x01,	0xff,0x24,	0x58,	0xff,0x25,	0x50,	0xff,0x26,	0x92,	0xff,0x00,	0x00,	0x00
};void OV2640_AutoExposure(uint8_t level)
{switch(level){case 0:SCCB_WriteRegs(OV2640_AUTOEXPOSURE_LEVEL0);break;case 1:SCCB_WriteRegs(OV2640_AUTOEXPOSURE_LEVEL1);break;case 2:SCCB_WriteRegs(OV2640_AUTOEXPOSURE_LEVEL2);break;case 3:SCCB_WriteRegs(OV2640_AUTOEXPOSURE_LEVEL3);break;case 4:SCCB_WriteRegs(OV2640_AUTOEXPOSURE_LEVEL4);break;default:SCCB_WriteRegs(OV2640_AUTOEXPOSURE_LEVEL0);break;}}void OV2640_BrightnessConfig(uint8_t Brightness)
{DCMI_SingleRandomWrite(0xff, 0x00);DCMI_SingleRandomWrite(0x7c, 0x00);DCMI_SingleRandomWrite(0x7d, 0x04);DCMI_SingleRandomWrite(0x7c, 0x09);DCMI_SingleRandomWrite(0x7d, Brightness);DCMI_SingleRandomWrite(0x7d, 0x00);
}/*** @}*/ /*** @}*/ /*** @}*/ /*** @}*/  /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

 

4.2 ov2640.h

 

/********************************************************************************* @file    ov2640.h* @author  MCD Application Team* @version V1.0.2* @date    02-December-2014* @brief   This file contains all the functions prototypes for the ov2640.c*          driver.******************************************************************************* @attention** <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>** Redistribution and use in source and binary forms, with or without modification,* are permitted provided that the following conditions are met:*   1. Redistributions of source code must retain the above copyright notice,*      this list of conditions and the following disclaimer.*   2. Redistributions in binary form must reproduce the above copyright notice,*      this list of conditions and the following disclaimer in the documentation*      and/or other materials provided with the distribution.*   3. Neither the name of STMicroelectronics nor the names of its contributors*      may be used to endorse or promote products derived from this software*      without specific prior written permission.** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.********************************************************************************/ /* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __OV2640_H
#define __OV2640_H#ifdef __cplusplusextern "C" {
#endif /* Includes ------------------------------------------------------------------*/
#include "stm32f4xx_hal.h"
//#include "../BSP/camera.h"/** @addtogroup BSP* @{*/ /** @addtogroup Components* @{*/ /** @addtogroup ov2640* @{*//** @defgroup OV2640_Exported_Types* @{*/
typedef enum   
{BMP_QQVGA             =   0x00,	    /* BMP Image QQVGA 160x120 Size */BMP_QVGA              =   0x01,           /* BMP Image QVGA 320x240 Size */JPEG_160x120          =   0x02,	    /* JPEG Image 160x120 Size */JPEG_176x144          =   0x03,	    /* JPEG Image 176x144 Size */JPEG_320x240          =   0x04,	    /* JPEG Image 320x240 Size */JPEG_352x288          =   0x05	    /* JPEG Image 352x288 Size */
}ImageFormat_TypeDef;/* Exported types ------------------------------------------------------------*/
typedef struct
{uint8_t Manufacturer_ID1;uint8_t Manufacturer_ID2;uint8_t Version;uint8_t PID; 
}OV2640_IDTypeDef;      
/*** @}*/ /** @defgroup OV2640_Exported_Constants* @{*/
#define CAMERA_I2C_ADDRESS              0x60
/** * @brief  OV2640 ID  */  
#define  OV2640_ID    0x26
/** * @brief  OV2640 Registers  */
/* OV2640 Registers definition when DSP bank selected (0xFF = 0x00) */
#define OV2640_DSP_R_BYPASS             0x05
#define OV2640_DSP_Qs                   0x44
#define OV2640_DSP_CTRL                 0x50
#define OV2640_DSP_HSIZE1               0x51
#define OV2640_DSP_VSIZE1               0x52
#define OV2640_DSP_XOFFL                0x53
#define OV2640_DSP_YOFFL                0x54
#define OV2640_DSP_VHYX                 0x55
#define OV2640_DSP_DPRP                 0x56
#define OV2640_DSP_TEST                 0x57
#define OV2640_DSP_ZMOW                 0x5A
#define OV2640_DSP_ZMOH                 0x5B
#define OV2640_DSP_ZMHH                 0x5C
#define OV2640_DSP_BPADDR               0x7C
#define OV2640_DSP_BPDATA               0x7D
#define OV2640_DSP_CTRL2                0x86
#define OV2640_DSP_CTRL3                0x87
#define OV2640_DSP_SIZEL                0x8C
#define OV2640_DSP_HSIZE2               0xC0
#define OV2640_DSP_VSIZE2               0xC1
#define OV2640_DSP_CTRL0                0xC2
#define OV2640_DSP_CTRL1                0xC3
#define OV2640_DSP_R_DVP_SP             0xD3
#define OV2640_DSP_IMAGE_MODE           0xDA
#define OV2640_DSP_RESET                0xE0
#define OV2640_DSP_MS_SP                0xF0
#define OV2640_DSP_SS_ID                0x7F
#define OV2640_DSP_SS_CTRL              0xF8
#define OV2640_DSP_MC_BIST              0xF9
#define OV2640_DSP_MC_AL                0xFA
#define OV2640_DSP_MC_AH                0xFB
#define OV2640_DSP_MC_D                 0xFC
#define OV2640_DSP_P_STATUS             0xFE
#define OV2640_DSP_RA_DLMT              0xFF/* OV2640 Registers definition when sensor bank selected (0xFF = 0x01) */
#define OV2640_SENSOR_GAIN              0x00
#define OV2640_SENSOR_COM1              0x03
#define OV2640_SENSOR_REG04             0x04
#define OV2640_SENSOR_REG08             0x08
#define OV2640_SENSOR_COM2              0x09
#define OV2640_SENSOR_PIDH              0x0A
#define OV2640_SENSOR_PIDL              0x0B
#define OV2640_SENSOR_COM3              0x0C
#define OV2640_SENSOR_COM4              0x0D
#define OV2640_SENSOR_AEC               0x10
#define OV2640_SENSOR_CLKRC             0x11
#define OV2640_SENSOR_COM7              0x12
#define OV2640_SENSOR_COM8              0x13
#define OV2640_SENSOR_COM9              0x14
#define OV2640_SENSOR_COM10             0x15
#define OV2640_SENSOR_HREFST            0x17
#define OV2640_SENSOR_HREFEND           0x18
#define OV2640_SENSOR_VSTART            0x19
#define OV2640_SENSOR_VEND              0x1A
#define OV2640_SENSOR_MIDH              0x1C
#define OV2640_SENSOR_MIDL              0x1D
#define OV2640_SENSOR_AEW               0x24
#define OV2640_SENSOR_AEB               0x25
#define OV2640_SENSOR_W                 0x26
#define OV2640_SENSOR_REG2A             0x2A
#define OV2640_SENSOR_FRARL             0x2B
#define OV2640_SENSOR_ADDVSL            0x2D
#define OV2640_SENSOR_ADDVHS            0x2E
#define OV2640_SENSOR_YAVG              0x2F
#define OV2640_SENSOR_REG32             0x32
#define OV2640_SENSOR_ARCOM2            0x34
#define OV2640_SENSOR_REG45             0x45
#define OV2640_SENSOR_FLL               0x46
#define OV2640_SENSOR_FLH               0x47
#define OV2640_SENSOR_COM19             0x48
#define OV2640_SENSOR_ZOOMS             0x49
#define OV2640_SENSOR_COM22             0x4B
#define OV2640_SENSOR_COM25             0x4E
#define OV2640_SENSOR_BD50              0x4F
#define OV2640_SENSOR_BD60              0x50
#define OV2640_SENSOR_REG5D             0x5D
#define OV2640_SENSOR_REG5E             0x5E
#define OV2640_SENSOR_REG5F             0x5F
#define OV2640_SENSOR_REG60             0x60
#define OV2640_SENSOR_HISTO_LOW         0x61
#define OV2640_SENSOR_HISTO_HIGH        0x62 /** * @brief  OV2640 Features Parameters  */
#define OV2640_BRIGHTNESS_LEVEL0        0x40   /* Brightness level -2         */
#define OV2640_BRIGHTNESS_LEVEL1        0x30   /* Brightness level -1         */
#define OV2640_BRIGHTNESS_LEVEL2        0x20   /* Brightness level 0          */
#define OV2640_BRIGHTNESS_LEVEL3        0x10   /* Brightness level +1         */
#define OV2640_BRIGHTNESS_LEVEL4        0x00   /* Brightness level +2         */#define OV2640_BLACK_WHITE_BW           0x18   /* Black and white effect      */
#define OV2640_BLACK_WHITE_NEGATIVE     0x40   /* Negative effect             */
#define OV2640_BLACK_WHITE_BW_NEGATIVE  0x58   /* BW and Negative effect      */
#define OV2640_BLACK_WHITE_NORMAL       0x00   /* Normal effect               */#define OV2640_CONTRAST_LEVEL0          0x3418 /* Contrast level -2           */
#define OV2640_CONTRAST_LEVEL1          0x2A1C /* Contrast level -2           */
#define OV2640_CONTRAST_LEVEL2          0x2020 /* Contrast level -2           */
#define OV2640_CONTRAST_LEVEL3          0x1624 /* Contrast level -2           */
#define OV2640_CONTRAST_LEVEL4          0x0C28 /* Contrast level -2           */#define OV2640_COLOR_EFFECT_ANTIQUE     0xA640 /* Antique effect              */
#define OV2640_COLOR_EFFECT_BLUE        0x40A0 /* Blue effect                 */
#define OV2640_COLOR_EFFECT_GREEN       0x4040 /* Green effect                */
#define OV2640_COLOR_EFFECT_RED         0xC040 /* Red effect                  */   
/*** @}*//** @defgroup OV2640_Exported_Functions* @{*/ void     ov2640_Config(uint16_t DeviceAddr, uint32_t feature, uint32_t value, uint32_t BR_value);
void OV2640_JPEGConfig(ImageFormat_TypeDef ImageFormat);
void OV2640_BrightnessConfig(uint8_t Brightness);
void OV2640_AutoExposure(uint8_t level);void OV2640_Init(void);
void OV2640_RGB565_Mode(void);
void OV2640_JPEG_Mode(void);
uint8_t OV2640_OutSize_Set(uint16_t width,uint16_t height);/* I2C_HandleTypeDef structure */
extern I2C_HandleTypeDef hi2c2;/*** @}*/    
#ifdef __cplusplus
}
#endif#endif /* __OV2640_H */
/*** @}*/ /*** @}*/ /*** @}*/ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

4.3 ov2640cfg.h

 

#ifndef _OV2640CFG_H
#define _OV2640CFG_H
#include "ov2640.h" //OV2640 UXG Register configuration
//frame rate: 15
//UXGA(1600*1200) 
const uint8_t ov2640_uxga_init_reg_tbl[][2]=
{   0xff, 0x00,0x2c, 0xff,0x2e, 0xdf,0xff, 0x01,0x3c, 0x32,//0x11, 0x00,0x09, 0x02,0x04, 0xD8,//horizon mirror, vertical rotate0x13, 0xe5,0x14, 0x48,0x2c, 0x0c,0x33, 0x78,0x3a, 0x33,0x3b, 0xfB,//0x3e, 0x00,0x43, 0x11,0x16, 0x10,//0x39, 0x92,//0x35, 0xda,0x22, 0x1a,0x37, 0xc3,0x23, 0x00,0x34, 0xc0,0x36, 0x1a,0x06, 0x88,0x07, 0xc0,0x0d, 0x87,0x0e, 0x41,0x4c, 0x00,0x48, 0x00,0x5B, 0x00,0x42, 0x03,//0x4a, 0x81,0x21, 0x99,//0x24, 0x40,0x25, 0x38,0x26, 0x82,0x5c, 0x00,0x63, 0x00,0x46, 0x00,0x0c, 0x3c,//0x61, 0x70,0x62, 0x80,0x7c, 0x05,//0x20, 0x80,0x28, 0x30,0x6c, 0x00,0x6d, 0x80,0x6e, 0x00,0x70, 0x02,0x71, 0x94,0x73, 0xc1, 0x3d, 0x34, 0x5a, 0x57,//0x12, 0x00,//UXGA 1600*12000x17, 0x11,0x18, 0x75,0x19, 0x01,0x1a, 0x97,0x32, 0x36,0x03, 0x0f, 0x37, 0x40,// 0x4f, 0xca,0x50, 0xa8,0x5a, 0x23,0x6d, 0x00,0x6d, 0x38,//0xff, 0x00,0xe5, 0x7f,0xf9, 0xc0,0x41, 0x24,0xe0, 0x14,0x76, 0xff,0x33, 0xa0,0x42, 0x20,0x43, 0x18,0x4c, 0x00,0x87, 0xd5,0x88, 0x3f,0xd7, 0x03,0xd9, 0x10,0xd3, 0x82,//0xc8, 0x08,0xc9, 0x80,//0x7c, 0x00,0x7d, 0x00,0x7c, 0x03,0x7d, 0x48,0x7d, 0x48,0x7c, 0x08,0x7d, 0x20,0x7d, 0x10,0x7d, 0x0e,//0x90, 0x00,0x91, 0x0e,0x91, 0x1a,0x91, 0x31,0x91, 0x5a,0x91, 0x69,0x91, 0x75,0x91, 0x7e,0x91, 0x88,0x91, 0x8f,0x91, 0x96,0x91, 0xa3,0x91, 0xaf,0x91, 0xc4,0x91, 0xd7,0x91, 0xe8,0x91, 0x20,//0x92, 0x00,0x93, 0x06,0x93, 0xe3,0x93, 0x05,0x93, 0x05,0x93, 0x00,0x93, 0x04,0x93, 0x00,0x93, 0x00,0x93, 0x00,0x93, 0x00,0x93, 0x00,0x93, 0x00,0x93, 0x00,//0x96, 0x00,0x97, 0x08,0x97, 0x19,0x97, 0x02,0x97, 0x0c,0x97, 0x24,0x97, 0x30,0x97, 0x28,0x97, 0x26,0x97, 0x02,0x97, 0x98,0x97, 0x80,0x97, 0x00,0x97, 0x00,//0xc3, 0xef,0xa4, 0x00,0xa8, 0x00,0xc5, 0x11,0xc6, 0x51,0xbf, 0x80,0xc7, 0x10,0xb6, 0x66,0xb8, 0xA5,0xb7, 0x64,0xb9, 0x7C,0xb3, 0xaf,0xb4, 0x97,0xb5, 0xFF,0xb0, 0xC5,0xb1, 0x94,0xb2, 0x0f,0xc4, 0x5c,//0xc0, 0xc8,0xc1, 0x96,0x8c, 0x00,0x86, 0x3d,0x50, 0x00,0x51, 0x90,0x52, 0x2c,0x53, 0x00,0x54, 0x00,0x55, 0x88,0x5a, 0x90,0x5b, 0x2C,0x5c, 0x05,0xd3, 0x02,	//auto setting should be careful//0xc3, 0xed,0x7f, 0x00,0xda, 0x09,0xe5, 0x1f,0xe1, 0x67,0xe0, 0x00,0xdd, 0x7f,0x05, 0x00,
};  
//OV2640 SVGA register configuration
//data frame rate: 30
//SVGA 800*600
const uint8_t ov2640_svga_init_reg_tbl[][2]=
{    0xff, 0x00,0x2c, 0xff,0x2e, 0xdf,0xff, 0x01,0x3c, 0x32,//0x11, 0x00,0x09, 0x02,0x04, 0xD8,//horizon mirror, vertical rotate0x13, 0xe5,0x14, 0x48,0x2c, 0x0c,0x33, 0x78,0x3a, 0x33,0x3b, 0xfB,//0x3e, 0x00,0x43, 0x11,0x16, 0x10,//0x39, 0x92,//0x35, 0xda,0x22, 0x1a,0x37, 0xc3,0x23, 0x00,0x34, 0xc0,0x36, 0x1a,0x06, 0x88,0x07, 0xc0,0x0d, 0x87,0x0e, 0x41,0x4c, 0x00,0x48, 0x00,0x5B, 0x00,0x42, 0x03,//0x4a, 0x81,0x21, 0x99,//0x24, 0x40,0x25, 0x38,0x26, 0x82,0x5c, 0x00,0x63, 0x00,0x46, 0x22,0x0c, 0x3c,//0x61, 0x70,0x62, 0x80,0x7c, 0x05,//0x20, 0x80,0x28, 0x30,0x6c, 0x00,0x6d, 0x80,0x6e, 0x00,0x70, 0x02,0x71, 0x94,0x73, 0xc1,0x3d, 0x34, 0x5a, 0x57,0x12, 0x40,//SVGA 800*6000x17, 0x11,0x18, 0x43,0x19, 0x00,0x1a, 0x4b,0x32, 0x09,0x37, 0xc0,//0x4f, 0xca,0x50, 0xa8,0x5a, 0x23,0x6d, 0x00,0x3d, 0x38,//0xff, 0x00,0xe5, 0x7f,0xf9, 0xc0,0x41, 0x24,0xe0, 0x14,0x76, 0xff,0x33, 0xa0,0x42, 0x20,0x43, 0x18,0x4c, 0x00,0x87, 0xd5,0x88, 0x3f,0xd7, 0x03,0xd9, 0x10,0xd3, 0x82,//0xc8, 0x08,0xc9, 0x80,//0x7c, 0x00,0x7d, 0x00,0x7c, 0x03,0x7d, 0x48,0x7d, 0x48,0x7c, 0x08,0x7d, 0x20,0x7d, 0x10,0x7d, 0x0e,//0x90, 0x00,0x91, 0x0e,0x91, 0x1a,0x91, 0x31,0x91, 0x5a,0x91, 0x69,0x91, 0x75,0x91, 0x7e,0x91, 0x88,0x91, 0x8f,0x91, 0x96,0x91, 0xa3,0x91, 0xaf,0x91, 0xc4,0x91, 0xd7,0x91, 0xe8,0x91, 0x20,//0x92, 0x00,0x93, 0x06,0x93, 0xe3,0x93, 0x05,0x93, 0x05,0x93, 0x00,0x93, 0x04,0x93, 0x00,0x93, 0x00,0x93, 0x00,0x93, 0x00,0x93, 0x00,0x93, 0x00,0x93, 0x00,//0x96, 0x00,0x97, 0x08,0x97, 0x19,0x97, 0x02,0x97, 0x0c,0x97, 0x24,0x97, 0x30,0x97, 0x28,0x97, 0x26,0x97, 0x02,0x97, 0x98,0x97, 0x80,0x97, 0x00,0x97, 0x00,//0xc3, 0xed,0xa4, 0x00,0xa8, 0x00,0xc5, 0x11,0xc6, 0x51,0xbf, 0x80,0xc7, 0x10,0xb6, 0x66,0xb8, 0xA5,0xb7, 0x64,0xb9, 0x7C,0xb3, 0xaf,0xb4, 0x97,0xb5, 0xFF,0xb0, 0xC5,0xb1, 0x94,0xb2, 0x0f,0xc4, 0x5c,0xc0, 0x64,0xc1, 0x4B,0x8c, 0x00,0x86, 0x3D,0x50, 0x00,0x51, 0xC8,0x52, 0x96,0x53, 0x00,0x54, 0x00,0x55, 0x00,0x5a, 0xC8,0x5b, 0x96,0x5c, 0x00,0xd3, 0x02,//0xc3, 0xed,0x7f, 0x00,0xda, 0x09,0xe5, 0x1f,0xe1, 0x67,0xe0, 0x00,0xdd, 0x7f,0x05, 0x00,
};   
const uint8_t ov2640_yuv422_reg_tbl[][2]=
{0xFF, 0x00, 0xDA, 0x10,0xD7, 0x03,0xDF, 0x00,0x33, 0x80,0x3C, 0x40,0xe1, 0x77,0x00, 0x00,
};
const uint8_t ov2640_jpeg_reg_tbl[][2]=
{0xff, 0x01, 0xe0, 0x14,0xe1, 0x77,0xe5, 0x1f,0xd7, 0x03,0xda, 0x10,0xe0, 0x00, 
};
const uint8_t ov2640_rgb565_reg_tbl[][2]=
{0xFF, 0x00,0xDA, 0x09,0xD7, 0x03,0xDF, 0x02,0x33, 0xa0,0x3C, 0x00,0xe1, 0x67,0xff, 0x01, 0xe0, 0x00,0xe1, 0x00,0xe5, 0x00,0xd7, 0x00, 0xda, 0x00,0xe0, 0x00,  
}; 
#endif

 

 4.4 main.c

 


/* USER CODE BEGIN PV */#define nWidth_raw	320
#define nHeight_raw	180#define DEF_DcmiDmaRxBuff_Size nWidth_raw*nHeight_raw*2uint8_t a_DcmiDmaRxBuff[DEF_DcmiDmaRxBuff_Size];/* USER CODE END PV *//* USER CODE BEGIN 2 */OV2640_Init();OV2640_RGB565_Mode();//OV2640_JPEG_Mode();OV2640_OutSize_Set(nWidth_raw, nHeight_raw);/* USER CODE END 2 *//* Infinite loop *//* USER CODE BEGIN WHILE */while (1){if(HAL_GPIO_ReadPin(CTR_GPIO_Port, CTR_Pin) == GPIO_PIN_RESET){HAL_Delay(10);if(HAL_GPIO_ReadPin(CTR_GPIO_Port, CTR_Pin) == GPIO_PIN_RESET){HAL_DCMI_Stop(&hdcmi);HAL_UART_DMAStop(&huart3);MX_DCMI_Init();__HAL_DCMI_ENABLE_IT(&hdcmi, DCMI_IT_FRAME);//__HAL_DCMI_ENABLE_IT(&hdcmi, DCMI_IT_OVR);HAL_DCMI_Start_DMA(&hdcmi, DCMI_MODE_SNAPSHOT,(uint32_t)a_DcmiDmaRxBuff, DEF_DcmiDmaRxBuff_Size);}while(HAL_GPIO_ReadPin(CTR_GPIO_Port, CTR_Pin) == GPIO_PIN_RESET);}if(getPicture == 1){getPicture = 0;uint32_t temp;HAL_DCMI_Stop(&hdcmi);temp = __HAL_DMA_GET_COUNTER(&hdma_dcmi);b_DcmiDmaRxBuff_Cnt =  DEF_DcmiDmaRxBuff_Size - temp;while(a_DcmiDmaRxBuff[b_DcmiDmaRxBuff_Cnt-1]==0){b_DcmiDmaRxBuff_Cnt--;}HAL_UART_Transmit_LargeArray(&huart3, a_DcmiDmaRxBuff, DEF_DcmiDmaRxBuff_Size, HAL_MAX_DELAY);for(i=0;i<b_DcmiDmaRxBuff_Cnt;i++){a_DcmiDmaRxBuff[i] = 0;}b_DcmiDmaRxBuff_Cnt = 0;}/* USER CODE END WHILE *//* USER CODE BEGIN 3 */}/* USER CODE END 3 */void HAL_UART_Transmit_LargeArray(UART_HandleTypeDef *huart, uint8_t *pData, uint32_t Size, uint32_t Timeout)
{uint32_t b_TxCnt = 0;while(b_TxCnt<Size){if((Size-b_TxCnt)>=20000){HAL_UART_Transmit(huart, pData+ b_TxCnt, 20000, Timeout);b_TxCnt += 20000;}else{HAL_UART_Transmit(huart, pData+ b_TxCnt, (Size-b_TxCnt), Timeout);b_TxCnt+=(Size-b_TxCnt);}}
}

 如果需要jpg格式,那么

OV2640_Init();//OV2640_RGB565_Mode();OV2640_JPEG_Mode();OV2640_OutSize_Set(nWidth_raw, nHeight_raw);

这里的ov2640_outsize_set函数可以设置想要的图片大小。这个函数在RAM有限的情况下很有用。

这篇关于STM32F4驱动OV2640获取JPG图片和RGB565格式图片-下位机的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/525041

相关文章

5分钟获取deepseek api并搭建简易问答应用

《5分钟获取deepseekapi并搭建简易问答应用》本文主要介绍了5分钟获取deepseekapi并搭建简易问答应用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需... 目录1、获取api2、获取base_url和chat_model3、配置模型参数方法一:终端中临时将加

C#实现添加/替换/提取或删除Excel中的图片

《C#实现添加/替换/提取或删除Excel中的图片》在Excel中插入与数据相关的图片,能将关键数据或信息以更直观的方式呈现出来,使文档更加美观,下面我们来看看如何在C#中实现添加/替换/提取或删除E... 在Excandroidel中插入与数据相关的图片,能将关键数据或信息以更直观的方式呈现出来,使文档更

C#实现系统信息监控与获取功能

《C#实现系统信息监控与获取功能》在C#开发的众多应用场景中,获取系统信息以及监控用户操作有着广泛的用途,比如在系统性能优化工具中,需要实时读取CPU、GPU资源信息,本文将详细介绍如何使用C#来实现... 目录前言一、C# 监控键盘1. 原理与实现思路2. 代码实现二、读取 CPU、GPU 资源信息1.

在C#中获取端口号与系统信息的高效实践

《在C#中获取端口号与系统信息的高效实践》在现代软件开发中,尤其是系统管理、运维、监控和性能优化等场景中,了解计算机硬件和网络的状态至关重要,C#作为一种广泛应用的编程语言,提供了丰富的API来帮助开... 目录引言1. 获取端口号信息1.1 获取活动的 TCP 和 UDP 连接说明:应用场景:2. 获取硬

Python MySQL如何通过Binlog获取变更记录恢复数据

《PythonMySQL如何通过Binlog获取变更记录恢复数据》本文介绍了如何使用Python和pymysqlreplication库通过MySQL的二进制日志(Binlog)获取数据库的变更记录... 目录python mysql通过Binlog获取变更记录恢复数据1.安装pymysqlreplicat

IDEA如何将String类型转json格式

《IDEA如何将String类型转json格式》在Java中,字符串字面量中的转义字符会被自动转换,但通过网络获取的字符串可能不会自动转换,为了解决IDEA无法识别JSON字符串的问题,可以在本地对字... 目录问题描述问题原因解决方案总结问题描述最近做项目需要使用Ai生成json,可生成String类型

C#实现获取电脑中的端口号和硬件信息

《C#实现获取电脑中的端口号和硬件信息》这篇文章主要为大家详细介绍了C#实现获取电脑中的端口号和硬件信息的相关方法,文中的示例代码讲解详细,有需要的小伙伴可以参考一下... 我们经常在使用一个串口软件的时候,发现软件中的端口号并不是普通的COM1,而是带有硬件信息的。那么如果我们使用C#编写软件时候,如

C#中图片如何自适应pictureBox大小

《C#中图片如何自适应pictureBox大小》文章描述了如何在C#中实现图片自适应pictureBox大小,并展示修改前后的效果,修改步骤包括两步,作者分享了个人经验,希望对大家有所帮助... 目录C#图片自适应pictureBox大小编程修改步骤总结C#图片自适应pictureBox大小上图中“z轴

C#实现WinForm控件焦点的获取与失去

《C#实现WinForm控件焦点的获取与失去》在一个数据输入表单中,当用户从一个文本框切换到另一个文本框时,需要准确地判断焦点的转移,以便进行数据验证、提示信息显示等操作,本文将探讨Winform控件... 目录前言获取焦点改变TabIndex属性值调用Focus方法失去焦点总结最后前言在一个数据输入表单

使用Python将长图片分割为若干张小图片

《使用Python将长图片分割为若干张小图片》这篇文章主要为大家详细介绍了如何使用Python将长图片分割为若干张小图片,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1. python需求的任务2. Python代码的实现3. 代码修改的位置4. 运行结果1. Python需求