5.7.7. I2C Master Example

This page is regarding the documentation on I2CM, for more information on I2CM Transaction, See Section 3.6 I2CM / Secure Sensor

5.7.7.1. Prerequisites

../../../_images/i2cm-accelerometer-k64f-wiring.png

Here is a photograph of above wiring diagram.

../../../_images/i2cm-accelerometer-k64f-photo.jpg

Note

  • We are using 2nd freedom K64F board only for connecting Accelerometer device to I2CM.

  • Short Jumper J9 & J10 of se050ARD board.

5.7.7.1.1. Disable K64F on board 2

Warning

If the K64F of the 2nd board doing some operations on I2C Pins, this demo would not work.

Follow below steps to make this demo work.

  • Flash frdmk64f_nop_wfi.bin binary located at demos/se05x/se05x_I2cMaster directory to K64F board.

  • This binary will put K64F in unoperation state and we will have easy access to Accelerometer through I2C pins.

Below is the c code

int main(void)
{
    /* Init board hardware. */
    BOARD_InitPins();
    BOARD_BootClockRUN();
    BOARD_InitDebugConsole();

    __disable_irq();
    while (1)
    {
        __disable_irq();
        __WFI();
    }
}

5.7.7.2. About the Example

This example reads Accelerometer data via the I2C master interface.

The Accelerometer on other K64F is used as an I2C Slave.

../../../_images/I2C-Master-operation.png

It uses the following APIs and data types:

5.7.7.3. Running the Demo

  1. Import project cmake_project_frdmk64f from simw-top/projects directory.

  2. Mention BUILD_TARGET as se05x_I2cMaster or se05x_I2cMasterWithAttestation in Debug/Makefile.

  3. Build the project and flash binary inside FRDMK64F_SE050ARD board.

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

  5. Rotate second K64F in any direction.

If everything is setup correctly the output would be as follows:

App:INFO :I2CM example to read Accelerometer value
   App:INFO :x =   113 , y =   -73 , z =  2118
   App:INFO :x =   109 , y =   -67 , z =  2103
   App:INFO :x =   108 , y =   -68 , z =  2120
   App:INFO :x =   117 , y =   -69 , z =  2109
   App:INFO :x =   117 , y =   -71 , z =  2105
   App:INFO :x =   111 , y =   -71 , z =  2108
   App:INFO :x =   115 , y =   -72 , z =  2104
   App:INFO :x =   117 , y =   -69 , z =  2122
   App:INFO :x =   115 , y =   -73 , z =  2120
   App:INFO :x =   115 , y =   -74 , z =  2114
   App:INFO :I2CM test completed !!!...