EM-X270: WinCE: SPI Sample

From Compulab Mediawiki
Revision as of 16:18, 15 March 2010 by Kostyas (talk)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Introduction

The SPI sample application demonstrates the SPI communication between EM-X270 and Maxim Semiconductor DS1722 thermometer. The DS1722 manual is available at: DS1722 manual.

This sample is located in the EM-X270 run-time image package at \x270-em-wince6-img\Demo Applications\SPI_Thermometer folder.


SPI Sample

controller.

Connecting the device to EM-X270

  • The SPI device can be connected to the SSP1 port available on the connector P6 on EB-X270. The following table describes the SSP pins:
EB-X270 P6 Pin Number DS1722 Pin Number
1 (SSP1_TXD) 6 (SDI)
2 (SSP1_RXD) 5 (SDO)
3 (SSP1_CLK) 3 (SCLK)
  • Connect EM-X270 GPIO 108 (GPIO used as SPI chip select) to pin 2 (CE) of DS1722.
  • Connect pin 6 (SERMODE) of DS1722 to VDD.
  • Connect all remaining DS1722 pins to VDD and GND. You can use available EM-X270 GPIOs to supply VDD and GND to DS1722. The following table summarizes the list of GPIOs used to supply VDD and GND to DS1722.
EM-X270 GPIO number GPIO location GPIO Functionality
22 pin 10 of P2 connector on EM-X270 keypad extender DS1722 GND
36 pin 19 of P2 connector on EM-X270 keypad extender DS1722 VDDD
96 pin 8 of P2 connector on EM-X270 keypad extender DS1722 VDDA
91 pin 7 of P2 connector on EM-X270 keypad extender DS1722 SERMOD
108 pin 6 of P2 connector on EM-X270 keypad extender DS1722 CE

SPI Sample

The SPI Sample performs the following actions:

  • Configure the SPI clock frequency (5KHz) and SFRM signal polarity.
  • Read the temperature measurement.
  • Write to the DS1722 configuration register.
  • Read back from the configuration register.

SPI Driver

Overview

The Windows CE demo image includes the SPI driver, which allows direct access to SSP1 functionality. The SSP1 is also used to communicate with the evaluation kit LCD.

The EM-X270 SPI driver is a stream driver that may be accessed using the "SPI" prefix.

SPI Driver API

Data Types

SPI_SLAVE_CONFIG

Device configuration structure

Fields
Name
Description
DWORD dwDataSize Size of each data frame in bits, allowed values: 4-32
DWORD dwClockRate Frequency in KHz. Allowed values: 4-13*1024
POLARITY ClockPol Clock polarity
POLARITY ChipSelectPol SFRM polarity
BOOL bTxTristate Tristate TX line when SFRM is de-asserted
BOOL ClkPhaseHalfCycle TRUE - CLK remains in its inactive/idle state until one-half clock cycle after the SFRM signal is asserted at the beginning of a frame.

FALSE - CLK remains in its inactive/idle state until one full clock cycle after the SFRM signal is asserted at the beginning of a frame.
Meaningless when bCSExternal = TRUE

BOOL bCSExternal SFRM is a GPIO
DWORD dwGpioNum GPIO number for SFRM
Remarks
bCSExternal is not supported in EM-X270

SPITRANS

Transaction data

Fields
Name
Description
DWORD mTransactions Number of data frames in the transaction
DWORD *mWriteBuffer Data to be written to the port
DWORD *mReadBuffer Data that was read from the port




POLARITY

Signals polarity enumeration

Values
LOW_INACTIVE
HIGH_INACTIVE

Functions

HANDLE SPIUserOpen()

Opens an instance of the SPI Bus Driver.

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


VOID SPIUserClose (HANDLE hDevice)

Closes the driver handle

Parameters
  • hDevice - Handle to an open SPI bus instance



BOOL SPIUserSetConfiguration(HANDLE hDevice, SPI_SLAVE_CONFIG* Settings)

Registers the configuration of the device.

Parameters
  • hDevice - Handle to an open SPI bus instance
  • Settings - The SPI device configuration
Return Values
TRUE - indicates success.
Remarks
The device specific configuration is passed to the SPI controller internally in the driver immediately before transaction start. The driver keeps the configuration until between calls to this function or until the SPI bus handle is closed


BOOL SPIUserTransact (HANDLE hDevice, SPITRANS* pTrans)

Submits SPI data transaction to the target device

Parameters
  • hDevice - Handle to an open SPI bus instance
  • pTrans - pointer to data structures containing data buffers for the transaction
Return Values
TRUE - indicates success.
Remarks
The SPI transaction data buffers must be allocated and released by the user