SoCKit User Manual
81
www.terasic.com
December 1, 2015
6
6
.
.
3
3
I
I
2
2
C
C
I
I
n
n
t
t
e
e
r
r
f
f
a
a
c
c
e
e
d
d
G
G
-
-
s
s
e
e
n
n
s
s
o
o
r
r
This demonstration shows how to control the G-sensor by accessing its registers through the built-in
I2C kernel driver in Altera SoC Yocto Linux.
Function Block Diagram
Figure 6-8
s
hows the function block diagram of this demonstration. The G-sensor on the SoCKit
board is connected to the
I2C1
controller in HPS. The G-Sensor I2C 7-bit device address is 0x53.
The system I2C bus driver is used to access the register files in the G-sensor. The G-sensor interrupt
signal is connected to the PIO controller. In this demonstration, we use polling method to read the
register data, so the interrupt method is not introduced here.
Figure 6-8 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:
5.
Open I2C bus driver "/dev/i2c-1": file = open("/dev/i2c-1", O_RDWR);
6.
Specify G-sensor's I2C address 0x53: ioctl(file, I2C_SLAVE, 0x53);
7.
Specify desired register index in g-sensor: write(file, &Addr8, sizeof(unsigned char));
8.
Read one-byte register value: read(file, &Data8, sizeof(unsigned char));
Because the G-sensor I2C bus is connected to the I2C1 controller, as shown in the
Figure 6-9
, the
given driver name is '/dev/i2c-1'.