2019-07-23 07:33 AM
I have to interface my STM32F401RE with an OV7670 camera module without external AL422. My aim is to be able to capture an image on request, so I tried to adapt the code structure used for one of the many Arduino tutorial to my board and HAL library but the results are quite frustrating because all I could get are messy noisy images, like these
At the moment what my code does is taking an image and send it via UART where a Java application is listening the COM port and shows the image. Some more details:
I am almost sure that there is some problem in reading signals correctly according the camera timing but I really cannot spot the problem, also because I haven't an oscilloscope to help me. In my current settings PCLK does not toggle during horizontal blanking. The main function to capture the image is the following (almost the same that can be found surfing the net):
int camera_capture_image(uint8_t image_buffer[][2*COLS]) {
uint16_t hg = 120, wg = 320, lg2;
int num = 0;
uint8_t buf[320];
while(HAL_GPIO_ReadPin(VSYNC_PORT, VSYNC_PIN) == GPIO_PIN_RESET);
while(HAL_GPIO_ReadPin(VSYNC_PORT, VSYNC_PIN) == GPIO_PIN_SET);
while(hg--){
uint8_t*b=buf,*b2=buf;
lg2=wg/5;
while(lg2--){
while(HAL_GPIO_ReadPin(PCLK_PORT, PCLK_PIN) == GPIO_PIN_SET);
*b++=(uint8_t)GPIOC->IDR;
while(HAL_GPIO_ReadPin(PCLK_PORT, PCLK_PIN) == GPIO_PIN_RESET);//wait for high
while(HAL_GPIO_ReadPin(PCLK_PORT, PCLK_PIN) == GPIO_PIN_SET);//wait for low
*b++=(uint8_t)GPIOC->IDR;
while(HAL_GPIO_ReadPin(PCLK_PORT, PCLK_PIN) == GPIO_PIN_RESET);//wait for high
while(HAL_GPIO_ReadPin(PCLK_PORT, PCLK_PIN) == GPIO_PIN_SET);//wait for low
*b++=(uint8_t)GPIOC->IDR;
while(HAL_GPIO_ReadPin(PCLK_PORT, PCLK_PIN) == GPIO_PIN_RESET);//wait for high
while(HAL_GPIO_ReadPin(PCLK_PORT, PCLK_PIN) == GPIO_PIN_SET);//wait for low
*b++=(uint8_t)GPIOC->IDR;
while(HAL_GPIO_ReadPin(PCLK_PORT, PCLK_PIN) == GPIO_PIN_RESET);//wait for high
while(HAL_GPIO_ReadPin(PCLK_PORT, PCLK_PIN) == GPIO_PIN_SET);//wait for low
*b++=(uint8_t)GPIOC->IDR;
image_buffer[hg][lg2] = *b2++;
num++;
//HAL_UART_Transmit(&huart2, b2++, sizeof(b2), HAL_MAX_DELAY);
while(HAL_GPIO_ReadPin(PCLK_PORT, PCLK_PIN) == GPIO_PIN_RESET);//wait for high
}
/* Finish sending the remainder during blanking */
lg2=320-(wg/5);
while(lg2--) {
image_buffer[hg][lg2] = *b2++;
num++;
//HAL_UART_Transmit(&huart2, b2++, sizeof(b2), HAL_MAX_DELAY);
}
}
return num;
}
If you need any other detail I am ready to provide it.
2019-07-23 09:57 AM
So you're basically bit-banging the interface.
Probably not going to get many bites on this, you're a bit off in left field here.
Would probably hard code the pin reading, the HAL code probably runs a dozen cycles.
Review with a scope/analyzer, tracking your progress in the loops with another GPIO toggling.