EM-X270: WinCE: I2C Sample

From Compulab Mediawiki
Jump to: navigation, search

Introduction

This sample application demonstrates the I2C communication between EM-X270 and CAT9555 GPIO extender located on EB-X270. The CAT9555 datasheet is available at: 9555.pdf.

The I2C sample is located in the EM-X270 run-time image package in the \x270-em-wince6-img\Demo Applications\I2CSample folder.


I2C Sample

The sample application performs the following actions:

  • Read the configuration registers. Normal mode clock is used.
  • Write registers. Set all pins, except for pin 0, to inputs.
  • Read the registers to verify write.
  • Read the output port register.
  • Write the output port register. Configure pin 1 on P9 connector on the EB-X270 to be low.

Connecting Custom Device

I2C physical interface:

Signal Name EB-X270 EM-X270
SCL Pin 19 of U5 Pin 132 on the CAMI
SDA Pin 20 of U5 Pin 136 on the CAMI

I2C Driver API

The Windows CE demo image includes an I2C driver that allows interaction with I2C devices. The I2C driver is a stream driver that may be accessed using the "I2C" prefix. The following pseudo code describes the driver’s algorithm:

1.  Set the clock speed according to mClkSpeed
2.  FOR i=0 TO i=mTransaction-1
      IF (mOpCode[i] == I2C_OPCODE_WRITE) THEN
         FOR j=0 TO mTransLen[i]-1   
           write mBuffer[mBufferOffset[i]+j] to the bus.
      ELSE IF (mOpCode[i] ==  I2C_OPCODE_READ) THEN 
         FOR j=0 TO mTransLen[i]-1
           read mTransLen[i] bytes from the bus into mBuffer[mBufferOffset[i]+j]
      ELSE “Fail – OpCode not supported”

Data Types

PXA_I2C_SPEED_T

Values
PXA_I2C_FAST_SPEED - use 400KHz clock
PXA_I2C_NORMAL_SPEED - use 100KHz clock


PXA_I2C_OPERATION_CODE

Values
I2C_OPCODE_READ
I2C_OPCODE_WRITE


I2CTRANS

Fields
Name
Description
DWORD mTransactions Number f transactions to perform
PXA_I2C_SPEED_T mClkSpeed
UCHAR mDeviceAddr 7 bit I2C address
PXA_I2C_OPERATION_CODE *mOpCode
DWORD *mBufferOffset The offset for the data in the array for each transaction
DWORD *mTransLen The length of each transaction
DWORD mErrorCode
UCHAR *mBuffer The buffer with the data for all the transactions

Functions

HANDLE I2CUserOpen()

Opens an instance of the I2C Driver.

Return Values
Returns a handle that should be used to access the driver. Nonzero indicates success.


void I2CUserClose(HANDLE hDevice)

Closes the driver handle

Parameters
  • hDevice - Handle to an open driver instance



void I2CUserTransact(HANDLE hDevice, I2CTRANS* pTrans)

Perform the I2C transaction

Parameters
  • hDevice - Handle to an open driver instance
  • pTrans
Return Values
TRUE on success