SoCKit User Manual
82
www.terasic.com
December 1, 2015
Figure 6-9 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
To write multiple byte values, developer can change step 4 to:
write(file, &szData8, sizeof(szData8)); // where szData is an array of bytes
G-sensor Control
The ADI ADXL345 provides I2C and SPI interfaces. I2C interface is used by setting the CS pin to
high on this SoCKit board.
The ADI ADXL345 G-sensor provides user-selectable resolution up to 13-bit
±
16g. The
resolution can be configured through the DATA_FORAMT(0x31) register. In the demonstration, we
configure the data format as:
Full resolution mode
±
16g range mode
Left-justified mode
The X/Y/Z data value can be derived from the DATAX0(0x32), DATAX1(0x33), DATAY0(0x34),
DATAY1(0x35), DATAZ0(0x36), and DATAX1(0x37) registers. The DATAX0 represents the least
significant byte, and DATAX1 represents the most significant byte. It is recommended to perform
multiple-byte read of all registers to prevent change in data between reads of sequential registers.
Developer can use the following statement to read 6 bytes of X, Y, or Z value.
read(file, szData8, sizeof(szData8)); // where szData is an array of six-bytes