May 20, 2024

Cross-analysis of I2C driver and test program trace based on S3c2440

VMware virtual machine+Fedora10, hardware platform TQ2440, kernel 2.6.30.4

The corresponding driver is suddenly enlightened, and after adding some dev_dbg, I also have some reference tips for the places I don't understand, which I will record and share with you.

The test procedure is as follows:

/*i2c_test.c

* hongtao_liu

*/

#include

#include

#include

#include

#include

#include

#include

#include

#define I2C_RETRIES 0x0701

#define I2C_TIMEOUT 0x0702

#define I2C_RDWR 0x0707

/*********Define struct i2c_rdwr_ioctl_data and struct i2c_msg, consistent with the kernel*******/

struct i2c_msg

{

unsigned short addr;

unsigned short flags;

#define I2C_M_TEN 0x0010

#define I2C_M_RD 0x0001

unsigned short len;

unsigned char *buf;

};

struct i2c_rdwr_ioctl_data

{

struct i2c_msg *msgs;

int nmsgs;

/* The number of nmsgs determines how many start signals there are, for "single start timing", take 1*/

};

/***********Main program***********/

int main()

{

int fd, ret;

struct i2c_rdwr_ioctl_data e2prom_data;

fd = open("/dev/i2c-0", O_RDWR);

/*

*dev/i2c-0 is generated after registering i2c-dev.c and represents an operational adapter. If not using i2c-dev.c

* way, there is no and no need for this node.

*/

if (fd < 0)

{

perror("open error");

}

e2prom_data.nmsgs=2;

/*

*Because in the operation sequence, at most 2 start signals (in byte read operation) are used, this will

*e2prom_data.nmsgs is configured as 2

*/

e2prom_data.msgs=(struct i2c_msg*) malloc(e2prom_data.nmsgs*sizeof(struct i2c_msg));

if(!e2prom_data.msgs)

{

perror("malloc error");

exit(1);

}

ioctl(fd, I2C_TIMEOUT, 1); /*timeout*/

ioctl(fd, I2C_RETRIES, 2); /* number of repetitions */

/***write data to e2prom**/

e2prom_data.nmsgs=1;

(e2prom_data.msgs[0]).len=2; //1 e2prom write target address and 1 data

(e2prom_data.msgs[0]).addr=0x50;//e2prom device address

(e2prom_data.msgs[0]).flags=0; //write

(e2prom_data.msgs[0]).buf = (unsigned char*) malloc(2);

(e2prom_data.msgs[0]).buf[0]=0x10;// e2prom write target address

(e2prom_data.msgs[0]).buf[1]=0x58; //the data to write

ret = ioctl(fd, I2C_RDWR, (unsigned long) &e2prom_data);

if(ret<0)

{

perror("ioctl error1");

}

sleep(1);

/******read data from e2prom*******/

e2prom_data.nmsgs=2;

(e2prom_data.msgs[0]).len=1; //The address of e2prom target data

(e2prom_data.msgs[0]).addr=0x50; // e2prom device address

(e2prom_data.msgs[0]).flags=0; //write

(e2prom_data.msgs[0]).buf[0]=0x10;//e2prom data address

(e2prom_data.msgs[1]).len=1;//Read data

(e2prom_data.msgs[1]).addr=0x50;// e2prom device address

(e2prom_data.msgs[1]).flags=I2C_M_RD;//read

(e2prom_data.msgs[1]).buf=(unsigned char*) malloc(1);//Store the address of the return value.

(e2prom_data.msgs[1]).buf[0]=0;//Initialize the read buffer

ret = ioctl(fd, I2C_RDWR, (unsigned long) &e2prom_data);

if(ret<0)

{

perror("ioctl error2");

}

printf("buff[0]=%x",(e2prom_data.msgs[1]).buf[0]);

/***Print the read value, if it is correct, it should be the 0x58 written earlier***/

close(fd);

return 0;

}

Split Core Current Transformer

SCT 016 split core Current Transformer is widely used in measuring, electric power system, industrial control and other automation part. The hole diameter is 16mm. Input current can from 80 A to 120 A, and out put can be current and voltage. Current from 20mA to 1A, and voltage usually is 0.33V. Also we have terminal and wire lead out which is convenient and flexible. The accuracy class is 0.5%. we have exported to Europe countries, America and India. and got many good feedback from them.

5533134905

863313490527331349054533134905

split core current transformer

  • Lock type Crimping terminal output Suspension installation
  • Measure current range: 5A~600A
  • current Work voltage: 720V Flame resistance: UL94-V0
  • Operation temperature: -25℃~+60℃
  • Storage temperature: -30℃~+90℃
  • Dielectric strength: AC 3500V/1min(between output and shell)
  • Isolation resistance: ˃100MΩ(500V DC) (between primary and secondary)050453490575045349051604534905

    Core material: Nanocrystalline core 1K107 SCT016 Typical graph

    Core loss graph

  • Model

    Rated measure current

    Accuracy

    Rated output

    Work

    frequency

    SCT016 120A 0.5/1 40mA

    50-1KHz

5604534905We attend Electrical exhibition In India, Germany and Brizil, South Korea...2293744905All of our material meet the RoHs, UL , SGS, CE certification9293744905

FAQ

1-MOQ?

We will work hard to fit your MOQ .Small purchase quantity is ok.

2-Payment term?

T/T, Western Union, Paypal, Credit Card

3-Delivery port?

Shenzhen, Guangzhou, Zhongshan, Hongkong.

4-Shipping date?

About 7 days when we check the payment.

5-Do you produce the core and bobbin by yourself .

Yes.we have 2 head company,1 subsidiary company.one is bobbin factory,one is core factory,last one is transformer factory.

6-Where is your factory?

In ShaanxI



Split Core Current Transformer,Open Type Current Sensor,High Accuracy Current Transformer,Measuring Split Current Transformer

Shaanxi Magason-tech Electronics Co.,Ltd , https://www.magason-tech.com