Use this forum to chat about hardware specific topics for the ESP8266 (peripherals, memory, clocks, JTAG, programming)

User avatar
By kolban
#24201 Do you have a spec on the OV7670 you are using? I believe that some of them can give you the data via SPI or I2C? How are you calculating the speed to read? 1/16 of a microsecond is 62 nano seconds. That is not long at all.
User avatar
By anvoice
#24212 The data sheet can be found at http://www.voti.nl/docs/OV7670.pdf

If I understand correctly, the version without FIFO (that I have) does not have the capability to store data and send it via I2C (SCCB, which is close to the same thing), which necessitates taking it from the data pins directly.

In order to get about 10 frames/second, a pixel clock of 8MHz would be used on the camera. I'm guessing the clock spends about half the time in the high state, and on each of those clock cycles all 8 data pins must be read to get a byte of data. So there would be 1/2 of 1/8M of a second to sample the 8 pins, and I agree that isn't long, which is why I'm wondering if it's feasible. Basically it would mean that anything sampling it must either run at 16MHz times 8 = 128MHz at least, and also be able to sample with one clock cycle. Assuming my logic is correct.

Alternatively, using a port to sample all the data pins at once, assuming it could be done in only a few clock cycles, means the processor would only need to run at a few times 16MHz, which the ESP does.

edit: I found a site that details the ESP8266 gpio registers (http://esp8266.ru/esp8266-gpio-register/), but don't exactly know how to move from there. Never tried communicating to registers directly before.

To get a comparison, I tested the digitalRead/Write functions on the arduino, those work at a frequency of ~120kHz, whereas using the port registers directly takes that up to over a MHz. Since the ESP runs at higher clock, it seems feasible that it might be fast enough to poll the pins fast enough if accessing registers directly.
User avatar
By anvoice
#24266 Update: made some progress, though not sure if it's complete yet. Basically the GPIO_IN register on the ESP can be used to catch grab data from all 16 pins at once. Truncating the returned value from the register to the least significant byte results in the first 8 input pins, which is just right for getting the 8 data bits from the OV7670. So the following statements:

Code: Select all#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <IPAddress.h>

#define GPIO_IN ((volatile uint32_t*) 0x60000318)    // register contains gpio pin values of ESP8266 in read mode + some extra values (need to be truncated)
#define PCLK 8
#define HREF 9
#define VSYNC 10

WiFiClient wifi;
IPAddress server(127,0,0,1);
const char * ssid = "SSID";
const char * pass = "PASSWORD";

byte data;

void setup() {
  //Serial.begin(115200);
 
  WiFi.begin(ssid, pass);
  WiFi.config(IPAddress(192,168,1,118), IPAddress(192,168,1,1), IPAddress(255,255,255,0));
  wifi.connect(server, 8080);
  while (WiFi.status() != WL_CONNECTED) {
    delay(200);
  }
 
  pinMode(0,INPUT);
  pinMode(1,INPUT);
  pinMode(2,INPUT);
  pinMode(3,INPUT);
  pinMode(4,INPUT);
  pinMode(5,INPUT);
  pinMode(6,INPUT);
  pinMode(7,INPUT);
  pinMode(PCLK,INPUT);
  pinMode(HREF,INPUT);
  pinMode(VSYNC,INPUT); 
}

bool st = false;

void loop() {

  if (!st){
 
  while(digitalRead(VSYNC));         // wait until new frame starts
  while(!digitalRead(VSYNC)) {      // VSYNC low = frame transmitted
    //wifi.write('s');        // signals frame start
    while(digitalRead(HREF)) {    // HREF high = row transmitted
      if (digitalRead(PCLK)){    // pixel clock high = byte transmitted
        data = (byte)*GPIO_IN;    // this line truncates all but the least significant data in the returned value, which corresponds exactly to the first 8 input pins (MSbit for pin 7, LSbit for pin 0)
        while(digitalRead(PCLK));  // wait for clock to go low
      }
      wifi.write(data);  // write data during clock low
      wifi.write('\n');
    }
    wifi.write('\n');
    //wifi.write('e');      // signals frame end
  }
 
  st = true;
  }
}


There would be a need to replace the SSID and PASSWORD tokens with valid ones.
User avatar
By stan
#29135 Very interesting project. Did you finally manage to grab one image from OV7670 and to ssend it through wifi ? Several images per second ?