Modification of Mbed-dev library for LQFP48 package microcontrollers: STM32F103C8 (STM32F103C8T6) and STM32F103CB (STM32F103CBT6) (Bluepill boards, Maple mini etc. )

Fork of mbed-STM32F103C8_org by Nothing Special

Embed: (wiki syntax)

« Back to documentation index

SPI Class Reference

A SPI Master, used for communicating with SPI slave devices. More...

#include <SPI.h>

Public Member Functions

 SPI (PinName mosi, PinName miso, PinName sclk, PinName ssel=NC)
 Create a SPI master connected to the specified pins.
void format (int bits, int mode=0)
 Configure the data transmission format.
void frequency (int hz=1000000)
 Set the spi bus clock frequency.
virtual int write (int value)
 Write to the SPI Slave and return the response.
virtual void lock (void)
 Acquire exclusive access to this SPI bus.
virtual void unlock (void)
 Release exclusive access to this SPI bus.
template<typename Type >
int transfer (const Type *tx_buffer, int tx_length, Type *rx_buffer, int rx_length, const event_callback_t &callback, int event=SPI_EVENT_COMPLETE)
 Start non-blocking SPI transfer using 8bit buffers.
void abort_transfer ()
 Abort the on-going SPI transfer, and continue with transfer's in the queue if any.
void clear_transfer_buffer ()
 Clear the transaction buffer.
void abort_all_transfers ()
 Clear the transaction buffer and abort on-going transfer.
int set_dma_usage (DMAUsage usage)
 Configure DMA usage suggestion for non-blocking transfers.

Protected Member Functions

void irq_handler_asynch (void)
 SPI IRQ handler.
int transfer (const void *tx_buffer, int tx_length, void *rx_buffer, int rx_length, unsigned char bit_width, const event_callback_t &callback, int event)
 Common transfer method.
int queue_transfer (const void *tx_buffer, int tx_length, void *rx_buffer, int rx_length, unsigned char bit_width, const event_callback_t &callback, int event)
void start_transfer (const void *tx_buffer, int tx_length, void *rx_buffer, int rx_length, unsigned char bit_width, const event_callback_t &callback, int event)
 Configures a callback, spi peripheral and initiate a new transfer.
void start_transaction (transaction_t *data)
 Start a new transaction.
void dequeue_transaction ()
 Dequeue a transaction.

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

Most SPI devices will also require Chip Select and Reset signals. These can be controlled using <DigitalOut> pins

Synchronization level: Thread safe

Example:

 // Send a byte to a SPI slave, and record the response

 #include "mbed.h"

 // hardware ssel (where applicable)
 //SPI device(p5, p6, p7, p8); // mosi, miso, sclk, ssel

 // software ssel
 SPI device(p5, p6, p7); // mosi, miso, sclk
 DigitalOut cs(p8); // ssel

 int main() {
     // hardware ssel (where applicable)
     //int response = device.write(0xFF);

     device.lock();
     // software ssel
     cs = 0;
     int response = device.write(0xFF);
     cs = 1;
     device.unlock();

 }

Definition at line 75 of file SPI.h.


Constructor & Destructor Documentation

SPI ( PinName  mosi,
PinName  miso,
PinName  sclk,
PinName  ssel = NC 
)

Create a SPI master connected to the specified pins.

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
sselSPI chip select pin

Definition at line 27 of file SPI.cpp.