Edantes87:
@rogerClark
I know TaylanPince some pages ago got it working but he went for the no FIFO version and an external chip instead. I only have the FIFO version and an old MEGA. I do have two non-FIFO versions of the camera but I would need to get me a chip. According to Mr. Arduino the code im using is too slow. he did mention however that the main (or most terrible as he put it) flaw of the code was that it was doing YUV to RGB conversion on the arduino itself. I deleted this lines because I do not need them I would be happy with grayscale. I reallyo hope someone can help me...school project.
ED87
Hi @Edantes87
I am currently working with the FIFO version and Arduino Nano. I'm also new to this microcontroller and have been working with the OV+FIFO for about a month now. I got VGA mode working recently but my colors are still a little off.
Anyways, you don't have to worry about the speed of your code execution when working with the FIFO version. The FIFO version has an external 12MHz oscillator that feeds directly into the XCLK of the OV7670. The onboard DRAM controller takes care of the esoteric processes of getting the camera data into the FIFO memory. After that, you can read bytes from the FIFO over UART as slow as you want regardless of the resolution.
I took a look at your code and it is quite a mess. I don't have time to coach you on your programming style but I can offer a few hints about the routines you will need to get a good image from the camera.
The most important question to ask you is which version of the OV7670+FIFO module you have? Some versions come with the OV VSYNC pin directly tied to the Write Reset pin of the FIFO. This has a huge impact on the code you need to write.
If you have the version that exposes the camera VSYNC output to you, then take a look at the VSYNC interrupt handler below and adapt it to your code. This part captures the camera image data into the FIFO memory.
// *****************************************************
// VSYNC INTERRUPT HANDLER
// *****************************************************
void static __inline__ vsyncIntFunc() {
DISABLE_WREN; // disable writing to fifo
if (bRequestPending && bNewFrame) { /* if a new frame is ready and I want that frame... */
detachInterrupt(VSYNC_INT);
processRequest(); /* read the data out of the fifo here */
bRequestPending = false; /* reset states */
bNewFrame = false;
attachInterrupt(VSYNC_INT, &vsyncIntFunc, FALLING);
}
else { */ load a new frame into the fifo */
ENABLE_WREN; /* enable writing to fifo (active LOW)*/
// reset write pointer of the fifo
ENABLE_WRST; /* write reset (active LOW) */
//_delay_cycles(500);
DISABLE_WRST;
//_delay_cycles(100); /* Disabled by me. 5/18/2015 */
bNewFrame = true;
}
}
I added a lot of comments for you. If you still don't understand what is going on here, then you should read the AL422b and OV7670 datasheets. Specifically the timing diagrams.


After you get the image from the camera into the FIFO, reading it out is as simple as resetting the FIFO read pointer address...
// Reset the fifo read pointer
void fifo_rrst(void)
{
ENABLE_RRST;
//_delayNanoseconds(5);
SET_RCLK_H;
//_delayNanoseconds(5);
SET_RCLK_L;
DISABLE_RRST;
}
and then pulsing the FIFO read clock for each byte you want.
// Read one byte from the fifo
uint8_t fifo_readByte(void)
{
uint8_t val;
SET_RCLK_H;
val = (DATA_PINS) /* & B11111000); // |B00000111; */
//_delay_cycles(10);
SET_RCLK_L;
//_delay_cycles(10);
return val;
}
Remember, YUV is 2bytes per pixel. QQVGA YUV = 1601202pixels = 38,400bytes to read out of the FIFO.
Good luck and keep us posted on your progress.