Hi,
Thanks for the Reply.
But i want to Read & Write register of OV5640 connected on J9 on imx6qsabresd board. It uses I2C1 for Configuration.
If i modify ov5640.c file and add read & write any register API in ov5640_probe(). And compile linux kernel. I can read/write registers.
But i want to do the same using C application.
I an using Eclipse for Develop & Debug my application.
I have setup eclipse as per the link below.
http://developer.toradex.com/knowledge-base/hello-world-application-on-embedded-linux
http://janaxelson.com/eclipse5.htm
This is my below program.
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <linux/i2c-dev.h>
#include <linux/i2c.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <linux/kernel.h>
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
typedef unsigned long long u64;
typedef signed char s8;
typedef short s16;
typedef int s32;
typedef long long s64;
// I2C Linux device handle
int g_i2cFile;
// open the Linux device
void i2cOpen()
{
g_i2cFile = open("/dev/i2c-1", O_RDWR);
if (g_i2cFile < 0) {
perror("i2cOpen");
puts("I2C Open Failed");
exit(1);
}
else
puts("I2C Open Success");
}
// close the Linux device
void i2cClose()
{
close(g_i2cFile);
}
// set the I2C slave address for all subsequent I2C device transfers
void i2cSetAddress(int address)
{
if (ioctl(g_i2cFile, I2C_SLAVE, address) < 0) {
perror("i2cSetAddress");
puts("I2C Set Address Failed");
exit(1);
}
else
puts("I2C Set Address Success");
}
static s32 ov5640_write_reg(u16 reg, u8 val)
{
u8 au8Buf[3] = {0};
au8Buf[0] = reg >> 8;
au8Buf[1] = reg & 0xff;
au8Buf[2] = val;
if (write(g_i2cFile, au8Buf, 3) < 0) {
return -1;
}
return 0;
}
static s32 ov5640_read_reg(u16 reg, u8 *val)
{
u8 au8RegBuf[2] = {0};
u8 u8RdVal = 0;
au8RegBuf[0] = reg >> 8;
au8RegBuf[1] = reg & 0xff;
if (2 != write(g_i2cFile, au8RegBuf, 2)) {
puts("1");
return -1;
}
else
puts("2");
if (1 != read(g_i2cFile, &u8RdVal, 1)) {
return -1;
}
else
puts("4");
*val = u8RdVal;
printf("%d",u8RdVal);
return u8RdVal;
}
int main(void) {
u8 mode;
puts("I2C Test Program");
i2cOpen();
i2cSetAddress(0x78);
ov5640_read_reg(0x3100, &mode);
printf("%d",mode);
if(mode == 0x78)
puts("Match");
else
puts("Not Match");
i2cClose();
return 0;
}
below is the Output of the Program
I2C Test Program
I2C Open Success
I2C Set Address Success
1
0Not Match
So whats wrong with the code?
And is there any tutorial to access ov5640 using C Application?