ov7690 SCCB writing data to register

Started by hassanmahmood April 16, 2012
hello:
       Hello:
       i am using ov7690 with at91sam usin MCK at 12.3MHz. but for testing
purpose i am using I2C at 153KHz from atmega2560 for SCCB. I can read any
register from ov7690 but I can't write to any register. the response is
correct i.e. status register of TWI of atmega2560 depicts correcr value,
meaning it sends data.

 but when i read back the value from that register the old valure
retains...

what can be the problem??	   
					
---------------------------------------		
Posted through http://www.EmbeddedRelated.com
the CODE is below.

I use eeprom routine beciase it is also working on I2C.
 I can read any register. but can not write.




volatile unsigned char pir='a',pir1='a';


void eeprom_write(unsigned char adrr , unsigned char val )
{
  //init_start
 TWCR=164;
while (!(TWCR & (1<<TWINT)));


//SLAVE write command
TWDR=0x42;
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));


// adress write command
TWDR=adrr;
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));


// data write command	
TWDR=val;
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));


//stop
TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWSTO);


}

unsigned char eeprom_read(unsigned char adrr)
{

 TWCR=164;  //start
while (!(TWCR & (1<<TWINT)));



//SLAVE write command
TWDR=0x42;
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));



TWDR=adrr;
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));


TWCR=164;
while (!(TWCR & (1<<TWINT)));



//SLAVE adress  read command
TWDR=0x43;
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));


TWCR = (1<<TWINT) | (1<<TWEN) ;//| (1<<TWEA);
//TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));


pir=TWDR;


//stop
TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWSTO);





return pir;
}

void main()
{
 TWBR=16;
TWSR=(0<<TWPS1) | (0<< TWPS0);   //aprox 153 KHZ

USART1_Init( MYUBRR);




TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWSTO);
_delay_ms(1000);
eeprom_read(0x0A);
send1(((pir & 0xF0)>>4)+0x30);
send1((pir & 0x0F)+0x30);

eeprom_read(0x0B);
send1(((pir & 0xF0)>>4)+0x30);
send1((pir & 0x0F)+0x30);


eeprom_read(0x1C);

send1(((pir & 0xF0)>>4)+0x30);
send1((pir & 0x0F)+0x30);


eeprom_read(0x1D);
send1((pir ));

//read 0x51 reg
eeprom_read(0x51);
send1((pir ));


  //write 0x51 reg
 eeprom_write(0x51,0x81);
   _delay_ms(100);
  


//read again 0x51
eeprom_read(0x51);
send1((pir ));






 }


	   
					
---------------------------------------		
Posted through http://www.EmbeddedRelated.com
In article <VemdndJNuOOzVxbSnZ2dnUVZ_oOdnZ2d@giganews.com>, hassan_
3md@n_o_s_p_a_m.yahoo.com says...
> > the CODE is below. > > I use eeprom routine beciase it is also working on I2C. > I can read any register. but can not write.
You obviously never send a write address for data to be written to. Looks like poorly structured student code.
> > volatile unsigned char pir='a',pir1='a'; > > > void eeprom_write(unsigned char adrr , unsigned char val ) > { > //init_start > TWCR=164; > while (!(TWCR & (1<<TWINT))); > > > //SLAVE write command > TWDR=0x42; > TWCR = (1<<TWINT) | (1<<TWEN); > while (!(TWCR & (1<<TWINT))); > > > // adress write command > TWDR=adrr;
.....
> unsigned char eeprom_read(unsigned char adrr) > { > > TWCR=164; //start > while (!(TWCR & (1<<TWINT))); > > > > //SLAVE write command > TWDR=0x42; > TWCR = (1<<TWINT) | (1<<TWEN); > while (!(TWCR & (1<<TWINT))); > > > > TWDR=adrr;
.......
> void main() > {
.....
> //read 0x51 reg > eeprom_read(0x51); > send1((pir )); > > > //write 0x51 reg > eeprom_write(0x51,0x81); > _delay_ms(100);
Write to 0x50 as you do not do any data shifting and adding one for reading on addresses. Check I2C or SCCB details for addresses
> > > //read again 0x51 > eeprom_read(0x51); > send1((pir )); > > > > > > > } > > > > > --------------------------------------- > Posted through http://www.EmbeddedRelated.com
-- Paul Carpenter | paul@pcserviceselectronics.co.uk <http://www.pcserviceselectronics.co.uk/> PC Services <http://www.pcserviceselectronics.co.uk/fonts/> Timing Diagram Font <http://www.gnuh8.org.uk/> GNU H8 - compiler & Renesas H8/H8S/H8 Tiny <http://www.badweb.org.uk/> For those web sites you hate
>Write to 0x50 as you do not do any data shifting and adding >one for reading on addresses. > >Check I2C or SCCB details for addresses
U can see the eeprom_read function. 0x42 is for write and 0x43 is for read. i donot have to shift any data. atmega2560 has dedicated module for I2C. I can read values from registers of ov7690. but can not write using eeprom_write function. I can read ID from 0x0A, ver from 0x0B and also manfacturer. but can not write R/W able registers. for example 0x51 is gain register. i can read value from it viz 0x9A but can write to it!!!! --------------------------------------- Posted through http://www.EmbeddedRelated.com
> i am using ov7690 with at91sam usin MCK at 12.3MHz. but for testing > purpose i am using I2C at 153KHz from atmega2560 for SCCB. I can read any > register from ov7690 but I can't write to any register. the response is > correct i.e. status register of TWI of atmega2560 depicts correcr value, > meaning it sends data. > > but when i read back the value from that register the old valure > retains... > > what can be the problem??
Does the OV7690 support I2C at more than the standard 100kHz? (That is, is it specified to work at 400kHz.) Are you sure that you don't send any sort of write enable prior to a write? You could help yourself by simplifying your code, using a common routine for all those: TWDR=adrr; TWCR = (1<<TWINT) | (1<<TWEN); while (!(TWCR & (1<<TWINT))); which just make it hard to read. Andrew
In article <veKdnXybQrrYaRbSnZ2dnUVZ_s-dnZ2d@giganews.com>, hassan_
3md@n_o_s_p_a_m.yahoo.com says...
> > >Write to 0x50 as you do not do any data shifting and adding > >one for reading on addresses. > > > >Check I2C or SCCB details for addresses > > > U can see the eeprom_read function. 0x42 is for write and 0x43 is for > read.
It was not obvious from your por code structure and lack of code comments.
> i donot have to shift any data. atmega2560 has dedicated module for > I2C.
That is not what I was refering to. One method people use is an address they pass to I2C functions as a COMMON address and maybe shift by one to I2C space or not, and add the 1 for read in the read function. Often these methods make for more readable code. Split your common bits of code into functions, the calling overhead of the functions will be insignificant compared to the overall I2C speed.
> I can read values from registers of ov7690. but can not write using > eeprom_write function. > > I can read ID from 0x0A, ver from 0x0B and also manfacturer. but can not > write R/W able registers. for example 0x51 is gain register. i can read > value from it viz 0x9A but can write to it!!!!
Sounds like device is in wrong mode and you have the pins set for a ONE time configuration at startup (RESET), not changeable via I2C/SCCB interface. Check the datasheet for the device and your ciruit and your soldeer joints
> --------------------------------------- > Posted through http://www.EmbeddedRelated.com
-- Paul Carpenter | paul@pcserviceselectronics.co.uk <http://www.pcserviceselectronics.co.uk/> PC Services <http://www.pcserviceselectronics.co.uk/fonts/> Timing Diagram Font <http://www.gnuh8.org.uk/> GNU H8 - compiler & Renesas H8/H8S/H8 Tiny <http://www.badweb.org.uk/> For those web sites you hate
yes ov7690 SCCB support 400KHZ, 300KHz, and 150Khz depending upon master
clock freq.

there is small difference between I2C and SCCB, I2c recieve ACKs where SCCB
dont	   
					
---------------------------------------		
Posted through http://www.EmbeddedRelated.com
On Tuesday, April 17, 2012 at 6:56:23 AM UTC+3, hassanmahmood wrote:
> yes ov7690 SCCB support 400KHZ, 300KHz, and 150Khz depending upon master > clock freq. > > there is small difference between I2C and SCCB, I2c recieve ACKs where SCCB > dont > > --------------------------------------- > Posted through http://www.EmbeddedRelated.com
Hi, I know this post is quite old. I however, need some help with a workable register setting for the ov7690 camera. Currently working with it on a project but the images from the camera doesn't come out quite clear. It is a lot noisy. Have also tried the color bar and there are incorrect colors in-between bars. Thanks in anticipation.