Main Page | Modules | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

SPI - Serial Protocol Interface


Files

file  otSpi.h
 SPI Library for BF51x.

Modules

 Version History
 SPI - Code example

Data Structures

struct  SpiConfig

Defines

#define SPI_CHIP_SELECT_PORT   PP_H
 Port where is located the SPI chip select.
#define SPI_CHIP_SELECT_BIT   0
 Bit of the port used for the SPI chip select.
#define MAX_SPI_ADDRESS   8
 Maximum number of SPI slaves.

Typedefs

typedef SpiConfig SpiConfig

Enumerations

enum  SpiAddress {
  SA_EEPROM, SA_Y6, SA_Y15, SA_LCD,
  SA_TOUCH, SA_ADC, SA_PGA, SA_DAC,
  SA_OFFBOARD, SA_L6470 = 8, SA_MCP48FVB = 9, SA_DIGPOT = 10,
  SA_MAX7219_A = 1, SA_MAX7219_B = 2, SA_MAX7219_C = 11
}
enum  SpiChannel { SPI_0, SPI_1 }
enum  SpiControls { SPI_DEF = 0, SPI_CPOL = 0x800, SPI_CPHA = 0x400 }

Functions

float SpiChannel (int id, float baud, U16 cpol, U16 cpha)
 Specify a new device configuration.
void SpiCs (bool ena)
 Enable or disable SPI chip select.
void SpiSet (int id)
 Select a device on SPI bus.
U8 SpiPut (U8 value)
 Send/receive one byte to selected device.
void SpiPutW (U16 value)
 Send a word to selected device.
U16 SpiGet16 (U8 val)
 Read a word.
U8 SpiPutN (const U8 *value, U32 num)
 Send n bytes to selected device.
void SpiGetN (U8 dummy, U8 *value, U32 num)
 Receive n bytes from selected device.

Detailed Description

Dependency: FPGA - Procedures for SharkDuino+ FPGA, PORT - Procedure for parallel port usage

Define Documentation

#define MAX_SPI_ADDRESS   8
 

#define SPI_CHIP_SELECT_BIT   0
 

#define SPI_CHIP_SELECT_PORT   PP_H
 


Typedef Documentation

typedef struct SpiConfig SpiConfig
 


Enumeration Type Documentation

enum SpiAddress
 

Enumeration values:
SA_EEPROM  0, 128 KByte EEPROM (X5)
SA_Y6  1, For Lepton or Arducam modules
SA_Y15  2, For Lepton or Arducam modules
SA_LCD  3, LCD display
SA_TOUCH  4, Touch screen controller
SA_ADC  5, 16 bit ADC X22
SA_PGA  6, Programmable gain amplifier on X23
SA_DAC  7, Four channel DAC on X24
SA_OFFBOARD  Suggested addresses.

8, Address not embedded

SA_L6470  8, L6470 on related shield
SA_MCP48FVB  9, DAC 8/10/12 bit on brushed DC motor shield
SA_DIGPOT  10, Digital potentiometers X9C102, X9C103, X9C104 and X9C504
SA_MAX7219_A  1, 8-Digit LED Display Drivers on Y6
SA_MAX7219_B  1, 8-Digit LED Display Drivers on Y15
SA_MAX7219_C  11, 8-Digit LED Display Drivers

enum SpiChannel
 

Enumeration values:
SPI_0  SPI channel 0 tipically reserved for FLASH.
SPI_1  SPI channel 1 for user.

enum SpiControls
 

Enumeration values:
SPI_DEF  CPOL and CPHA set to 0.
SPI_CPOL  CPOL=0 is a clock which idles at 0, and each cycle consists of a pulse of 1. That is, the leading edge is a rising edge, and the trailing edge is a falling edge. CPOL=1 is a clock which idles at 1, and each cycle consists of a pulse of 0. That is, the leading edge is a falling edge, and the trailing edge is a rising edge.
SPI_CPHA  For CPHA=0, the "out" side changes the data on the trailing edge of the preceding clock cycle, while the "in" side captures the data on (or shortly after) the leading edge of the clock cycle. The out side holds the data valid until the trailing edge of the current clock cycle. For the first cycle, the first bit must be on the MOSI line before the leading clock edge. An alternative way of considering it is to say that a CPHA=0 cycle consists of a half cycle with the clock idle, followed by a half cycle with the clock asserted. For CPHA=1, the "out" side changes the data on the leading edge of the current clock cycle, while the "in" side captures the data on (or shortly after) the trailing edge of the clock cycle. The out side holds the data valid until the leading edge of the following clock cycle. For the last cycle, the slave holds the MISO line valid until slave select is deasserted. An alternative way of considering it is to say that a CPHA=1 cycle consists of a half cycle with the clock asserted, followed by a half cycle with the clock idle.


Function Documentation

float SpiChannel int  id,
float  baud,
U16  cpol,
U16  cpha
 

Parameters:
id Device address, refer to SpiAddress. The address change from one platform to another.
baud Used frequency in the synchronous protocol. Baud is expressed as MHz.
cpol Clock polarity, refer to SpiControls
cpha Phase activity, refer to SpiControls
Returns:
Real used frequency.

void SpiCs bool  ena  ) 
 

Parameters:
ena If true enable the chip select

U16 SpiGet16 U8  val  ) 
 

Parameters:
val Byte to sent
Returns:
Word

void SpiGetN U8  dummy,
U8 value,
U32  num
 

Parameters:
dummy Dummy character used in transmission.
value Pointer where store received data
num Number of bytes to read
Returns:
Received data

U8 SpiPut U8  value  ) 
 

Parameters:
value Data to be sent
Returns:
Received data

U8 SpiPutN const U8 value,
U32  num
 

Parameters:
value Pointer to the buffer o data to be sent
num Number of bytes to write
Returns:
Last received byte

void SpiPutW U16  value  ) 
 

Parameters:
value Data to be sent

void SpiSet int  id  ) 
 

Parameters:
id Device address, refer to SpiAddress. The address change from one platform to another.
footer

otStudio - Library Reference - (C) 2020-25 Officina Turini, All Rights Reserved
Document built with Doxygen 1.4.0