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

다운로드
페이지 100
FXOS8700CQ
Sensors
32
Freescale Semiconductor, Inc.
9.4
FXOS8700CQConfiguration function
This function configures the FXOS8700CQ for 200-Hz hybrid mode meaning that both accelerometer and magnetometer data 
are provided at the 200-Hz rate.The code is self-explanatory and can be easily customized for different settings.
Example 5. 
// function configures FXOS8700CQcombination accelerometer and magnetometer sensor
 static _mqx_int s_FXOS8700CQ_start(MQX_FILE_PTR aFP)
{
uint8_t databyte;
// read and check the FXOS8700CQ WHOAMI register
if (s_i2c_read_regs(aFP, FXOS8700CQ_SLAVE_ADDR, FXOS8700CQ_WHOAMI, &databyte, 
(uint8_t) 1) != 1)
{
return (I2C_ERROR);
}
if (databyte != FXOS8700CQ_WHOAMI_VAL)
{
return (I2C_ERROR);
}
// write 0000 0000 = 0x00 to accelerometer control register 1 to place FXOS8700CQ 
into
// standby
// [7-1] = 0000 000
// [0]: active=0
databyte = 0x00;
if (s_i2c_write_regs(aFP, FXOS8700CQ_SLAVE_ADDR, FXOS8700CQ_CTRL_REG1, &databyte, 
(uint8_t) 1) != 1)
{
return (I2C_ERROR);
}
// write 0001 1111 = 0x1F to magnetometer control register 1
// [7]: m_acal=0: auto calibration disabled
// [6]: m_rst=0: no one-shot magnetic reset
// [5]: m_ost=0: no one-shot magnetic measurement
// [4-2]: m_os=111=7: 8x oversampling (for 200Hz) to reduce magnetometer noise
// [1-0]: m_hms=11=3: select hybrid mode with accel and magnetometer active
databyte = 0x1F;
if (s_i2c_write_regs(aFP, FXOS8700CQ_SLAVE_ADDR, FXOS8700CQ_M_CTRL_REG1, 
&databyte, (uint8_t) 1) != 1)
{
return (I2C_ERROR);
}
// write 0010 0000 = 0x20 to magnetometer control register 2
// [7]: reserved
// [6]: reserved
// [5]: hyb_autoinc_mode=1 to map the magnetometer registers to follow the 
// accelerometer registers
// [4]: m_maxmin_dis=0 to retain default min/max latching even though not used
// [3]: m_maxmin_dis_ths=0
// [2]: m_maxmin_rst=0
// [1-0]: m_rst_cnt=00 to enable magnetic reset each cycle
databyte = 0x20;