printer

Dependents:   Good_Serial_HelloWorld_Mbed

Fork of mbed by gokmen ascioglu

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SPIHalfDuplex.h Source File

SPIHalfDuplex.h

00001 /* mbed Microcontroller Library - SPIHalfDuplex
00002  * Copyright (c) 2010-2011 ARM Limited. All rights reserved.
00003  */
00004 
00005 #ifndef MBED_SPIHALFDUPLEX_H
00006 #define MBED_SPIHALFDUPLEX_H
00007 
00008 #include "device.h"
00009 
00010 #if DEVICE_SPI
00011 
00012 #include "SPI.h"
00013 
00014 namespace mbed {
00015 
00016 /* Class: SPIHalfDuplex
00017  *   A SPI half-duplex master, used for communicating with SPI slave devices
00018  * over a shared data line.
00019  *
00020  * The default format is set to 8-bits for both master and slave, and a
00021  * clock frequency of 1MHz
00022  *
00023  * Most SPI devies will also require Chip Select and Reset signals. These
00024  * can be controlled using <DigitalOut> pins.
00025  *
00026  * Although this is for a shared data line, both MISO and MOSI are defined,
00027  * and should be tied together externally to the mbed. This class handles
00028  * the tri-stating of the MOSI pin.
00029  *
00030  * Example:
00031  * > // Send a byte to a SPI half-duplex slave, and record the response
00032  * >
00033  * > #include "mbed.h"
00034  * > 
00035  * > SPIHalfDuplex device(p5, p6, p7) // mosi, miso, sclk
00036  * >
00037  * > int main() {
00038  * >     int respone = device.write(0xAA);
00039  * > }
00040  */
00041 
00042 class SPIHalfDuplex : public SPI {
00043 
00044 public:
00045     
00046     /* Constructor: SPIHalfDuplex
00047      *  Create a SPI half-duplex master connected to the specified pins
00048      *
00049      * Variables:
00050      *  mosi - SPI Master Out, Slave In pin
00051      *  miso - SPI Master In, Slave Out pin
00052      *  sclk - SPI Clock pin
00053      *  name - (optional) A string to identify the object
00054      *
00055      * Pin Options:
00056      *  (5, 6, 7) or (11, 12, 13)
00057      *
00058      *  mosi or miso can be specfied as NC if not used
00059      */
00060     SPIHalfDuplex(PinName mosi, PinName miso, PinName sclk,
00061         const char *name = NULL);
00062 
00063 #if 0 // Inherited from SPI - documentation only
00064     /* Function: format
00065      *  Configure the data transmission format
00066      *
00067      * Variables:
00068      *  bits - Number of bits per SPI frame (4 - 16)
00069      *  mode - Clock polarity and phase mode (0 - 3)
00070      *
00071      * > mode | POL PHA
00072      * > -----+--------
00073      * >   0  |  0   0
00074      * >   1  |  0   1
00075      * >   2  |  1   0
00076      * >   3  |  1   1
00077      */
00078     void format(int bits, int mode = 0);
00079 
00080     /* Function: frequency
00081      *  Set the spi bus clock frequency
00082      *
00083      * Variables:
00084      *  hz - SCLK frequency in hz (default = 1MHz)
00085      */
00086     void frequency(int hz = 1000000);
00087 #endif
00088 
00089     /* Function: write
00090      *  Write to the SPI Slave and return the response
00091      *
00092      * Variables:
00093      *  value - Data to be sent to the SPI slave
00094      *  returns - Response from the SPI slave
00095      */
00096     virtual int write(int value);
00097     
00098     /* Function: slave_format
00099      *  Set the number of databits expected from the slave, from 4-16
00100      *
00101      * Variables:
00102      *  sbits - Number of expected bits in the slave response
00103      */
00104     void slave_format(int sbits);
00105 
00106 protected:
00107     PinName _mosi;
00108     PinName _miso;
00109     int     _sbits;
00110 
00111 }; // End of class
00112 
00113 } // End of namespace mbed
00114 
00115 #endif
00116 
00117 #endif