Lab 1 Program C
Fork of mbed by
SPI.h@1:6b7f447ca868, 2008-04-30 (annotated)
- Committer:
- simon.ford@mbed.co.uk
- Date:
- Wed Apr 30 15:43:24 2008 +0000
- Revision:
- 1:6b7f447ca868
- Parent:
- 0:82220227f4fa
- Child:
- 4:5d1359a283bc
Fixes:
- ADC bug
- Newlines at end of files
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
simon.ford@mbed.co.uk | 0:82220227f4fa | 1 | /* mbed Microcontroller Library - SPI |
simon.ford@mbed.co.uk | 0:82220227f4fa | 2 | * Copyright (c) 2007-2008, sford |
simon.ford@mbed.co.uk | 0:82220227f4fa | 3 | */ |
simon.ford@mbed.co.uk | 0:82220227f4fa | 4 | |
simon.ford@mbed.co.uk | 0:82220227f4fa | 5 | #ifndef MBED_SPI_H |
simon.ford@mbed.co.uk | 0:82220227f4fa | 6 | #define MBED_SPI_H |
simon.ford@mbed.co.uk | 0:82220227f4fa | 7 | |
simon.ford@mbed.co.uk | 0:82220227f4fa | 8 | #include "Base.h" |
simon.ford@mbed.co.uk | 0:82220227f4fa | 9 | #include "LPC2300.h" |
simon.ford@mbed.co.uk | 0:82220227f4fa | 10 | |
simon.ford@mbed.co.uk | 0:82220227f4fa | 11 | namespace mbed { |
simon.ford@mbed.co.uk | 0:82220227f4fa | 12 | |
simon.ford@mbed.co.uk | 0:82220227f4fa | 13 | /* Class: SPI |
simon.ford@mbed.co.uk | 0:82220227f4fa | 14 | * A SPI Master, used for communicating with SPI slave devices |
simon.ford@mbed.co.uk | 0:82220227f4fa | 15 | */ |
simon.ford@mbed.co.uk | 0:82220227f4fa | 16 | class SPI : public Base { |
simon.ford@mbed.co.uk | 0:82220227f4fa | 17 | |
simon.ford@mbed.co.uk | 0:82220227f4fa | 18 | public: |
simon.ford@mbed.co.uk | 0:82220227f4fa | 19 | |
simon.ford@mbed.co.uk | 0:82220227f4fa | 20 | /* Group: Configuration Methods */ |
simon.ford@mbed.co.uk | 0:82220227f4fa | 21 | |
simon.ford@mbed.co.uk | 0:82220227f4fa | 22 | /* Constructor: SPI |
simon.ford@mbed.co.uk | 0:82220227f4fa | 23 | * Create a SPI master connected to the specified pins |
simon.ford@mbed.co.uk | 0:82220227f4fa | 24 | * |
simon.ford@mbed.co.uk | 0:82220227f4fa | 25 | * Variables: |
simon.ford@mbed.co.uk | 0:82220227f4fa | 26 | * mosi - SPI Master Out, Slave In pin |
simon.ford@mbed.co.uk | 0:82220227f4fa | 27 | * miso - SPI Master In, Slave Out pin |
simon.ford@mbed.co.uk | 0:82220227f4fa | 28 | * sclk - SPI Clock pin |
simon.ford@mbed.co.uk | 0:82220227f4fa | 29 | * |
simon.ford@mbed.co.uk | 0:82220227f4fa | 30 | * Pin Options: |
simon.ford@mbed.co.uk | 0:82220227f4fa | 31 | * (5, 6, 7) or (11, 12, 13) |
simon.ford@mbed.co.uk | 0:82220227f4fa | 32 | */ |
simon.ford@mbed.co.uk | 0:82220227f4fa | 33 | SPI(int mosi, int miso, int sclk); |
simon.ford@mbed.co.uk | 0:82220227f4fa | 34 | |
simon.ford@mbed.co.uk | 0:82220227f4fa | 35 | /* Function: format |
simon.ford@mbed.co.uk | 0:82220227f4fa | 36 | * Set the transmission format |
simon.ford@mbed.co.uk | 0:82220227f4fa | 37 | * |
simon.ford@mbed.co.uk | 0:82220227f4fa | 38 | * Variables: |
simon.ford@mbed.co.uk | 0:82220227f4fa | 39 | * bits - Number of bits per frame (4 - 16, default = 8) |
simon.ford@mbed.co.uk | 0:82220227f4fa | 40 | * polarity - Clock polarity, 0 = Steady state low (default), 1 = Steady state high |
simon.ford@mbed.co.uk | 0:82220227f4fa | 41 | * phase - Clock phase, 0 = Capture on first edge (default), 1 = Capture on second edge |
simon.ford@mbed.co.uk | 0:82220227f4fa | 42 | */ |
simon.ford@mbed.co.uk | 0:82220227f4fa | 43 | void format(int bits = 8, int polarity = 0, int phase = 0); |
simon.ford@mbed.co.uk | 0:82220227f4fa | 44 | |
simon.ford@mbed.co.uk | 0:82220227f4fa | 45 | /* Function: frequency |
simon.ford@mbed.co.uk | 0:82220227f4fa | 46 | * Set the bus clock frequency |
simon.ford@mbed.co.uk | 0:82220227f4fa | 47 | * |
simon.ford@mbed.co.uk | 0:82220227f4fa | 48 | * Variables: |
simon.ford@mbed.co.uk | 0:82220227f4fa | 49 | * hz - SCLK frequency in hz (default = 1MHz) |
simon.ford@mbed.co.uk | 0:82220227f4fa | 50 | */ |
simon.ford@mbed.co.uk | 0:82220227f4fa | 51 | void frequency(int hz = 1000000); |
simon.ford@mbed.co.uk | 0:82220227f4fa | 52 | |
simon.ford@mbed.co.uk | 0:82220227f4fa | 53 | /* Group: Access Methods */ |
simon.ford@mbed.co.uk | 0:82220227f4fa | 54 | |
simon.ford@mbed.co.uk | 0:82220227f4fa | 55 | /* Function: write |
simon.ford@mbed.co.uk | 0:82220227f4fa | 56 | * Write to the SPI Slave and return the response |
simon.ford@mbed.co.uk | 0:82220227f4fa | 57 | * |
simon.ford@mbed.co.uk | 0:82220227f4fa | 58 | * Variables: |
simon.ford@mbed.co.uk | 0:82220227f4fa | 59 | * value - Data to be sent to the SPI slave |
simon.ford@mbed.co.uk | 0:82220227f4fa | 60 | * returns - Response from the SPI slave |
simon.ford@mbed.co.uk | 0:82220227f4fa | 61 | */ |
simon.ford@mbed.co.uk | 0:82220227f4fa | 62 | int write(int value); |
simon.ford@mbed.co.uk | 0:82220227f4fa | 63 | |
simon.ford@mbed.co.uk | 0:82220227f4fa | 64 | protected: |
simon.ford@mbed.co.uk | 0:82220227f4fa | 65 | |
simon.ford@mbed.co.uk | 0:82220227f4fa | 66 | void configure(); |
simon.ford@mbed.co.uk | 0:82220227f4fa | 67 | |
simon.ford@mbed.co.uk | 0:82220227f4fa | 68 | int _id; |
simon.ford@mbed.co.uk | 0:82220227f4fa | 69 | |
simon.ford@mbed.co.uk | 0:82220227f4fa | 70 | int _uid; |
simon.ford@mbed.co.uk | 0:82220227f4fa | 71 | static int _uidcounter; |
simon.ford@mbed.co.uk | 0:82220227f4fa | 72 | |
simon.ford@mbed.co.uk | 0:82220227f4fa | 73 | int _bits, _polarity, _phase, _hz; |
simon.ford@mbed.co.uk | 0:82220227f4fa | 74 | static int _config[2]; |
simon.ford@mbed.co.uk | 0:82220227f4fa | 75 | }; |
simon.ford@mbed.co.uk | 0:82220227f4fa | 76 | |
simon.ford@mbed.co.uk | 0:82220227f4fa | 77 | } |
simon.ford@mbed.co.uk | 0:82220227f4fa | 78 | |
simon.ford@mbed.co.uk | 1:6b7f447ca868 | 79 | #endif |
simon.ford@mbed.co.uk | 1:6b7f447ca868 | 80 |