mbed-drivers
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
mbed::SPI Class Reference

#include <SPI.h>

Classes

class  SPITransferAdder
 

Public Types

typedef mbed::util::FunctionPointer3< void, Buffer, Buffer, int > event_callback_t
 

Public Member Functions

 SPI (PinName mosi, PinName miso, PinName sclk)
 
void format (int bits, int mode=0, spi_bitorder_t order=SPI_MSB)
 
void frequency (int hz=1000000)
 
virtual int write (int value)
 
SPITransferAdder transfer ()
 
void abort_transfer ()
 
void clear_transfer_buffer ()
 
void abort_all_transfers ()
 
int set_dma_usage (DMAUsage usage)
 

Protected Member Functions

void irq_handler_asynch (void)
 
int queue_transfer (const transaction_data_t &td)
 
void start_transfer (const transaction_data_t &td)
 
void start_transaction (transaction_data_t *data)
 
void dequeue_transaction ()
 
int transfer (const SPITransferAdder &xfer)
 
void aquire (void)
 

Protected Attributes

spi_t _spi
 
CThunk< SPI_irq
 
transaction_data_t _current_transaction
 
DMAUsage _usage
 
int _bits
 
int _mode
 
spi_bitorder_t _order
 
int _hz
 
bool _busy
 

Static Protected Attributes

static CircularBuffer< transaction_t, TRANSACTION_QUEUE_SIZE_SPI > _transaction_buffer
 
static SPI_owner = NULL
 

Detailed Description

A SPI Master, used for communicating with SPI slave devices

The default format is set to 8-bits, mode 0, and a clock frequency of 1MHz

NOTE: This information will be deprecated soon. Most SPI devices will also require Chip Select and Reset signals. These can be controlled using <DigitalOut> pins

Member Typedef Documentation

typedef mbed::util::FunctionPointer3<void, Buffer, Buffer, int> mbed::SPI::event_callback_t

SPI transfer callback

Parameters
Bufferthe tx buffer
Bufferthe rx buffer
intthe event that triggered the calback

Constructor & Destructor Documentation

mbed::SPI::SPI ( PinName  mosi,
PinName  miso,
PinName  sclk 
)

Create a SPI master connected to the specified pins

Pin Options: (5, 6, 7) or (11, 12, 13)

mosi or miso can be specfied as NC if not used

Parameters
mosiSPI Master Out, Slave In pin
misoSPI Master In, Slave Out pin
sclkSPI Clock pin

Member Function Documentation

void mbed::SPI::abort_all_transfers ( )

Clear the transaction buffer and abort on-going transfer.

void mbed::SPI::abort_transfer ( void  )

Abort the on-going SPI transfer, and continue with transfer's in the queue if any.

void mbed::SPI::clear_transfer_buffer ( )

Clear the transaction buffer

void mbed::SPI::dequeue_transaction ( )
protected

Dequeue a transaction

void mbed::SPI::format ( int  bits,
int  mode = 0,
spi_bitorder_t  order = SPI_MSB 
)

Configure the data transmission format

Parameters
bitsNumber of bits per SPI frame (4 - 16)
modeClock polarity and phase mode (0 - 3)
orderBit order. SPI_MSB (standard) or SPI_LSB.
mode | POL PHA
-----+--------
0 | 0 0
1 | 0 1
2 | 1 0
3 | 1 1
void mbed::SPI::frequency ( int  hz = 1000000)

Set the spi bus clock frequency

Parameters
hzSCLK frequency in hz (default = 1MHz)
void mbed::SPI::irq_handler_asynch ( void  )
protected

SPI IRQ handler

int mbed::SPI::queue_transfer ( const transaction_data_t td)
protected

Add a transfer to the queue

Parameters
dataTransaction data
Returns
Zero if a transfer was added to the queue, or -1 if the queue is full
int mbed::SPI::set_dma_usage ( DMAUsage  usage)

Configure DMA usage suggestion for non-blocking transfers

Parameters
usageThe usage DMA hint for peripheral
Returns
Zero if the usage was set, -1 if a transaction is on-going
void mbed::SPI::start_transaction ( transaction_data_t data)
protected

Start a new transaction

Parameters
dataTransaction data
void mbed::SPI::start_transfer ( const transaction_data_t td)
protected

Configures a callback, spi peripheral and initiate a new transfer

Parameters
dataTransaction data
SPI::SPITransferAdder mbed::SPI::transfer ( )

Start an SPI transfer The transfer() method returns a SPITransferAdder. This class allows each parameter to be set with a dedicated method. This way, the many optional parameters are easy to identify and set.

Returns
A SPITransferAdder object. When either apply() is called or the SPITransferAdder goes out of scope, the transfer is queued.
int mbed::SPI::transfer ( const SPITransferAdder xfer)
protected

Initiate a transfer

Parameters
xferthe SPITransferAdder object used to create the SPI transfer
Returns
the result of validating the transfer parameters
int mbed::SPI::write ( int  value)
virtual

Write to the SPI Slave and return the response

Parameters
valueData to be sent to the SPI slave
Returns
Response from the SPI slave

The documentation for this class was generated from the following files: