MCUXpresso SDK Documentation

i2c_read_accel_value_transfer

i2c_read_accel_value_transfer#

Overview#

The i2c_read_accel_value example shows how to use I2C driver to communicate with an i2c device:

  1. How to use the i2c driver to read a i2c device who_am_I register.

  2. How to use the i2c driver to write/read the device registers.

In this example, the values of three-axis accelerometer print to the serial terminal on PC through the virtual serial port on board.

Supported Boards#

EVK-MIMXRT595
Hardware requirements
  • Micro USB cable

  • EVK-MIMXRT595 board

  • Personal Computer

Board settings
Prepare the Demo
  1. Connect a micro USB cable between the PC host and the CMSIS DAP USB port (J40) on the board

  2. Open a serial terminal with the following settings:

    • 115200 baud rate

    • 8 data bits

    • No parity

    • One stop bit

    • No flow control

  3. Download the program to the target board.

  4. Launch the debugger in your IDE to begin running the demo.

Running the demo

When the example runs successfully, you can see the similar information from the terminal as below.

I2C example -- Read Accelerometer Value
Found an FXOS8700 on board , the device address is 0x1e .
The accel values:
status_reg = 0xff , x =    20 , y =  -102 , z =  2102
status_reg = 0xff , x =    83 , y =   -51 , z =  2089
status_reg = 0xff , x =    66 , y =   -53 , z =  2101
status_reg = 0xff , x =    51 , y =   -80 , z =  2098
status_reg = 0xff , x =    15 , y =   -99 , z =  2105
status_reg = 0xff , x =    44 , y =   -89 , z =  2097
status_reg = 0xff , x =    53 , y =   -56 , z =  2099
status_reg = 0xff , x =    54 , y =   -78 , z =  2103
status_reg = 0xff , x =    25 , y =   -98 , z =  2098
status_reg = 0xff , x =    17 , y =  -118 , z =  2107

End of I2C example .
EVK-MIMXRT685
Hardware requirements
  • Micro USB cable

  • EVK-MIMXRT685 board

  • Personal Computer

Board settings

Make sure J15 and J30 are shorted.

Prepare the Demo
  1. Connect a micro USB cable between the PC host and the CMSIS DAP USB port (J5) on the board

  2. Open a serial terminal with the following settings:

    • 115200 baud rate

    • 8 data bits

    • No parity

    • One stop bit

    • No flow control

  3. Download the program to the target board.

  4. Launch the debugger in your IDE to begin running the demo.

Running the demo

The following message shows in the terminal if the example runs successfully.

I2C example -- Read Accelerometer Value
Found an FXOS8700 on board , the device address is 0x1e.
The accel values:
status_reg = 0xff , x =   -88 , y =   -84 , z =  2084 
status_reg = 0xff , x =   -84 , y =   -88 , z =  2096 
status_reg = 0xff , x =   -84 , y =   -88 , z =  2092 
status_reg = 0xff , x =   -76 , y =   -88 , z =  2104 
status_reg = 0xff , x =   -80 , y =   -88 , z =  2096 
status_reg = 0xff , x =   -84 , y =   -80 , z =  2100 
status_reg = 0xff , x =   -80 , y =   -80 , z =  2080 
status_reg = 0xff , x =   -72 , y =   -92 , z =  2088 
status_reg = 0xff , x =   -84 , y =   -88 , z =  2084 
status_reg = 0xff , x =   -88 , y =   -88 , z =  2104 

End of I2C example .
FRDM-K22F
Hardware requirements
  • Mini/Micro USB cable

  • FRDM-K22F board

  • Personal Computer

Board settings

No special is needed.

Prepare the Demo
  1. Connect a mini USB cable between the PC host and the OpenSDA USB port on the board.

  2. Open a serial terminal on PC for OpenSDA serial device with these settings:

    • 115200 baud rate

    • 8 data bits

    • No parity

    • One stop bit

    • No flow control

  3. Download the program to the target board.

  4. Either press the reset button on your board or launch the debugger in your IDE to begin running the demo.

Running the demo

When the example runs successfully, you can see the similar information from the terminal as below.

I2C example – Read Accelerometer Value Found an FXOS8700 on board , the device address is 0x1d . The accel values: status_reg = 0xff , x = -10 , y = 31 , z = 2025 status_reg = 0xff , x = -6 , y = 32 , z = 2022 status_reg = 0xff , x = -9 , y = 35 , z = 2023 status_reg = 0xff , x = -4 , y = 32 , z = 2034 status_reg = 0xff , x = -12 , y = 32 , z = 2020 status_reg = 0xff , x = -8 , y = 33 , z = 2022 status_reg = 0xff , x = -8 , y = 33 , z = 2017 status_reg = 0xff , x = -9 , y = 35 , z = 2024 status_reg = 0xff , x = -7 , y = 35 , z = 2018 status_reg = 0xff , x = -5 , y = 33 , z = 2019

End of I2C example .

FRDM-K32L2B
Hardware requirements
  • Mini/Micro USB cable

  • FRDM-K32L2B board

  • Personal Computer

Board settings

FXOS8700 must be available on board to run this example. If it’s not soldered, the example cannot work.

Prepare the Demo
  1. Connect a mini USB cable between the PC host and the OpenSDA USB port on the board.

  2. Open a serial terminal on PC for OpenSDA serial device with these settings:

    • 115200 baud rate

    • 8 data bits

    • No parity

    • One stop bit

    • No flow control

  3. Download the program to the target board.

  4. Either press the reset button on your board or launch the debugger in your IDE to begin running the demo.

Running the demo

When the example runs successfully, you can see the similar information from the terminal as below.

I2C example – Read Accelerometer Value Found an FXOS8700 on board , the device address is 0x1c . The accel values: status_reg = 0xff , x = -10 , y = 31 , z = 2025 status_reg = 0xff , x = -6 , y = 32 , z = 2022 status_reg = 0xff , x = -9 , y = 35 , z = 2023 status_reg = 0xff , x = -4 , y = 32 , z = 2034 status_reg = 0xff , x = -12 , y = 32 , z = 2020 status_reg = 0xff , x = -8 , y = 33 , z = 2022 status_reg = 0xff , x = -8 , y = 33 , z = 2017 status_reg = 0xff , x = -9 , y = 35 , z = 2024 status_reg = 0xff , x = -7 , y = 35 , z = 2018 status_reg = 0xff , x = -5 , y = 33 , z = 2019

End of I2C example .

FRDM-KE02Z40M
Hardware requirements
  • Mini USB cable

  • FRDM-KE02Z40M board

  • Personal Computer

Board settings

No special is needed.

Prepare the Demo
  1. Connect a mini USB cable between the PC host and the OpenSDA USB port on the board.

  2. Open a serial terminal on PC for OpenSDA serial device with these settings:

    • 115200 baud rate

    • 8 data bits

    • No parity

    • One stop bit

    • No flow control

  3. Download the program to the target board.

  4. Either press the reset button on your board or launch the debugger in your IDE to begin running the demo.

Running the demo

When the example runs successfully, you can see the similar information from the terminal as below.

I2C example – Read Accelerometer Value Found an MMA8451 on board , the device address is 0x1d . The accel values: status_reg = 0xff , x = -82 , y = -194 , z = 2058 status_reg = 0xff , x = -79 , y = -198 , z = 2055 status_reg = 0xff , x = -78 , y = -194 , z = 2057 status_reg = 0xff , x = -82 , y = -191 , z = 2058 status_reg = 0xff , x = -82 , y = -190 , z = 2057 status_reg = 0xff , x = -80 , y = -192 , z = 2059 status_reg = 0xff , x = -79 , y = -186 , z = 2058 status_reg = 0xff , x = -85 , y = -187 , z = 2050 status_reg = 0xff , x = -83 , y = -192 , z = 2048 status_reg = 0xff , x = -81 , y = -196 , z = 2054

End of I2C example .

LPCXpresso55S06
Hardware requirements
  • Mini/Micro USB cable

  • LPCXpresso55S06 board

  • Personal Computer

Board settings

This project does not use the default serial port. P1_10(J13-4) for UART RX, P1_11(J13_6) for UART TX.

Prepare the Demo
  1. Connect a micro USB cable between the PC host and the LPC-Link USB port (J1) on the board.

  2. Open a serial terminal on PC for JLink serial device with these settings:

    • 115200 baud rate

    • 8 data bits

    • No parity

    • One stop bit

    • No flow control

  3. Download the program to the target board.

  4. Either press the reset button on your board or launch the debugger in your IDE to begin running the demo.

Running the demo

When the example runs successfully, you can see the similar information from the terminal as below.

I2C example – Read Accelerometer Value Found an MMA8652 on board , the device address is 0x1d . The accel values: status_reg = 0xff , x = -192 , y = 188 , z = 2152 status_reg = 0xff , x = -168 , y = 192 , z = 2160 status_reg = 0xff , x = -180 , y = 152 , z = 2144 status_reg = 0xff , x = -200 , y = 132 , z = 2064 status_reg = 0xff , x = -192 , y = 108 , z = 2196 status_reg = 0xff , x = -232 , y = 136 , z = 2092 status_reg = 0xff , x = -260 , y = 192 , z = 1992 status_reg = 0xff , x = -240 , y = 304 , z = 1968 status_reg = 0xff , x = -208 , y = 336 , z = 1976 status_reg = 0xff , x = -208 , y = 296 , z = 1900

End of I2C example .

LPCXpresso55S16
Hardware requirements
  • Mini/Micro USB cable

  • LPCXpresso55S16 boards

  • Personal Computer

Board settings

No special settings are required. The jumper setting: Default jumpers configuration does not work, you will need to add JP20 and JP21 (JP22 optional for ADC use)

Prepare the Demo
  1. Connect a micro USB cable between the PC host and the LPC-Link USB port (J1) on the board.

  2. Open a serial terminal on PC for JLink serial device with these settings:

    • 115200 baud rate

    • 8 data bits

    • No parity

    • One stop bit

    • No flow control

  3. Download the program to the target board.

  4. Either press the reset button on your board or launch the debugger in your IDE to begin running the demo.

Running the demo

When the example runs successfully, you can see the similar information from the terminal as below.

I2C example – Read Accelerometer Value Found an MMA8652 on board , the device address is 0x1d . The accel values: status_reg = 0xff , x = -192 , y = 188 , z = 2152 status_reg = 0xff , x = -168 , y = 192 , z = 2160 status_reg = 0xff , x = -180 , y = 152 , z = 2144 status_reg = 0xff , x = -200 , y = 132 , z = 2064 status_reg = 0xff , x = -192 , y = 108 , z = 2196 status_reg = 0xff , x = -232 , y = 136 , z = 2092 status_reg = 0xff , x = -260 , y = 192 , z = 1992 status_reg = 0xff , x = -240 , y = 304 , z = 1968 status_reg = 0xff , x = -208 , y = 336 , z = 1976 status_reg = 0xff , x = -208 , y = 296 , z = 1900

End of I2C example .

LPCXpresso55S28
Hardware requirements
  • Mini/Micro USB cable

  • LPCXpresso55S28 boards

  • Personal Computer

Board settings

No special settings are required.

# Prepare the Demo

Note: MCUXpresso IDE project default debug console is semihost

  1. Connect a micro USB cable between the PC host and the LPC-Link USB port (P6) on the board.

  2. Open a serial terminal on PC for JLink serial device with these settings:

    • 115200 baud rate

    • 8 data bits

    • No parity

    • One stop bit

    • No flow control

  3. Download the program to the target board.

  4. Either press the reset button on your board or launch the debugger in your IDE to begin running the demo.

Running the demo

When the example runs successfully, you can see the similar information from the terminal as below.

I2C example – Read Accelerometer Value Found an MMA8652 on board , the device address is 0x1d . The accel values: status_reg = 0xff , x = -192 , y = 188 , z = 2152 status_reg = 0xff , x = -168 , y = 192 , z = 2160 status_reg = 0xff , x = -180 , y = 152 , z = 2144 status_reg = 0xff , x = -200 , y = 132 , z = 2064 status_reg = 0xff , x = -192 , y = 108 , z = 2196 status_reg = 0xff , x = -232 , y = 136 , z = 2092 status_reg = 0xff , x = -260 , y = 192 , z = 1992 status_reg = 0xff , x = -240 , y = 304 , z = 1968 status_reg = 0xff , x = -208 , y = 336 , z = 1976 status_reg = 0xff , x = -208 , y = 296 , z = 1900

End of I2C example .

LPCXpresso55S69
Hardware requirements
  • Mini/Micro USB cable

  • LPCXpresso55s69 boards

  • Personal Computer

Board settings

No special settings are required.

# Prepare the Demo

Note: MCUXpresso IDE project default debug console is semihost

  1. Connect a micro USB cable between the PC host and the LPC-Link USB port (P6) on the board.

  2. Open a serial terminal on PC for JLink serial device with these settings:

    • 115200 baud rate

    • 8 data bits

    • No parity

    • One stop bit

    • No flow control

  3. Download the program to the target board.

  4. Either press the reset button on your board or launch the debugger in your IDE to begin running the demo.

Running the demo

When the example runs successfully, you can see the similar information from the terminal as below.

I2C example – Read Accelerometer Value Found an MMA8652 on board , the device address is 0x1d . The accel values: status_reg = 0xff , x = -192 , y = 188 , z = 2152 status_reg = 0xff , x = -168 , y = 192 , z = 2160 status_reg = 0xff , x = -180 , y = 152 , z = 2144 status_reg = 0xff , x = -200 , y = 132 , z = 2064 status_reg = 0xff , x = -192 , y = 108 , z = 2196 status_reg = 0xff , x = -232 , y = 136 , z = 2092 status_reg = 0xff , x = -260 , y = 192 , z = 1992 status_reg = 0xff , x = -240 , y = 304 , z = 1968 status_reg = 0xff , x = -208 , y = 336 , z = 1976 status_reg = 0xff , x = -208 , y = 296 , z = 1900

End of I2C example .

TWR-KM34Z50MV3
Hardware requirements
  • Mini USB cable

  • TWR-KM34Z50MV3 board

  • Personal Computer

Board settings

No special settings are required.

Prepare the Demo
  1. Connect a USB cable between the host PC and the OpenSDA USB port on the target board.

  2. Open a serial terminal with the following settings:

    • 115200 baud rate

    • 8 data bits

    • No parity

    • One stop bit

    • No flow control

  3. Download the program to the target board.

  4. Either press the reset button on your board or launch the debugger in your IDE to begin running the demo.

Running the demo

When the demo runs successfully, similar message will be displayed in the terminal:

I2C example – Read Accelerometer Value Found MMA8491 on board, the device address is 0x55. The accel values: status_reg = 0xf , x = -26 , y = 29 , z = 1036 status_reg = 0xf , x = -7 , y = -6 , z = 1017 status_reg = 0xf , x = -4 , y = 43 , z = 1031 status_reg = 0xf , x = -22 , y = 33 , z = 1035 status_reg = 0xf , x = -18 , y = 35 , z = 1020 status_reg = 0xf , x = 2 , y = 11 , z = 1029 status_reg = 0xf , x = -10 , y = 34 , z = 1029 status_reg = 0xf , x = 1 , y = 15 , z = 1016 status_reg = 0xf , x = -8 , y = 41 , z = 1041 status_reg = 0xf , x = -21 , y = 20 , z = 1045

End of I2C example .

TWR-KM34Z75M
Hardware requirements
  • Mini/Micro USB cable

  • TWR-KM34Z75M board

  • Personal Computer

Board settings

No special settings are required.

Prepare the Demo
  1. Connect a USB cable between the host PC and the OpenSDA USB port on the target board.

  2. Open a serial terminal with the following settings:

    • 115200 baud rate

    • 8 data bits

    • No parity

    • One stop bit

    • No flow control

  3. Download the program to the target board.

  4. Either press the reset button on your board or launch the debugger in your IDE to begin running the demo.

Running the demo

When the demo runs successfully, the following message is displayed in the terminal:

I2C example – Read Accelerometer Value Found an MMA8451 on board , the device address is 0x1d . The accel values: status_reg = 0xff , x = -10 , y = 31 , z = 2025 status_reg = 0xff , x = -6 , y = 32 , z = 2022 status_reg = 0xff , x = -9 , y = 35 , z = 2023 status_reg = 0xff , x = -4 , y = 32 , z = 2034 status_reg = 0xff , x = -12 , y = 32 , z = 2020 status_reg = 0xff , x = -8 , y = 33 , z = 2022 status_reg = 0xff , x = -8 , y = 33 , z = 2017 status_reg = 0xff , x = -9 , y = 35 , z = 2024 status_reg = 0xff , x = -7 , y = 35 , z = 2018 status_reg = 0xff , x = -5 , y = 33 , z = 2019

End of I2C example .

TWR-KM35Z75M
Hardware requirements
  • Micro USB cable

  • TWR-KM35Z75M board

  • Personal Computer

Board settings

No special settings are required.

Prepare the Demo
  1. Connect a USB cable between the host PC and the OpenSDA USB port on the target board.

  2. Open a serial terminal with the following settings:

    • 115200 baud rate

    • 8 data bits

    • No parity

    • One stop bit

    • No flow control

  3. Download the program to the target board.

  4. Either press the reset button on your board or launch the debugger in your IDE to begin running the demo.

Running the demo

When the demo runs successfully, the following message is displayed in the terminal:

I2C example – Read Accelerometer Value Found an MMA8451 on board , the device address is 0x1d . The accel values: status_reg = 0xff , x = -10 , y = 31 , z = 2025 status_reg = 0xff , x = -6 , y = 32 , z = 2022 status_reg = 0xff , x = -9 , y = 35 , z = 2023 status_reg = 0xff , x = -4 , y = 32 , z = 2034 status_reg = 0xff , x = -12 , y = 32 , z = 2020 status_reg = 0xff , x = -8 , y = 33 , z = 2022 status_reg = 0xff , x = -8 , y = 33 , z = 2017 status_reg = 0xff , x = -9 , y = 35 , z = 2024 status_reg = 0xff , x = -7 , y = 35 , z = 2018 status_reg = 0xff , x = -5 , y = 33 , z = 2019

End of I2C example .