1

I'm using stm32f4 connect to ov7670 (without FIFO) to capture a image (176x144, RGB565). After capture image, stm will send data to PC via UART-COM. I have written a program using C# to read data from com port and display as image. But I have problem with view I get:

image is sent in computer

Here is my C# code:

using System.Drawing;
using System.Windows.Forms;

namespace camview
    {
    public partial class Form1 : Form
    {
        Bitmap bmp = new Bitmap(176, 144);
        public Form1()
        {
            InitializeComponent();

            serialPort1.Open();
        }

        void setbmp(Bitmap bmp, int x, int y, int a, int b)
        {
            int tmp = (a << 8) | b;

            int red = tmp >> 11;
            int green = (tmp >> 5) & 0x3f;
            int blue = tmp & 0x1f;

            bmp.SetPixel(x, y, Color.FromArgb(red * 8, green * 4, blue * 8));

        }

        private void button1_Click(object sender, System.EventArgs e)
        {
            string s = "";
            while (s != "OK\r")
            {
                s = serialPort1.ReadLine();
                richTextBox1.Text += s;
            }

            richTextBox1.Text += "Start\n";
            for (int i = 0; i < 144; i++)
                for (int j = 0; j < 176; j++)
                {
                    int a = serialPort1.ReadByte();
                    int b = serialPort1.ReadByte();
                    //richTextBox1.Text += a + ' ' + b + ' ';
                    setbmp(bmp, j, i, a, b);
                }

            pictureBox1.Image = bmp;
        }
    }
}

These is my config for ov7670 reg:

I2C_writereg(0x12, 0x80); // reset all reg
I2C_writereg(0x11, 0xc0); //set CLKRC
I2C_writereg(0x12, 0x0c); // set output QCIF, RGB
I2C_writereg(0x70, 0x3a); // scaling
I2C_writereg(0x71, 0x35); 
I2C_writereg(0x8c, 0x00); // disable RGB444
I2C_writereg(0x40, 0xd0); // enable RGB565, output range from 00 to FF
I2C_writereg(0x0c, 0x4c); // 
Programmer dude
  • 167
  • 1
  • 5
  • 23
  • 1
    Are you sure the image is 176x144? The specs for the `ov7670` claim it is 640x480 – DavidG Nov 30 '15 at 02:04
  • thank for reply. I read datasheet of ov7670 and see ov7670 supports image size: VGA, CIF and any size scaling down from CIF to 40x30 (such as QVGA, QCIF). – Programmer dude Nov 30 '15 at 13:57
  • I set COM7 reg to 0x0c (bit 3 and bit 2 is 1). According datasheet, output is QCIF (176x144) and RGB565 format. – Programmer dude Nov 30 '15 at 14:02
  • Are you sure that you are effectively writing the OV7670 registers? I had the same issue and realized my I2C module was not writing the registers and had to increase the I2C speed. – KansaiRobot May 19 '17 at 00:21

0 Answers0