Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: BLE_file_test BLE_Blink ExternalEncoder
SPIHalfDuplex Class Reference
A SPI half-duplex master, used for communicating with SPI slave devices over a shared data line. More...
#include <SPIHalfDuplex.h>
Inherits mbed::SPI.
Public Member Functions | |
SPIHalfDuplex (PinName mosi, PinName miso, PinName sclk) | |
Create a SPI half-duplex master connected to the specified pins. | |
virtual int | write (int value) |
Write to the SPI Slave and return the response. | |
void | slave_format (int sbits) |
Set the number of databits expected from the slave, from 4-16. | |
void | format (int bits, int mode=0) |
Configure the data transmission format. | |
void | frequency (int hz=1000000) |
Set the spi bus clock frequency. | |
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 | |
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. | |
void | irq_handler_asynch (void) |
SPI IRQ handler. | |
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 half-duplex master, used for communicating with SPI slave devices over a shared data line.
The default format is set to 8-bits for both master and slave, and a clock frequency of 1MHz
Most SPI devies will also require Chip Select and Reset signals. These can be controlled using <DigitalOut> pins.
Although this is for a shared data line, both MISO and MOSI are defined, and should be tied together externally to the mbed. This class handles the tri-stating of the MOSI pin.
Example:
// Send a byte to a SPI half-duplex slave, and record the response #include "mbed.h" SPIHalfDuplex device(p5, p6, p7) // mosi, miso, sclk int main() { int respone = device.write(0xAA); }
Definition at line 42 of file SPIHalfDuplex.h.
Constructor & Destructor Documentation
SPIHalfDuplex | ( | PinName | mosi, |
PinName | miso, | ||
PinName | sclk | ||
) |
Create a SPI half-duplex 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:
-
mosi SPI Master Out, Slave In pin miso SPI Master In, Slave Out pin sclk SPI Clock pin name (optional) A string to identify the object
Definition at line 16 of file SPIHalfDuplex.cpp.
Member Function Documentation
void slave_format | ( | int | sbits ) |
Set the number of databits expected from the slave, from 4-16.
- Parameters:
-
sbits Number of expected bits in the slave response
Definition at line 22 of file SPIHalfDuplex.cpp.
Generated on Tue Jul 12 2022 15:21:05 by
