Online Development Notebook > Index > ODN > Raw Device Programming > 14 - InitSPICmd

Command #14 - InitSPICmd


Description:

This command sets the SPI subsystem attributes and the direction of the SPI lines. The SPI subsystem can be either a SPI master or a SPI slave. The InitSPICmd command sets the port lines appropriately for selection of either master or slave. Clock frequency, polarity, and phase are also set.

Command Format:

Byte Number Description
0 14h: InitSPICmd
1 Byte Data
2 <not used>
3 <not used>
4 <not used>
5 <not used>
6 <not used>
7 <not used>

Command Format Details:

Byte 0 contains the command. Byte 1 is the SPI subsystem attribute data. Byte 2 through byte 7 are unused.

The direction of the SPI port lines (A.5-MOSI, A.6-MISO, A.7-SCK, and, in the case of SPI slave operation, A.4-SS) is set based on the command to set the SPI subsystem to either master or slave.

When set as a master SPI device, A.5-MOSI and A.7-SCK are set as outputs. A.6-MISO is set to input. A.4-SS is unaffected.

When set as a slave SPI device, A.5-MOSI, A.7-SCK, and A.4-SS are set as inputs. A.6-MISO is set to output.

Turning off the SPI subsystem with the InitSPICmd command will still set the port direction of the SPI port lines as a SPI master. If you wish to turn off the SPI and use the SPI port lines, issue a DirectionACmd command after the InitSPICmd command.

The format of the data byte written to control the SPI subsystem attributes is divided into bit fields.

Bits 1 and 0 control the clock frequency: (applicable to the master mode)

         00 = 2 Mbits⁄s

         01 = 1 Mbits⁄s

         10 = 500,000 bits⁄s

         11 = 62,500 bits⁄s.

Bits 3 and 2 control the clock polarity and phase:

         00 = clock starts⁄idles low, data sampled on falling edge (common SPI name: Mode 1)

         01 = clock starts⁄idles low, data sampled on rising edge (common SPI name: Mode 0)

         10 = clock starts⁄idles high, data sampled on rising edge (common SPI name: Mode 3)

         11 = clock starts⁄idles high, data sampled on falling edge. (common SPI name: Mode 2)

Bits 5 and 4 control the SPI mode:

         00 = SPI disabled

         01 = SPI master

         10 = SPI slave

         11 should not be used.

Bits 7 and 6 should be written as 00.

Response Format:

Byte Number Description
0 14h: InitSPICmd
1 <not used>
2 <not used>
3 <not used>
4 <not used>
5 <not used>
6 <not used>
7 <not used>

Response Format Details:

Byte 0 contains the command. Byte 1 through byte 7 are unused.

Example Usage:

14-10-00-00-00-00-00-00 will initialize the SPI as a master, at 2 Mbits⁄s, and with the clock starting  low and data valid on the falling edge.


Hardware:  U401 USB Interface    U421 USB Interface
Programming:  USBm DLL Programming    Download Files
Application Notes:  U4x1 Application Notes    Misc Applications and Information    FAQ