94
Figure 6-7 Block Diagram of the G-sensor Demonstration
I2C Driver
Here is the list of procedures in order to read a register value from G-sensor register files by using
the existing I2C bus driver in the system:
1.
Open I2C bus driver "/dev/i2c-0": file = open("/dev/i2c-0", O_RDWR);
2.
Specify G-sensor's I2C address 0x53: ioctl(file, I2C_SLAVE, 0x53);
3.
Specify desired register index in g-sensor: write(file, &Addr8, sizeof(unsigned char));
4.
Read one-byte register value: read(file, &Data8, sizeof(unsigned char));
Because the G-sensor I2C bus is connected to the I2C0 controller, as shown in the
Figure 6-8
, the
given driver name is '/dev/i2c-0'.
Figure 6-8 Schematic of I2C
To write a value into a register, developer can change step 4 to:
write(file, &Data8, sizeof(unsigned char));
To read multiple byte values, developer can change step 4 to:
read(file, &szData8, sizeof(szData8)); // where szData is an array of bytes
Summary of Contents for DE1-SOC
Page 1: ...1...
Page 108: ...107 Figure 8 4 Select Devices Page...