cancel
Showing results for 
Search instead for 
Did you mean: 

Interfacing STM32F401 with OV7670 camera: scrambled images

MCarp
Associate

Hello everyone,

I am trying to interface my STM32F401RE with OV7670 camera. I have set the input clock for the camera from the MCO output of the board at 8MHz. Because my board is not provided with DCMI, I have to explicitly implement the communication protocol of the camera. Apparently I am able to get an image, but it seems more noise than real data. I send the data from the MCU to my PC via UART to check the image with an external software, which is working if I test it with predefined values (eg sending always zero from MCU results in a full black image). The camera registers also seem correctly set , just looking at their content after writing. I suspect about subtle timing problems that prevent me from getting the image. I retrieve the 8 bits of data from the camera by reading the GPIOx IDR register.

Here is the code involved in reading the image.

while (!(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_11) == GPIO_PIN_SET)); //wait for high VSYNC
 while ((HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_11) == GPIO_PIN_SET));  //wait for low VSYNC
 
  y = height;
  while (y--){
    x = width;
    while (x--){
      while ((HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_9) == GPIO_PIN_SET)); //wait for low PCLK
      data  = (uint16_t)GPIOB->IDR & 0x00ff;	// read port B to get input from camera
      effective_data = (uint8_t)data;			// only the last 8 bits contain my data
      HAL_UART_Transmit(&huart2, (uint8_t *)effective_data, 1, 10);
      data = 0;
      effective_data = 0;
      while (!(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_9) == GPIO_PIN_SET));  //wait for high PCLK
      while ((HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_9) == GPIO_PIN_SET));   //wait for low PCLK
      while (!(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_9) == GPIO_PIN_SET));//wait for high PCLK
    }
  }

0 REPLIES 0