OV7670 writing to registers

Im using Arduino UNO to read the values of OV7670 registers.. Im using the Wire library..

Reading the registers works fine
int addressread = 0x21;
int address = 0x1;
int data = 0x3;

Wire.beginTransmission(addressread);
   Wire.write(address);
   Wire.endTransmission();
   Wire.requestFrom(addressread,1);
   while(!Wire.available())
   {  
   }
   int c = Wire.read();
   Serial.println(c);

but when I am writing registers, it doesn't work

Wire.beginTransmission(0x21); // i2c slave address
Wire.write(0x1); //register address to write
Wire.write(0x3); //data to write
Wire.endTransmission();

I executed the above write function, and when I read back, it doesnt change.

Please help

Thanks

Can you post all the code so we can see you reading and writing in the same code.

#include <Wire.h>


int slaveaddress = 0x21;
int regaddress = 0x01;
int regdata = 0xFF;
void setup()
{
  Serial.begin(9600);
  Wire.begin();
  Read();
  Write();
  
}

void Write()
{
   Wire.beginTransmission(slaveaddress);
   Wire.write(regaddress);
   Wire.write(regdata);
}

void Read()
{
  Wire.beginTransmission(slaveaddress);
   Wire.write(regaddress);
   Wire.endTransmission();
   Wire.requestFrom(regaddress,1);
   while(!Wire.available())
   {  
   }
   
   int c = Wire.read();
   
   Serial.println(c);
}

void loop()
{
  Read();
}

I think you have missed an end transmission from the write, try these two functions:-

void Write()
{
   Wire.beginTransmission(slaveaddress);
   Wire.write(regaddress);
   Wire.write(regdata);
   Wire.endTransmission();    // stop transmitting
}

void Read()
{
  Wire.beginTransmission(slaveaddress);
   Wire.write(regaddress);
   Wire.endTransmission();
   Wire.requestFrom(regaddress,1);
   int c = Wire.read();   
   Serial.println(c);
}

I tried to include that

Wire.endTransmission();

and still it doesnt work. Im still getting the same reading even if I tried to write a new value.

Cheers,
vvavepacket

Have you got level shifting in place? Or are you driving the camara from 5V.
Have you seen this thread
http://forum.arduino.cc/index.php?topic=159557.0

Yes I have already seen that thread, disabled the pullup resistors in the TWI.c file, and currently using the 3.3 volt line to avoid damaging the camera.

Cheers

You need pull up resistors to the 3V3 line as well as disabling the internal pullups.
From what I read you also need to supply it with a 10MHz clock signal in order for it to work.
I assume you haven't just got the raw chipp, so what else is on the board in terms of regulators and such?

How are you powering it? The 3v3 output line on the aeduino has limited current capabilities.

You do realize that I have posted code that shows how to read registers. You can use this code assuming you want to use Wire.h

byte wrReg(unsigned char regID, unsigned char regDat){
	Wire.beginTransmission(sensor_addr >> 1);
	Wire.write(regID);
	Wire.write(regDat);
	if(Wire.endTransmission()){
		return 0;
		while(1);
	}
	delay(1);
	return 1;
}

Before using the function please add this to setup()

Wire.begin();

Also you will need to add

#define sensor_addr 0x42

To your code
Also yes you do need to provide a clock. The best way to provide a clock is to use PWM, using PWM you can generate an 8mhz clock. You will need to convert the 5v clock to 3.3v. I use a buffer to do this.