The program demonstrates how to implement SPI on BLE Nano platform

Dependencies:   mbed

The program demonstrates how to implement SPI on BLE Nano platform.

Committer:
RedBearLab
Date:
Wed Oct 22 05:08:52 2014 +0000
Revision:
0:5810870d2b29
First commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RedBearLab 0:5810870d2b29 1 /*
RedBearLab 0:5810870d2b29 2
RedBearLab 0:5810870d2b29 3 Copyright (c) 2012-2014 RedBearLab
RedBearLab 0:5810870d2b29 4
RedBearLab 0:5810870d2b29 5 Permission is hereby granted, free of charge, to any person obtaining a copy of this software
RedBearLab 0:5810870d2b29 6 and associated documentation files (the "Software"), to deal in the Software without restriction,
RedBearLab 0:5810870d2b29 7 including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
RedBearLab 0:5810870d2b29 8 and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
RedBearLab 0:5810870d2b29 9 subject to the following conditions:
RedBearLab 0:5810870d2b29 10 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
RedBearLab 0:5810870d2b29 11
RedBearLab 0:5810870d2b29 12 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
RedBearLab 0:5810870d2b29 13 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
RedBearLab 0:5810870d2b29 14 PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
RedBearLab 0:5810870d2b29 15 FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
RedBearLab 0:5810870d2b29 16 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
RedBearLab 0:5810870d2b29 17
RedBearLab 0:5810870d2b29 18 */
RedBearLab 0:5810870d2b29 19
RedBearLab 0:5810870d2b29 20 #ifndef _SPI_MASTER_H_
RedBearLab 0:5810870d2b29 21 #define _SPI_MASTER_H_
RedBearLab 0:5810870d2b29 22
RedBearLab 0:5810870d2b29 23 #include "mbed.h"
RedBearLab 0:5810870d2b29 24
RedBearLab 0:5810870d2b29 25 #define SPI_FREQUENCY_125K 0x02000000UL
RedBearLab 0:5810870d2b29 26 #define SPI_FREQUENCY_250K 0x04000000UL
RedBearLab 0:5810870d2b29 27 #define SPI_FREQUENCY_500K 0x08000000UL
RedBearLab 0:5810870d2b29 28 #define SPI_FREQUENCY_1M 0x10000000UL
RedBearLab 0:5810870d2b29 29 #define SPI_FREQUENCY_2M 0x20000000UL
RedBearLab 0:5810870d2b29 30 #define SPI_FREQUENCY_4M 0x40000000UL
RedBearLab 0:5810870d2b29 31 #define SPI_FREQUENCY_8M 0x80000000UL
RedBearLab 0:5810870d2b29 32
RedBearLab 0:5810870d2b29 33 #define SPI_125K 0
RedBearLab 0:5810870d2b29 34 #define SPI_250K 1
RedBearLab 0:5810870d2b29 35 #define SPI_500K 2
RedBearLab 0:5810870d2b29 36 #define SPI_1M 3
RedBearLab 0:5810870d2b29 37 #define SPI_2M 4
RedBearLab 0:5810870d2b29 38 #define SPI_4M 5
RedBearLab 0:5810870d2b29 39 #define SPI_8M 6
RedBearLab 0:5810870d2b29 40
RedBearLab 0:5810870d2b29 41 #define SPI_MODE0 0
RedBearLab 0:5810870d2b29 42 #define SPI_MODE1 1
RedBearLab 0:5810870d2b29 43 #define SPI_MODE2 2
RedBearLab 0:5810870d2b29 44 #define SPI_MODE3 3
RedBearLab 0:5810870d2b29 45
RedBearLab 0:5810870d2b29 46 #define CS P0_14
RedBearLab 0:5810870d2b29 47 #define SCK P0_25
RedBearLab 0:5810870d2b29 48 #define MOSI P0_20
RedBearLab 0:5810870d2b29 49 #define MISO P0_22
RedBearLab 0:5810870d2b29 50
RedBearLab 0:5810870d2b29 51 typedef enum{
RedBearLab 0:5810870d2b29 52
RedBearLab 0:5810870d2b29 53 MSBFIRST = 0,
RedBearLab 0:5810870d2b29 54 LSBFIRST = 1
RedBearLab 0:5810870d2b29 55
RedBearLab 0:5810870d2b29 56 }BitOrder;
RedBearLab 0:5810870d2b29 57
RedBearLab 0:5810870d2b29 58 class SPIClass
RedBearLab 0:5810870d2b29 59 {
RedBearLab 0:5810870d2b29 60 public:
RedBearLab 0:5810870d2b29 61 SPIClass(NRF_SPI_Type *_spi);
RedBearLab 0:5810870d2b29 62
RedBearLab 0:5810870d2b29 63 void begin();
RedBearLab 0:5810870d2b29 64 void begin(uint32_t sck, uint32_t mosi, uint32_t miso);
RedBearLab 0:5810870d2b29 65 uint8_t transfer(uint8_t data);
RedBearLab 0:5810870d2b29 66 void endTransfer();
RedBearLab 0:5810870d2b29 67
RedBearLab 0:5810870d2b29 68 void setSPIMode( uint8_t mode );
RedBearLab 0:5810870d2b29 69 void setFrequency(uint8_t speed );
RedBearLab 0:5810870d2b29 70 void setBitORDER( BitOrder bit);
RedBearLab 0:5810870d2b29 71 void setCPHA( bool trailing);
RedBearLab 0:5810870d2b29 72 void setCPOL( bool active_low);
RedBearLab 0:5810870d2b29 73
RedBearLab 0:5810870d2b29 74
RedBearLab 0:5810870d2b29 75 private:
RedBearLab 0:5810870d2b29 76 NRF_SPI_Type *spi;
RedBearLab 0:5810870d2b29 77
RedBearLab 0:5810870d2b29 78 uint32_t SCK_Pin;
RedBearLab 0:5810870d2b29 79 uint32_t MOSI_Pin;
RedBearLab 0:5810870d2b29 80 uint32_t MISO_Pin;
RedBearLab 0:5810870d2b29 81
RedBearLab 0:5810870d2b29 82 };
RedBearLab 0:5810870d2b29 83
RedBearLab 0:5810870d2b29 84 #endif