| FRDM-KW40Z Demo Software Reference Manual Rev 0.0 NXP Semiconductors |

Modules | Files | Data Structures | Macros | Typedefs | Enumerations | Enumerator | Functions | Variables
FXOS8700CQ
Accelerometer

## Overview

The FXOS8700CQ module implements the functions to initialize, configure, and read the FXOS8700CQ accelerometer + magnetometer sensor from NXP.

The sensor registers are described in the FXOS8700CQ Registers section.

The current driver version is 1.0 and it does not include these features:

1. Accelerometer filter
2. Accelerometer pulse detection
3. Accelerometer motion and free-fall
4. Accelerometer acceleration transient
5. Accelerometer orientation detection
6. Accelerometer vector magnitude change
7. FXOS8700 low-power configuration
8. Magnetometer magnetic threshold
9. Magnetometer vector-magnitude
10. Magnetometer magnetic Min/Max detection
11. FIFO configuration
12. SPI transport

## Modules
| FXOS8700CQ Registers

## Files
file | FXOS8700CQ_registers.h

## Data Structures
struct | FXOS8700CQ_config_t
struct | FXOS8700CQ_interrupt_config_t
struct | FXOS8700CQ_accelerometer_config_t
struct | FXOS8700CQ_magnetometer_config_t
struct | FXOS8700CQ_output_data_t

## Macros
#define | FXOS8700CQ_TRANSPORT_I2C
#define | FXOS8700CQ_I2C_ADDRESS
#define | FXOS8700CQ_I2C_INSTANCE
#define | FXOS8700CQ_I2C_BAUDRATE_KBPS
#define | FXOS8700CQ_TIMEOUT_MS

## Typedefs
typedef void(* | FXOS8700CQ_callback_function_t) (uint8_t *dataSource, uint8_t byteCount)

## Enumerations
enum | FXOS8700CQ_status_t { kStatusSuccess, kStatusTimeOutError, kStatusInitializationError, kStatusTransportBusyError, kStatusCommunicationsError, kStatusMemoryAllocationError }

## Functions
FXOS8700CQ_status_t | FXOS8700CQ_init (FXOS8700CQ_config_t *pConfigStruct)
FXOS8700CQ_status_t | FXOS8700CQ_start (void)
FXOS8700CQ_status_t | FXOS8700CQ_stop (void)
FXOS8700CQ_status_t | FXOS8700CQ_communication_test (void)
FXOS8700CQ_status_t | FXOS8700CQ_interrupt_configuration (FXOS8700CQ_interrupt_config_t *pConfigurationParameters)
FXOS8700CQ_status_t | FXOS8700CQ_get_interrupt_status (uint8_t *interruptStatus)
FXOS8700CQ_status_t | FXOS8700CQ_accelerometer_configuration (FXOS8700CQ_accelerometer_config_t *pConfigurationParameters)
FXOS8700CQ_status_t | FXOS8700CQ_get_accelerometer_readings (FXOS8700CQ_output_data_t *pAccelerometerData)
FXOS8700CQ_status_t | FXOS8700CQ_magnetometer_configuration (FXOS8700CQ_magnetometer_config_t *pConfigurationParameters)
FXOS8700CQ_status_t | FXOS8700CQ_get_magnetometer_readings (FXOS8700CQ_output_data_t *pMagnetometerData)
FXOS8700CQ_status_t | FXOS8700CQ_get_hybrid_sensor_readings (FXOS8700CQ_output_data_t *pAccelerometerData, FXOS8700CQ_output_data_t *pMagnetometerData)
FXOS8700CQ_status_t | FXOS8700CQ_get_registers (uint8_t startRegisterAddress, uint8_t byteCount, FXOS8700CQ_callback_function_t onCompletionCallback)
FXOS8700CQ_status_t | FXOS8700CQ_get_registers_blocking (uint8_t startRegisterAddress, uint8_t byteCount, uint8_t *pOutBuffer)
FXOS8700CQ_status_t | FXOS8700CQ_set_register (uint8_t registerAddress, uint8_t *registerDataPtr)
FXOS8700CQ_status_t | FXOS8700CQ_set_register_blocking (uint8_t registerAddress, uint8_t *registerDataPtr)

## Variables
unsigned char | FXOS8700CQ_CTRL_REG1_map_t::ctrl_reg1
unsigned char | FXOS8700CQ_CTRL_REG1_map_t::active: 1
unsigned char | FXOS8700CQ_CTRL_REG1_map_t::f_read: 1
unsigned char | FXOS8700CQ_CTRL_REG1_map_t::lnoise: 1
unsigned char | FXOS8700CQ_CTRL_REG1_map_t::dr: 3
unsigned char | FXOS8700CQ_CTRL_REG1_map_t::aslp_rate: 2
struct {
unsigned char | active: 1
unsigned char | f_read: 1
unsigned char | lnoise: 1
unsigned char | dr: 3
unsigned char | aslp_rate: 2
} | FXOS8700CQ_CTRL_REG1_map_t::ctrl_reg1_map
unsigned char | FXOS8700CQ_CTRL_REG2_map_t::ctrl_reg2
unsigned char | FXOS8700CQ_CTRL_REG2_map_t::mods: 2
unsigned char | FXOS8700CQ_CTRL_REG2_map_t::slpe: 1
unsigned char | FXOS8700CQ_CTRL_REG2_map_t::smods: 2
unsigned char | FXOS8700CQ_CTRL_REG2_map_t::reserved: 1
unsigned char | FXOS8700CQ_CTRL_REG2_map_t::rst: 1
unsigned char | FXOS8700CQ_CTRL_REG2_map_t::st: 1
struct {
unsigned char | mods: 2
unsigned char | slpe: 1
unsigned char | smods: 2
unsigned char | reserved: 1
unsigned char | rst: 1
unsigned char | st: 1
} | FXOS8700CQ_CTRL_REG2_map_t::ctrl_reg2_map
unsigned char | FXOS8700CQ_XYZ_DATA_CFG_map_t::xyz_data_cfg
unsigned char | FXOS8700CQ_XYZ_DATA_CFG_map_t::fs: 2
unsigned char | FXOS8700CQ_XYZ_DATA_CFG_map_t::reserved0: 2
unsigned char | FXOS8700CQ_XYZ_DATA_CFG_map_t::hpf_out: 1
unsigned char | FXOS8700CQ_XYZ_DATA_CFG_map_t::reserved1: 3
struct {
unsigned char | fs: 2
unsigned char | reserved0: 2
unsigned char | hpf_out: 1
unsigned char | reserved1: 3
} | FXOS8700CQ_XYZ_DATA_CFG_map_t::xyz_data_cfg_map
unsigned char | FXOS8700CQ_M_CTRL_REG1_map_t::m_ctrl_reg1
unsigned char | FXOS8700CQ_M_CTRL_REG1_map_t::m_hms: 2
unsigned char | FXOS8700CQ_M_CTRL_REG1_map_t::m_os: 3
unsigned char | FXOS8700CQ_M_CTRL_REG1_map_t::m_ost: 1
unsigned char | FXOS8700CQ_M_CTRL_REG1_map_t::m_rst: 1
unsigned char | FXOS8700CQ_M_CTRL_REG1_map_t::m_acal: 1
struct {
unsigned char | m_hms: 2
unsigned char | m_os: 3
unsigned char | m_ost: 1
unsigned char | m_rst: 1
unsigned char | m_acal: 1
} | FXOS8700CQ_M_CTRL_REG1_map_t::m_ctrl_reg1_map
unsigned char | FXOS8700CQ_M_CTRL_REG2_map_t::m_ctrl_reg2
unsigned char | FXOS8700CQ_M_CTRL_REG2_map_t::m_rst_cnt: 2
unsigned char | FXOS8700CQ_M_CTRL_REG2_map_t::m_maxmin_rst: 1
unsigned char | FXOS8700CQ_M_CTRL_REG2_map_t::m_maxmin_dis_ths: 1
unsigned char | FXOS8700CQ_M_CTRL_REG2_map_t::m_maxmin_dis: 1
unsigned char | FXOS8700CQ_M_CTRL_REG2_map_t::hyb_autoinc_mode: 1
unsigned char | FXOS8700CQ_M_CTRL_REG2_map_t::reserved: 2
struct {
unsigned char | m_rst_cnt: 2
unsigned char | m_maxmin_rst: 1
unsigned char | m_maxmin_dis_ths: 1
unsigned char | m_maxmin_dis: 1
unsigned char | hyb_autoinc_mode: 1
unsigned char | reserved: 2
} | FXOS8700CQ_M_CTRL_REG2_map_t::m_ctrl_reg2_map
unsigned char | FXOS8700CQ_M_CTRL_REG3_map_t::m_ctrl_reg3
unsigned char | FXOS8700CQ_M_CTRL_REG3_map_t::reserved: 3
unsigned char | FXOS8700CQ_M_CTRL_REG3_map_t::m_ths_xys_update: 1
unsigned char | FXOS8700CQ_M_CTRL_REG3_map_t::m_aslp_os: 3
unsigned char | FXOS8700CQ_M_CTRL_REG3_map_t::m_raw: 1
struct {
unsigned char | reserved: 3
unsigned char | m_ths_xys_update: 1
unsigned char | m_aslp_os: 3
unsigned char | m_raw: 1
} | FXOS8700CQ_M_CTRL_REG3_map_t::m_ctrl_reg3_map

## Data Structure Documentation

struct FXOS8700CQ_config_t

Configuration structure for the FXOS8700CQ initialization.

Data Fields
FXOS8700CQ_data_rate_hz_t | outputDataRate | Set the output data rate.
FXOS8700CQ_sensor_enable_t | enabledSensors | Set the sensors to enable.

struct FXOS8700CQ_interrupt_config_t

Configuration structure for the FXOS8700CQ interruptions initialization.

Data Fields
FXOS8700CQ_interrupt_sources_t | interruptSources | Interrupt sources to enable separated by | operator.
FXOS8700CQ_interrupt_pin_map_t | interruptPinMap | Interrupt sources to map to INT2 separated by | operator (mapped to INT1 when clear)

struct FXOS8700CQ_accelerometer_config_t

Configuration structure for the accelerometer sensor initialization.

Data Fields
FXOS8700CQ_sensitivity_t | sensitivity | Accelerometer sensitivity.
bool_t | fastModeEnabled | Enable fast mode; 8-bit output resolution when enabled.
bool_t | lowNoiseEnabled | Enable low noise; does not work with +-8g sensitivity.
FXOS8700CQ_oversampling_mods_t | oversamplingMod | Select the ADC oversampling mod.

struct FXOS8700CQ_magnetometer_config_t

Configuration structure for the magnetometer sensor initialization.

Data Fields
FXOS8700CQ_magnetometer_osr_t | oversamplingRatio | Magnetometer oversampling ratio.
FXOS8700CQ_magnetic_sensor_reset_t | autoSensorResetFreq | Magnetic sensor reset (degaussing) frequency.
bool_t | autoCalibrationEnabled | Enable sensor autocalibration.

struct FXOS8700CQ_output_data_t

Sensor ouput data presentation structure.

Data Fields
uint8_t | status | Output data status flags.
int16_t | xAxisData | X-Axis data in a signed 16-bit format.
int16_t | yAxisData | Y-Axis data in a signed 16-bit format.
int16_t | zAxisData | Z-Axis data in a signed 16-bit format.

## Macro Definition Documentation

#define FXOS8700CQ_TRANSPORT_I2C

I2C transport selected.

Select just one transport. If both are selected, I2C takes precedence

#define FXOS8700CQ_I2C_ADDRESS

I2C address configured for the FXOS8700CQ.

#define FXOS8700CQ_I2C_INSTANCE

I2C module instance to use.

#define FXOS8700CQ_I2C_BAUDRATE_KBPS

Baudrate (in kbit/s)

#define FXOS8700CQ_TIMEOUT_MS

Timeout for the blocking functions.

## Typedef Documentation

typedef void(* FXOS8700CQ_callback_function_t) (uint8_t *dataSource, uint8_t byteCount)

FXOS8700CQ non-blocking functions callback type.

## Enumeration Type Documentation

enum FXOS8700CQ_status_t

Status responses for the FXOS8700CQ driver functions.

Enumerator
kStatusSuccess | No error occured.
kStatusTimeOutError | Timeout error occured.
kStatusInitializationError | Error during initialization.
kStatusTransportBusyError | Transport is busy.
kStatusCommunicationsError | Error communicating with the FXOS8700CQ.
kStatusMemoryAllocationError | Error trying to allocate memory.

## Function Documentation

FXOS8700CQ_status_t FXOS8700CQ_init | ( | FXOS8700CQ_config_t * | pConfigStruct | ) |

Initializes the FXOS8700CQ module over the selected transport

Parameters

  [in] | pConfigStruct | Module configuration structure (See FXOS8700CQ_config_t )

Returns
  FXOS8700CQ_status_t Function execution status

FXOS8700CQ_status_t FXOS8700CQ_start | ( | void |  | ) |

Starts the FXOS8700CQ module

Parameters

  [in] | None |

Returns
  FXOS8700CQ_status_t Function execution status

FXOS8700CQ_status_t FXOS8700CQ_stop | ( | void |  | ) |

Stops the FXOS8700CQ module

Parameters

  [in] | None |

Returns
  FXOS8700CQ_status_t Function execution status

FXOS8700CQ_status_t FXOS8700CQ_communication_test | ( | void |  | ) |

Executes communications tests by reading the WHO AM I register

Parameters

  [in] | None |

Returns
  FXOS8700CQ_status_t Function execution status

FXOS8700CQ_status_t FXOS8700CQ_interrupt_configuration | ( | FXOS8700CQ_interrupt_config_t * | pConfigurationParameters | ) |

Configures the FXOS8700CQ module to generate interrupt requests using the INT1 and INT2 pins.

Parameters

  [in] | pConfigurationParameters | Interrupt configuration parameters (See FXOS8700CQ_interrupt_config_t)

Returns
  FXOS8700CQ_status_t Function execution status

FXOS8700CQ_status_t FXOS8700CQ_get_interrupt_status | ( | uint8_t * | interruptStatus | ) |

Gets the current interrupt status register

Parameters

  [out] | interruptStatus | Pointer to the 8-bit variable where the result is to be stored

Returns
  FXOS8700CQ_status_t Function execution status

FXOS8700CQ_status_t FXOS8700CQ_accelerometer_configuration | ( | FXOS8700CQ_accelerometer_config_t * | pConfigurationParameters | ) |

Configures the accelerometer sensor

Parameters

  [in] | pConfigurationParameters | Configuration structure for the accelerometer (see FXOS8700CQ_accelerometer_config_t)

Returns
  FXOS8700CQ_status_t Function execution status

FXOS8700CQ_status_t FXOS8700CQ_get_accelerometer_readings | ( | FXOS8700CQ_output_data_t * | pAccelerometerData | ) |

Reads the accelerometer data from the FXOS8700CQ

Parameters

  [out] | pAccelerometerData | Pointer to the structure where the results are to be stored (see FXOS8700CQ_output_data_t)

Returns
  FXOS8700CQ_status_t Function execution status

FXOS8700CQ_status_t FXOS8700CQ_magnetometer_configuration | ( | FXOS8700CQ_magnetometer_config_t * | pConfigurationParameters | ) |

Configures the magnetometer sensor

Parameters

  [in] | pConfigurationParameters | Configuration structure for the magnetometer (see FXOS8700CQ_magnetometer_config_t)

Returns
  FXOS8700CQ_status_t Function execution status

FXOS8700CQ_status_t FXOS8700CQ_get_magnetometer_readings | ( | FXOS8700CQ_output_data_t * | pMagnetometerData | ) |

Reads the magnetometer data from the FXOS8700CQ

Parameters

  [out] | pMagnetometerData | Pointer to the structure where the results are to be stored (see FXOS8700CQ_output_data_t)

Returns
  FXOS8700CQ_status_t Function execution status

FXOS8700CQ_status_t FXOS8700CQ_get_hybrid_sensor_readings | ( | FXOS8700CQ_output_data_t * | pAccelerometerData,
|  | FXOS8700CQ_output_data_t * | pMagnetometerData
| ) |  |

Reads the accelerometer and magnetometer data in a single sequence

Parameters

  [out] | pAccelerometerData | Pointer to the structure where the results are to be stored (see FXOS8700CQ_output_data_t)
  [out] | pMagnetometerData | Pointer to the structure where the results are to be stored (see FXOS8700CQ_output_data_t)

Returns
  FXOS8700CQ_status_t Function execution status

Note
  When using this function to read the magnetometer data, the magnetometer STATUS byte in the struct is not updated.

FXOS8700CQ_status_t FXOS8700CQ_get_registers | ( | uint8_t | startRegisterAddress,
|  | uint8_t | byteCount,
|  | FXOS8700CQ_callback_function_t | onCompletionCallback
| ) |  |

Reads a sequence of the FXOS8700CQ registers

Parameters

  [in] | startRegisterAddress | Address for the first register to read
  [in] | byteCount | Number of registers to read
  [in] | onCompletionCallback | Callback function to execute upon read complete. This function must be compatible with the FXOS8700CQ_callback_function_t type.

Returns
  FXOS8700CQ_status_t Function execution status

FXOS8700CQ_status_t FXOS8700CQ_get_registers_blocking | ( | uint8_t | startRegisterAddress,
|  | uint8_t | byteCount,
|  | uint8_t * | pOutBuffer
| ) |  |

Reads a sequence of the FXOS8700CQ registers blocking the execution until completion.

Parameters

  [in] | startRegisterAddress | Address for the first register to read
  [in] | byteCount | Number of registers to read
  [out] | pOutBuffer | Pointer to the buffer where the data are to be stored

Returns
  FXOS8700CQ_status_t Function execution status

FXOS8700CQ_status_t FXOS8700CQ_set_register | ( | uint8_t | registerAddress,
|  | uint8_t * | registerDataPtr
| ) |  |

Starts a FXOS8700CQ register write.

Parameters

  [in] | registerAddress | Address for the register to write.
  [in] | registerDataPtr | Pointer to the variable containing the data to write.

Returns
  FXOS8700CQ_status_t Function execution status

FXOS8700CQ_status_t FXOS8700CQ_set_register_blocking | ( | uint8_t | registerAddress,
|  | uint8_t * | registerDataPtr
| ) |  |

Starts a FXOS8700CQ register write and waits until it is complete.

Parameters

  [in] | registerAddress | Address for the register to write.
  [in] | registerDataPtr | Pointer to the variable containing the data to write.

Returns
  FXOS8700CQ_status_t Function execution status

## Variable Documentation

unsigned char FXOS8700CQ_CTRL_REG1_map_t::ctrl_reg1

unsigned { ... } ::active

unsigned { ... } ::f_read

unsigned { ... } ::lnoise

unsigned { ... } ::dr

unsigned { ... } ::aslp_rate

struct { ... } FXOS8700CQ_CTRL_REG1_map_t::ctrl_reg1_map

unsigned char FXOS8700CQ_CTRL_REG2_map_t::ctrl_reg2

unsigned { ... } ::mods

unsigned { ... } ::slpe

unsigned { ... } ::smods

unsigned { ... } ::reserved

unsigned { ... } ::rst

unsigned { ... } ::st

struct { ... } FXOS8700CQ_CTRL_REG2_map_t::ctrl_reg2_map

unsigned char FXOS8700CQ_XYZ_DATA_CFG_map_t::xyz_data_cfg

unsigned { ... } ::fs

unsigned { ... } ::reserved0

unsigned { ... } ::hpf_out

unsigned { ... } ::reserved1

struct { ... } FXOS8700CQ_XYZ_DATA_CFG_map_t::xyz_data_cfg_map

unsigned char FXOS8700CQ_M_CTRL_REG1_map_t::m_ctrl_reg1

unsigned { ... } ::m_hms

unsigned { ... } ::m_os

unsigned { ... } ::m_ost

unsigned { ... } ::m_rst

unsigned { ... } ::m_acal

struct { ... } FXOS8700CQ_M_CTRL_REG1_map_t::m_ctrl_reg1_map

unsigned char FXOS8700CQ_M_CTRL_REG2_map_t::m_ctrl_reg2

unsigned { ... } ::m_rst_cnt

unsigned { ... } ::m_maxmin_rst

unsigned { ... } ::m_maxmin_dis_ths

unsigned { ... } ::m_maxmin_dis

unsigned { ... } ::hyb_autoinc_mode

unsigned { ... } ::reserved

struct { ... } FXOS8700CQ_M_CTRL_REG2_map_t::m_ctrl_reg2_map

unsigned char FXOS8700CQ_M_CTRL_REG3_map_t::m_ctrl_reg3

unsigned { ... } ::reserved

unsigned { ... } ::m_ths_xys_update

unsigned { ... } ::m_aslp_os

unsigned { ... } ::m_raw

struct { ... } FXOS8700CQ_M_CTRL_REG3_map_t::m_ctrl_reg3_map