1 /* mbed Microcontroller Library - SPI
2 * Copyright (c) 2010 ARM Limited. All rights reserved.
6 #ifndef MBED_SPIHALFDUPLEX_H
7 #define MBED_SPIHALFDUPLEX_H
13 /* Class: SPIHalfDuplex
14 * A SPI half-duplex master, used for communicating with SPI slave devices
15 * over a shared data line.
17 * The default format is set to 8-bits for both master and slave, and a
18 * clock frequency of 1MHz
20 * Most SPI devies will also require Chip Select and Reset signals. These
21 * can be controlled using <DigitalOut> pins.
23 * Although this is for a shared data line, both MISO and MOSI are defined,
24 * and should be tied together externally to the mbed. This class handles
25 * the tri-stating of the MOSI pin.
28 * > // Send a byte to a SPI half-duplex slave, and record the response
32 * > SPIHalfDuplex device(p5, p6, p7) // mosi, miso, sclk
35 * > int respone = device.write(0xAA);
39 class SPIHalfDuplex : public SPI {
43 /* Constructor: SPIHalfDuplex
44 * Create a SPI half-duplex master connected to the specified pins
47 * mosi - SPI Master Out, Slave In pin
48 * miso - SPI Master In, Slave Out pin
49 * sclk - SPI Clock pin
50 * name - (optional) A string to identify the object
53 * (5, 6, 7) or (11, 12, 13)
55 * mosi or miso can be specfied as NC if not used
57 SPIHalfDuplex(PinName mosi, PinName miso, PinName sclk,
58 const char *name = NULL);
60 #if 0 // Inherited from SPI - documentation only
62 * Configure the data transmission format
65 * bits - Number of bits per SPI frame (4 - 16)
66 * mode - Clock polarity and phase mode (0 - 3)
75 void format(int bits, int mode = 0);
77 /* Function: frequency
78 * Set the spi bus clock frequency
81 * hz - SCLK frequency in hz (default = 1MHz)
83 void frequency(int hz = 1000000);
87 * Write to the SPI Slave and return the response
90 * value - Data to be sent to the SPI slave
91 * returns - Response from the SPI slave
93 virtual int write(int value);
95 /* Function: slave_format
96 * Set the number of databits expected from the slave, from 4-16
99 * sbits - Number of expected bits in the slave response
101 void slave_format(int sbits);
111 } // End of namespace mbed