Freescale Semiconductor FRDM-FXS-MULTI 데이터 시트

다운로드
페이지 100
FXOS8700CQ
Sensors
Freescale Semiconductor, Inc.
31
9
Example FXOS8700CQ Driver Code
9.1
Introduction
It is very straightforward to configure the FXOS8700CQ and start receiving data from the three accelerometer and three 
magnetometer channels. Unfortunately, since every hardware platform will be different, it is not possible to provide completely 
portable software drivers. This section therefore provides real FXOS8700CQ driver code for a Kinetis uC board running under 
the MQX operating system. The I
2
C functions s_i2c_read_regs and s_i2c_write_regs are not provided here and should be 
replaced with the corresponding low level I
2
C driver code on the development platform.
9.2
FXOS8700CQ Addresses
This section lists the I
2
C address of the FXOS8700CQ. The I
2
C address depends on the logic level of FXOS8700CQ’s SA0 and 
SA1 address selection pins, so the actual I
2
C address may be 0x1C, 0x1D, 0x1E or 0x1F. 
Please see 
 for the available I
2
C addresses and SA1/SA0 settings.
Example 1. 
// FXOS8700CQ I2C address
#define FXOS8700CQ_SLAVE_ADDR
0x1E
// with pins SA0=0, SA1=0
Some of the key FXOS8700CQ internal register addresses are listed below.
Example 2. 
// FXOS8700CQ internal register addresses
#define FXOS8700CQ_STATUS
0x00
#define FXOS8700CQ_WHOAMI
0x00
#define FXOS8700CQ_XYZ_DATA_CFG 
0x0E
#define FXOS8700CQ_CTRL_REG1
0x2A
#define FXOS8700CQ_M_CTRL_REG1
0x5B
#define FXOS8700CQ_M_CTRL_REG2
0x5C
#define FXOS8700CQ_WHOAMI_VAL
0xC7
The reference driver code shown in this example does a block read of the FXOS8700CQ status byte and three 16-bit 
accelerometer channels plus three 16-bit magnetometer channels for a total of 13 bytes in a single I
2
C read operation.
Example 3. 
// number of bytes to be read from the FXOS8700CQ
#define FXOS8711CQFXOS8701CQFXOS8700CQ_READ_LEN 13// status plus 6 channels = 13 
bytes
9.3
 
Sensor data structure
The high and low bytes of the three accelerometer and three magnetometer channels are placed into a structure of type 
SRAWDATA containing three signed short integers.
Example 4. 
typedef struct
{
int16_t  x;
int16_t  y;
int16_t  z;
} SRAWDATA;