BLE temperature profile using digital DS1820 or analog LM35 sensors

Dependencies:   DS1820

Committer:
gkroussos
Date:
Sat Mar 07 16:23:41 2015 +0000
Revision:
0:637031152314
Working version 1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gkroussos 0:637031152314 1 /* mbed Microcontroller Library
gkroussos 0:637031152314 2 * Copyright (c) 2006-2013 ARM Limited
gkroussos 0:637031152314 3 *
gkroussos 0:637031152314 4 * Licensed under the Apache License, Version 2.0 (the "License");
gkroussos 0:637031152314 5 * you may not use this file except in compliance with the License.
gkroussos 0:637031152314 6 * You may obtain a copy of the License at
gkroussos 0:637031152314 7 *
gkroussos 0:637031152314 8 * http://www.apache.org/licenses/LICENSE-2.0
gkroussos 0:637031152314 9 *
gkroussos 0:637031152314 10 * Unless required by applicable law or agreed to in writing, software
gkroussos 0:637031152314 11 * distributed under the License is distributed on an "AS IS" BASIS,
gkroussos 0:637031152314 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
gkroussos 0:637031152314 13 * See the License for the specific language governing permissions and
gkroussos 0:637031152314 14 * limitations under the License.
gkroussos 0:637031152314 15 */
gkroussos 0:637031152314 16 #ifndef MBED_SPI_H
gkroussos 0:637031152314 17 #define MBED_SPI_H
gkroussos 0:637031152314 18
gkroussos 0:637031152314 19 #include "platform.h"
gkroussos 0:637031152314 20
gkroussos 0:637031152314 21 #if DEVICE_SPI
gkroussos 0:637031152314 22
gkroussos 0:637031152314 23 #include "spi_api.h"
gkroussos 0:637031152314 24
gkroussos 0:637031152314 25 namespace mbed {
gkroussos 0:637031152314 26
gkroussos 0:637031152314 27 /** A SPI Master, used for communicating with SPI slave devices
gkroussos 0:637031152314 28 *
gkroussos 0:637031152314 29 * The default format is set to 8-bits, mode 0, and a clock frequency of 1MHz
gkroussos 0:637031152314 30 *
gkroussos 0:637031152314 31 * Most SPI devices will also require Chip Select and Reset signals. These
gkroussos 0:637031152314 32 * can be controlled using <DigitalOut> pins
gkroussos 0:637031152314 33 *
gkroussos 0:637031152314 34 * Example:
gkroussos 0:637031152314 35 * @code
gkroussos 0:637031152314 36 * // Send a byte to a SPI slave, and record the response
gkroussos 0:637031152314 37 *
gkroussos 0:637031152314 38 * #include "mbed.h"
gkroussos 0:637031152314 39 *
gkroussos 0:637031152314 40 * SPI device(p5, p6, p7); // mosi, miso, sclk
gkroussos 0:637031152314 41 *
gkroussos 0:637031152314 42 * int main() {
gkroussos 0:637031152314 43 * int response = device.write(0xFF);
gkroussos 0:637031152314 44 * }
gkroussos 0:637031152314 45 * @endcode
gkroussos 0:637031152314 46 */
gkroussos 0:637031152314 47 class SPI {
gkroussos 0:637031152314 48
gkroussos 0:637031152314 49 public:
gkroussos 0:637031152314 50
gkroussos 0:637031152314 51 /** Create a SPI master connected to the specified pins
gkroussos 0:637031152314 52 *
gkroussos 0:637031152314 53 * Pin Options:
gkroussos 0:637031152314 54 * (5, 6, 7) or (11, 12, 13)
gkroussos 0:637031152314 55 *
gkroussos 0:637031152314 56 * mosi or miso can be specfied as NC if not used
gkroussos 0:637031152314 57 *
gkroussos 0:637031152314 58 * @param mosi SPI Master Out, Slave In pin
gkroussos 0:637031152314 59 * @param miso SPI Master In, Slave Out pin
gkroussos 0:637031152314 60 * @param sclk SPI Clock pin
gkroussos 0:637031152314 61 */
gkroussos 0:637031152314 62 SPI(PinName mosi, PinName miso, PinName sclk, PinName _unused=NC);
gkroussos 0:637031152314 63
gkroussos 0:637031152314 64 /** Configure the data transmission format
gkroussos 0:637031152314 65 *
gkroussos 0:637031152314 66 * @param bits Number of bits per SPI frame (4 - 16)
gkroussos 0:637031152314 67 * @param mode Clock polarity and phase mode (0 - 3)
gkroussos 0:637031152314 68 *
gkroussos 0:637031152314 69 * @code
gkroussos 0:637031152314 70 * mode | POL PHA
gkroussos 0:637031152314 71 * -----+--------
gkroussos 0:637031152314 72 * 0 | 0 0
gkroussos 0:637031152314 73 * 1 | 0 1
gkroussos 0:637031152314 74 * 2 | 1 0
gkroussos 0:637031152314 75 * 3 | 1 1
gkroussos 0:637031152314 76 * @endcode
gkroussos 0:637031152314 77 */
gkroussos 0:637031152314 78 void format(int bits, int mode = 0);
gkroussos 0:637031152314 79
gkroussos 0:637031152314 80 /** Set the spi bus clock frequency
gkroussos 0:637031152314 81 *
gkroussos 0:637031152314 82 * @param hz SCLK frequency in hz (default = 1MHz)
gkroussos 0:637031152314 83 */
gkroussos 0:637031152314 84 void frequency(int hz = 1000000);
gkroussos 0:637031152314 85
gkroussos 0:637031152314 86 /** Write to the SPI Slave and return the response
gkroussos 0:637031152314 87 *
gkroussos 0:637031152314 88 * @param value Data to be sent to the SPI slave
gkroussos 0:637031152314 89 *
gkroussos 0:637031152314 90 * @returns
gkroussos 0:637031152314 91 * Response from the SPI slave
gkroussos 0:637031152314 92 */
gkroussos 0:637031152314 93 virtual int write(int value);
gkroussos 0:637031152314 94
gkroussos 0:637031152314 95 protected:
gkroussos 0:637031152314 96 spi_t _spi;
gkroussos 0:637031152314 97
gkroussos 0:637031152314 98 void aquire(void);
gkroussos 0:637031152314 99 static SPI *_owner;
gkroussos 0:637031152314 100 int _bits;
gkroussos 0:637031152314 101 int _mode;
gkroussos 0:637031152314 102 int _hz;
gkroussos 0:637031152314 103 };
gkroussos 0:637031152314 104
gkroussos 0:637031152314 105 } // namespace mbed
gkroussos 0:637031152314 106
gkroussos 0:637031152314 107 #endif
gkroussos 0:637031152314 108
gkroussos 0:637031152314 109 #endif