Fork of the official mbed C/C++ SDK provides the software platform and libraries to build your applications. The fork has the documentation converted to Doxygen format
Dependents: NervousPuppySprintOne NervousPuppySprint2602 Robot WarehouseBot1 ... more
Fork of mbed by
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 /** A SPI half-duplex master, used for communicating with SPI slave devices 00017 * over a shared data line. 00018 * 00019 * The default format is set to 8-bits for both master and slave, and a 00020 * clock frequency of 1MHz 00021 * 00022 * Most SPI devies will also require Chip Select and Reset signals. These 00023 * can be controlled using <DigitalOut> pins. 00024 * 00025 * Although this is for a shared data line, both MISO and MOSI are defined, 00026 * and should be tied together externally to the mbed. This class handles 00027 * the tri-stating of the MOSI pin. 00028 * 00029 * Example: 00030 * @code 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 * @endcode 00041 */ 00042 00043 class SPIHalfDuplex : public SPI { 00044 00045 public: 00046 00047 /** Create a SPI half-duplex master connected to the specified pins 00048 * 00049 * Pin Options: 00050 * (5, 6, 7) or (11, 12, 13) 00051 * 00052 * mosi or miso can be specfied as NC if not used 00053 * 00054 * @param mosi SPI Master Out, Slave In pin 00055 * @param miso SPI Master In, Slave Out pin 00056 * @param sclk SPI Clock pin 00057 * @param name (optional) A string to identify the object 00058 */ 00059 SPIHalfDuplex(PinName mosi, PinName miso, PinName sclk, 00060 const char *name = NULL); 00061 00062 #if 0 // Inherited from SPI - documentation only 00063 /** Configure the data transmission format 00064 * 00065 * @param bits Number of bits per SPI frame (4 - 16) 00066 * @param mode Clock polarity and phase mode (0 - 3) 00067 * 00068 * @code 00069 * mode | POL PHA 00070 * -----+-------- 00071 * 0 | 0 0 00072 * 1 | 0 1 00073 * 2 | 1 0 00074 * 3 | 1 1 00075 * @endcode 00076 */ 00077 void format(int bits, int mode = 0); 00078 00079 /** Set the spi bus clock frequency 00080 * 00081 * @param hz SCLK frequency in hz (default = 1MHz) 00082 */ 00083 void frequency(int hz = 1000000); 00084 #endif 00085 00086 /** Write to the SPI Slave and return the response 00087 * 00088 * @param value Data to be sent to the SPI slave 00089 * 00090 * @returns 00091 * Response from the SPI slave 00092 */ 00093 virtual int write(int value); 00094 00095 /** Set the number of databits expected from the slave, from 4-16 00096 * 00097 * @param sbits Number of expected bits in the slave response 00098 */ 00099 void slave_format(int sbits); 00100 00101 protected: 00102 PinName _mosi; 00103 PinName _miso; 00104 int _sbits; 00105 00106 }; // End of class 00107 00108 } // End of namespace mbed 00109 00110 #endif 00111 00112 #endif
Generated on Tue Jul 12 2022 11:27:27 by 1.7.2