Tuesday, January 29, 2013

Demo: STM32F4 + OV7670 + qSerialTerm

Yup, that mess of wires actually works.

In this post I'll cover 3 basic demo programs for the STM32F4 to interface the OV7670. Additionally, I've use qSerialTerm to receive data from the uC and display it in a human readable form.

I assume you know how the OV7670 works and have some knowledge about common peripherals found in uC (GPIO, USART, DMA, etc).

The board used in this demo was the custom development board: F4Dev. The STM32F4DISCOVERY wasn't used and can't be used because the Digital Camera Interface (DCMI) peripheral pins are not fully available in that development board.

I've used bareCortexM, an Eclipse based IDE, and libstm32pp, a template peripheral library, to develop these demos for the STM32F4.

The following configuration applies to all the demos:
  • The STM32F4 operated at 42 MHz, the system clock, the AHB clock, the APB1 clock and the APB2 clock, all of them operated at this frequency.
  • This 42 MHz frequency was obtained from the uC High Speed Internal (HSI) oscillator, which runs at 16 MHz, after scaling up the frequency using the uC internal PLL.
  • The MCO1 pin was configured to output the HSI clock (16 MHz) and this output was used to drive the OV7670 XCLK.

Demo 1: Scanning the SCCB bus (Code)


In this first demo, the STM32F4 will interface the OV7670 using a bit bang implementation of the SCCB protocol.

The uC will wait until the letter 'S' is received on the USART1 interface. Upon receiving this signal, the uC will read all the internal registers of the OV7670 using the SCCB interface.

After scanning all the OV7670 registers. The uC will report the address and values of the registers via the USART1 in a human readable format.

Default values of the internal registers of the OV7670

You can find the log file of the uC output here.

Under the hood details: The formatting was done using the printf function.

Demo 2: Reading a frame and visualizing the data in hex format (Code)


In this second demo, the STM32F4 will interface the OV7670 using the Digital Camera Module Interface (DCMI) to grab a frame from the OV7670 and then display the data in hexadecimal format.

The uC will wait until the letter 'S' is received on the USART1 interface. Upon receiving this signal, the uC will use the DCMI in single shot mode to grab one frame from the OV7670.

After capturing the frame, the uC will send all the data via the USART1 interface in a human readable hexadecimal format.

Frame taken in a pitch black environment. Data in hex format.

You can get the full log file here.

Under the hood details: The DCMI peripheral works hand to hand with the DMA peripheral. The data that is captured by the DCMI is moved by the DMA to a predetermined memory address without intervention of the uP. The formatting was done using the printf function.

Demo 3: Reading a frame and visualizing the data as an image (Code)

The last demo is pretty similar to the second demo. The difference is that the uC reports the frame data in binary form. On the PC side, this binary data is parsed and displayed in qSerialTerm.

Frames captured by the OV7670. Left: A electrical tape. Right: Pitch black image.

Under the hood details: After capturing the frame, the data was sent through the USART interface using the DMA peripheral.

That's it. You have access to my full code, both the STM32F4 firmware and the qSerialTerm are fully available to you. I hope this information will help you in projects that involve the OV7670.

28 comments:

  1. Thank you!
    It's midnight so I'll check it out tomorrow but I've been looking for this :-)

    Cat

    ReplyDelete
  2. Dear Jorge!
    Do you think, I can use the same camera module, with STM32F103 microcontroller? It doesn't have DCMI.

    ReplyDelete
    Replies
    1. Yeah, it can be done. I did it with STM32F103. But you cannot get higher frame rates. then I moved to stm32F4 discovery board. It was success, now I can get images upto 30 fps.

      Delete
  3. hi

    you said in your tutorial that stm32f4discovery can not be used, but according to its datasheet it has dcmi so what is the problem with stm32f4discovery?

    i have both stm32f4discovery and linksprite jpeg camera and is it possible to capture frames with them and send pictures to PCs monitor?

    thanks for your answer that would be appreciated.

    ReplyDelete
    Replies
    1. Hi Tolga,

      I mentioned that, because on the STM32F4DISCOVERY board has the DCMI pins connected to other ICs in the board, and I think that might distort the OV7670 signals and corrupt image data or even stop the DCMI interface from working.

      However on the comments of my post 'Hacking the OV7670', Austin Ciambriello claims that he has managed to get the STM32F4DISCOVERY working with the OV7670.

      So, in the end, it might be possible, I can't assure you that because I haven't tried that combination (STM32F4DISCOVERY + OV7670)

      Regards

      Delete
    2. thank you jorge, i will try my linksprite cam with stm32f4discovery, hope it would work :)

      Delete
    3. Hi Tolga,

      did you manage to make that setup working ?

      Delete
  4. I need qSerial to display image. Can you give me it. It is very neccesary for me. Thanks! My email is tvden018@student.ctu.edu.vn

    ReplyDelete
    Replies
    1. Hi Den,

      The qSerialTerm code is among my github projects. Go look for it (hint: top right of this page), modify and build it to yours needs.

      And please don't spam post the same comment in other blog entries.

      Delete
  5. Hi yoman, yes you can interface ov7725 with stm32f1 , i've already tried , it works and im even processing 320x240 data.i suppose that this is also truth for ov7670
    Hi Jorge, i've just realized the existence of the DCMI on stm32f4, can you tell the advantages of DCMI, and overall advantages in image adquisition on stm32f4 over stm32f1

    ReplyDelete
  6. Hello,
    I currently have the problem of the camera (OV7670) via Ethernet (UDP) to stream.

    I currently use the demo software and a simple UDP connection (server) to build, now I want to send the camera data in JPEG format.

    Can you please help me? I uploaded the demo software on Dropbox ->
    ETH + DCMI Demo Project

    How can I read the data from the camera and send via UDP?

    I would be very happy if you can help me?

    Thank you very much

    ReplyDelete
    Replies
    1. Demo Projekt -> https://www.dropbox.com/sh/x74c963dkxyct74/3oCAFAA8dq?v=0mcn

      Delete
  7. Hi Jorge

    I'm trying to run first demo on STM32F4DISCOVERY, but in fuction readSlaveRegister, function getByte always return false and I don't know why. Have you got any idea? I will be very appreciate for help.

    Regards,
    Wojtek

    ReplyDelete
    Replies
    1. Did you manage STM32F4DISCOVERY working with the cam ?

      Delete
  8. This comment has been removed by the author.

    ReplyDelete
  9. Hi all,
    I'd like to ask you about DMA_BufferSize.
    DMA_InitStructure.DMA_BufferSize = picture_x * picture_y * 2 / 4;
    Why did you use "*2/4" here?

    ReplyDelete
  10. Why do you use bit bang i2c? I used the hardware i2c and it works just fine. The trick to getting it working is to use a 10k pullup resistor. It appears that using a resistor with too low of a resistance and it won't work.

    ReplyDelete
  11. Acetech have many years of experience in custom software development. Find out more about custom software development at http://www.acetechindia.com

    ReplyDelete
  12. Congrats about the post!
    Very Nice!
    I'm in a project with OV7670, I research a lot, but I don't know what is the black strip in the left of the images, you know?

    ReplyDelete
  13. will it work with hyper terminal or teraterm ???

    ReplyDelete
  14. Congratulations for getting it work and a brilliant walk-through post. I know its based on Qt, but is there any alternate utility for plotting images received over serial port on windows XP platform?

    Thanks,
    Prasad. (logging to gmail is banned in the company, so have to comment as anonymous user)

    ReplyDelete
  15. This blog explains the details of most popular technological details. This helps to learn about what are all the different method is there. And the working methods all of that are explained here. Informative blog
    PHP Training in Chennai

    ReplyDelete
  16. hi, I've just started started my project on this topic, mostly emage processing and i found useful info from your project.I am starting with arduino uno, do you have any guidline for me, i appreciate your help.

    ReplyDelete
  17. how to use it without DCMI. i am using STM32f30k6 M0 board.

    ReplyDelete
  18. Wonderful blog.. Thanks for sharing informative blog.. its very useful to me..

    iOS Training in Chennai

    ReplyDelete
  19. Do you have an advice for using STM32 with a OV7670 with FIFO? Specially what settings I should use. (Now I am not getting a good image). The clock is set to 24MHz by an external oscillator

    ReplyDelete
  20. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my
    vision, keep sharing..
    Android App Development Company

    ReplyDelete