CM-X300: WinCE: SPI Driver API

From Compulab Mediawiki
Jump to: navigation, search

Introduction

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

The Windows CE demo image includes the SPI driver, which allows direct access to SSP3 and SSP1 functionality.

SPI Sample

Connecting the device to CM-X300

  • The SPI device can be connected to the SSP3 port available on connector P6 on SB-X300. The following table describes the connector pin-out:
Signal Name Pin Number
SSP3_TXD 5
SSP3_RXD 7
SSP3_CLK 3
SSP3_SFRM 1
  • Connect pin 6 (SERMODE) of DS1722 to VDD.
  • Connect all remaining DS1722 pins to VDD and GND according to the device datasheet.
  • Refer to CM-X300-Man for gpio mapping of SSP1.

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 CM-X300 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 CM-X300

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 immediately before the transaction starts. The driver keeps the configuration 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