api / mbed / trunk / SPIHalfDuplex
SPIHalfDuplex
class SPIHalfDuplex : public SPI
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);
}| SPIHalfDuplex | A SPI half-duplex master, used for communicating with SPI slave devices over a shared data line. |
| Functions | |
| SPIHalfDuplex | Create a SPI half-duplex master connected to the specified pins |
| format | Configure the data transmission format |
| frequency | Set the spi bus clock frequency |
| write | Write to the SPI Slave and return the response |
| slave_format | Set the number of databits expected from the slave, from 4-16 |
SPIHalfDuplex
SPIHalfDuplex( PinName mosi, PinName miso, PinName sclk, const char * name = NULL )
Create a SPI half-duplex master connected to the specified pins
Variables
| 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 |
Pin Options
(5, 6, 7) or (11, 12, 13)
mosi or miso can be specfied as NC if not used
A SPI half-duplex master, used for communicating with SPI slave devices over a shared data line.
class SPIHalfDuplex : public SPI
Create a SPI half-duplex master connected to the specified pins
SPIHalfDuplex( PinName mosi, PinName miso, PinName sclk, const char * name = NULL )
Configure the data transmission format
void format( int bits, int mode = 0 )
Set the spi bus clock frequency
void frequency( int hz = 1000000 )
Write to the SPI Slave and return the response
virtual int write( int value )
Set the number of databits expected from the slave, from 4-16
void slave_format( int sbits )
A digital output, used for setting the state of a pin
class DigitalOut : public Base
