config Property

Top  Previous  Next

Gets or sets configuration parameters for the SPI bus.

Syntax

Cell.SPI.config

Property Value

A group of bit fields that determine SPI bus parameters.

Remarks

The config property is a byte value with bit fields that control SPI parameters. You must combine (bit-wise OR) values from each section below to create a complete value.

 

The parameters set by the config property apply to a single SPI slave device. If you have multiple devices on the SPI bus, you will need to change the config property each time you switch between devices.

 

SPI Mode

There are four combinations of clock phase and polarity with respect to serial data on the bus. Clock polarity refers to the level of the clock when the bus is idle, thus determining the whether the first edge is rising (if the clock was low) or falling (if the clock was high). Clock phase refers to whether data is sampled on the leading edge (whether rising or falling) or on the trailing edge. The table below details how each SPI mode determines clock phase and polarity.

 

SPI Mode

Clock Idle

Leading Edge

Trailing Edge

0

Low

Sample

Rising


Falling

1

Low


Rising

Sample

Falling

2

High

Sample

Falling


Rising

3

High


Falling

Sample

Rising

 

Using the documentation for you SPI slave device, determine which of the four SPI modes to use. Use one of the constants mode0, mode1, mode2, or mode3 to select the appropriate mode.

 

SS Pin

For automatic control of the SS pin, use one of the following numeric values to designate physical pins:

 

Pin

Value

A0

0

A1

1

A2

2

A3

3

A4

4

A5

5

A6

6

A7

7

B0

8

B1

9

B2

10

B3

11

B4

12

B5

13

B6

14

B7

15

 

For manual control of SS or a non-SPI protocol that does not use SS, select the constant noSS.

 

First Bit

SPI sends data most-significant bit (MSB) first. If you are using a non-SPI protocol and need to send the least-significant bit (LSB) first, use the constant LSBfirst.

Examples

// Set up for SPI EEPROM

Cell.SPI.config = Cell.SPI.mode0 | 12; // SS on B4

 

// Set up for 3-wire interface (DS1620)

Cell.SPI.config = Cell.SPI.mode3 | Cell.SPI.LSBfirst | Cell.SPI.noSS;

See Also

LSBfirst Constant, mode0 Constant, mode1 Constant, mode2 Constant, mode3 Constant, noSS Constant