2009-04-07 09:56:12     discuss local_get_register in TWI_TEST.C

Document created by Aaronwu Employee on Aug 14, 2013
Version 1Show Document
  • View in full screen mode

2009-04-07 09:56:12     discuss local_get_register in TWI_TEST.C

Ashutosh natraj (UNITED KINGDOM)

Message: 72329   


Question: I'm trying to read the device ID of the camera, using the OV7660 camera setup,


                The datasheet for the camera says, the register address 0x0a 0x0b should contain the values


                 which are the device ID for the camera.The register value stored in the register address is not


                able to be fetched, instead to read the value the program enters a wrong loop to write the register value. could you please tell me how the values are passed.for the register address mentioned to read the values stored in them.




Upon running the program after chaning the register address: as 0x0a ,0x0b the error I get is:


Location of Program: ashu@ashu:~/uClinux-dist-2008R1.5-RC3/user/blkfin-test/twi_test


( the uClinux dist/user/blkfin-test/twi_test)




Case 1: Program with correct I2C_SLAVE address


local_cam_get_register: error reading value @ 0x0a, errno = 1


Fail to get data from register 10




I tried to understand the function which is always going in to the error to get the cam register value stored in the address 0x0a and 0x0b. kindly tell me how to avoid this error in the write function, as I have highlighted below:



local_cam_get_register(int    filehandle,

                       int    bus_width,

                       int    reg_addr,

                       int    *val)



    unsigned char   regval =    reg_addr; /* Device register to access */

    unsigned char   buf[10];

    int             try_count;


    buf[0] = regval;

    int temp;


    if (  write(filehandle, buf, 1) != 1) // 3rd parameter the number of bytes, mentioned as 1 here, but still


                                                       // when I run the program twi_test.c , i face the problem that the


                                                       // register to be read, should give me the value stored.


        printf("local_cam_get_register: error sending register address 0x%02x, errno = %d\r\n",

            regval, errno);

        return -1;



    if (read(filehandle, buf, bus_width) == bus_width)


        if (bus_width == 1)


            *val = buf[0];




            *val = buf[0] << 8;

            *val |= buf[1];



        return 0;


    printf("local_cam_get_register: error reading value @ 0x%02x, errno = %d\r\n", regval, errno);

    return -1;





Thanks in advance


Ashutosh Natraj






2009-04-09 05:23:28     Re: discuss local_get_register in TWI_TEST.C

Mike Frysinger (UNITED STATES)

Message: 72459   


please dont post the same question multiple times