Docs

Micro-controllers, wireless transmission and database

Head

OV7670 Camera /ST7735 Display with STM32F407VET6 using STM32CubeIDE

STM32CubeIDE Settings

Click RCC → High Speed Clock (HSE) to Crystal/Ceramic Resonator

(Tick) Master Clock Output 1

Configuration → GPIO Settings → Select PA8 Maximum Output Speed to Very High

Click Clock Configuration tab → HSE Input Frequency 8

Select HSE & Select PLLCLK → HCLK (MHz) to 168

MCO1 Source MUX → Select PLLCLK → and /4 to get speed 42MHz OR

MCO1 Source MUX → Select HSE → and /1 to get speed 8MHz OR

MCO1 Source MUX → Select HSI → and /1 to get speed 16MHz

Click Pinout and Configuration tab


Click connectivity → Click I2C2

For I2C select I2C

Configuration → GPIO Settings → Select PB10 and PB11 → GPIO pullup


Click connectivity → Click SPI1

For Mode select Half-Duplex Master

Configuration → Parameter Settings

Change prescalar (for Baud rate) to 16

Set PB0, PC4 AND PC5 to GPIO_Output


Click Multimedia → Click DCMI

DCMI → Slave 8 bits external Synchro

Configuration → Parameter Settings

Pixel clock polarity → Active on rising edge

Vertical syncronisation polarity → Active High

Configuration → GPIO Settings → Select All pins

GPIO Pull down & Maximum output speed to Very High

Configuration → DMA Settings → Click add button → Select DCMI → uncheck memory

Configuration → NVIC Settings → DCMI global interrupt (Tick)

Move DCMI_D4 from PE4 to PC11

Move DCMI_D6 from PE5 to PB8

Move DCMI_D7 from PE6 to PB9

Set PD11 and PD12 to GPIO_Output

Set PD11 User lable to CAMERA_RESET


Libraries

Taken from https://github.com/iwatake2222/DigitalCamera_STM32

Inside Core/Inc Folder

common.h

st7735.h

ov7670.h

ov7670Config.h

ov7670Reg.h

Inside Core/Src Folder

st7735.c

ov7670.c

Additional code on top of STM32CubeIDE generated code

/* USER CODE BEGIN Includes */
#include "common.h"
#include "ov7670.h"
#include "st7735.h"
/* USER CODE END Includes */

/* USER CODE BEGIN PV */
#define MAX_PICTURE_BUFF     19200
uint16_t pBuffer[MAX_PICTURE_BUFF];
/* USER CODE END PV */

  /* USER CODE BEGIN 2 */
  ST7735_Init();
  ST7735_FillScreen(ST7735_BLACK);
  ST7735_FillRectangle(10, 10, 108, 140, ST7735_RED); // Test the display
  HAL_Delay(1000);
  HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, GPIO_PIN_RESET); //Camera PWDN to GND
  ov7670_init(&hdcmi, &hdma_dcmi, &hi2c2);
  ov7670_config(OV7670_MODE_QVGA_RGB565);
  ov7670_stopCap();
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    HAL_DCMI_Start_DMA(&hdcmi, DCMI_MODE_SNAPSHOT, pBuffer, MAX_PICTURE_BUFF/2);
    HAL_Delay(100);  //Wait for DMA to complete
    // picture pBuffer size 120*160=19200 is now available, we can transmit
    // or display in lcd as shown below
    int pixel = 0;
    for( int x = 0; x < 120; x++ )
    {
      for( int y = 159; y > -1; y-- )
      {
        ST7735_DrawPixel(x, y, pBuffer[pixel]);
        pixel++;
      }
    }
    /* USER CODE END WHILE */