CM-X300: WinCE: I2C Programming

From Compulab Mediawiki
Revision as of 09:38, 14 March 2010 by Mike (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Introduction

This sample application demonstrates the I2C communication with CAT9555 GPIO extender located on SB-X300. The CAT9555 datasheet is available at: 9555.pdf.

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 in the SB-X300 to be low.

Connecting Custom Device

I2C physical interface:

Signal Name SB-X300 CM-X300
SCL Pin 27 of connector P12 Pin 61 on the CAMI connector P1
SDA Pin 26 of connector P12 Pin 60 on the CAMI connector P1

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