1. This forum section is a read-only archive which contains old newsgroup posts. If you wish to post a query, please do so in one of our main forum sections (here). This way you will get a faster, better response from the members on Motherboard Point.

ov7690 SCCB writing data to register

Discussion in 'Embedded' started by hassanmahmood, Apr 16, 2012.

  1. 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
     
    hassanmahmood, Apr 16, 2012
    #1
    1. Advertising

  2. 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
     
    hassanmahmood, Apr 16, 2012
    #2
    1. Advertising

  3. hassanmahmood

    Paul Guest

    In article <>, 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 |
    <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
     
    Paul, Apr 16, 2012
    #3

  4. >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
     
    hassanmahmood, Apr 16, 2012
    #4
  5. > 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
     
    Andrew Jackson, Apr 16, 2012
    #5
  6. hassanmahmood

    Paul Guest

    In article <>, 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 |
    <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
     
    Paul, Apr 16, 2012
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy Carol
    Replies:
    4
    Views:
    369
    Brian Dean
    Oct 5, 2003
  2. Replies:
    25
    Views:
    5,635
    Paul Olley
    Feb 20, 2006
  3. Matej@OS|SB

    Re: sccb(I2C) for ov7670

    Matej@OS|SB, Aug 19, 2010, in forum: Embedded
    Replies:
    0
    Views:
    1,642
    Matej@OS|SB
    Aug 19, 2010
  4. Paul

    Re: sccb(I2C) for ov7670

    Paul, Aug 19, 2010, in forum: Embedded
    Replies:
    0
    Views:
    722
  5. hassanmahmood

    ov7690 SCCB interface

    hassanmahmood, Apr 4, 2012, in forum: Embedded
    Replies:
    0
    Views:
    627
    hassanmahmood
    Apr 4, 2012
Loading...

Share This Page