Motherboard Forums


Reply
Thread Tools Display Modes

ov7690 SCCB writing data to register

 
 
hassanmahmood
Guest
Posts: n/a
 
      04-16-2012, 05:15 AM
hello:
Hello:
i am using ov7690 with at91sam usin MCK at 12.3MHz. but for testin
purpose i am using I2C at 153KHz from atmega2560 for SCCB. I can read an
register from ov7690 but I can't write to any register. the response i
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 valur
retains...

what can be the problem??

---------------------------------------
Posted through http://www.EmbeddedRelated.com
 
Reply With Quote
 
 
 
 
hassanmahmood
Guest
Posts: n/a
 
      04-16-2012, 07:28 AM
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
 
Reply With Quote
 
 
 
 
Paul
Guest
Posts: n/a
 
      04-16-2012, 09:40 AM
In article <(E-Mail Removed)>, 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 | (E-Mail Removed)
<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
 
Reply With Quote
 
hassanmahmood
Guest
Posts: n/a
 
      04-16-2012, 10:28 AM

>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 fo
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 usin
eeprom_write function.

I can read ID from 0x0A, ver from 0x0B and also manfacturer. but can no
write R/W able registers. for example 0x51 is gain register. i can rea
value from it viz 0x9A but can write to it!!!!

---------------------------------------
Posted through http://www.EmbeddedRelated.com
 
Reply With Quote
 
Andrew Jackson
Guest
Posts: n/a
 
      04-16-2012, 11:08 AM
> 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
 
Reply With Quote
 
Paul
Guest
Posts: n/a
 
      04-16-2012, 11:52 AM
In article <(E-Mail Removed)>, 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 | (E-Mail Removed)
<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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ov7690 SCCB interface hassanmahmood Embedded 0 04-04-2012 06:19 PM
Re: sccb(I2C) for ov7670 Paul Embedded 0 08-19-2010 02:59 PM
Re: sccb(I2C) for ov7670 Matej@OS|SB Embedded 0 08-19-2010 01:31 PM
Omnivision OV7640 SCCB (I2C?) bus problem may_2005@olley.com Embedded 25 02-20-2006 05:06 PM
Problem with 16 bit AVR register (temp register oddness) Andy Carol Embedded 4 10-05-2003 04:12 AM


All times are GMT. The time now is 06:12 PM.


Welcome!
Welcome to Motherboard Point
 

Advertisment