Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: cc3000_ping_demo_try_2
Fork of mbed by
SPI3.h@10:fcb9359f0959, 2009-05-14 (annotated)
- Committer:
- simon.ford@mbed.co.uk
- Date:
- Thu May 14 14:44:00 2009 +0000
- Revision:
- 10:fcb9359f0959
- Parent:
- 5:62573be585e9
Minor fix: Modified rtc time() functions to be in std namespace
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| simon.ford@mbed.co.uk | 5:62573be585e9 | 1 | /* mbed Microcontroller Library - SPI3 |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 2 | * Copyright (c) 2007-2009, sford |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 3 | */ |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 4 | |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 5 | #ifndef MBED_SPI3_H |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 6 | #define MBED_SPI3_H |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 7 | |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 8 | #include "Base.h" |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 9 | #include "LPC2300.h" |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 10 | |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 11 | namespace mbed { |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 12 | |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 13 | /* Class: SPI3 |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 14 | * A SPI Master, used for communicating with 3-wire SPI slave devices |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 15 | * |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 16 | * 3-wire SPI devices use the same line for input an output, and should be connected to both |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 17 | * the mosi and miso pins on the mbed Microcontroller |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 18 | */ |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 19 | |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 20 | class SPI3 : public Base { |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 21 | |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 22 | public: |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 23 | |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 24 | /* Constructor: SPI3 |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 25 | * Create a 3-wire SPI master connected to the specified pins |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 26 | * |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 27 | * Variables: |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 28 | * mosi - SPI Master Out, Slave In pin |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 29 | * miso - SPI Master In, Slave Out pin |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 30 | * sclk - SPI Clock pin |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 31 | * |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 32 | * Pin Options: |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 33 | * (5, 6, 7) or (11, 12, 13) |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 34 | */ |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 35 | SPI3(int mosi, int miso, int sclk, const char *name=NULL); |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 36 | |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 37 | /* Function: format |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 38 | * Configure the data transmission format |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 39 | * |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 40 | * Variables: |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 41 | * bits - Number of bits per SPI frame (4 - 16, default = 8) |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 42 | * mode - Clock polarity and phase mode (0 - 3, default = 0) |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 43 | * |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 44 | * > mode | POL PHA |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 45 | * > -----+-------- |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 46 | * > 0 | 0 0 |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 47 | * > 1 | 0 1 |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 48 | * > 2 | 1 0 |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 49 | * > 3 | 1 1 |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 50 | */ |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 51 | void format(int bits = 8, int mode = 0); |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 52 | |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 53 | // old one... |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 54 | void format(int bits = 8, int polarity = 0, int phase = 0); |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 55 | |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 56 | /* Function: frequency |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 57 | * Set the bus clock frequency |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 58 | * |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 59 | * Variables: |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 60 | * hz - SCLK frequency in hz (default = 1MHz) |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 61 | */ |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 62 | void frequency(int hz = 1000000); |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 63 | |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 64 | /* Function: write |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 65 | * Set the direction to output and write to the SPI Slave |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 66 | * |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 67 | * Variables: |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 68 | * value - Data to be sent to the SPI slave |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 69 | */ |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 70 | void write(int value); |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 71 | |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 72 | /* Function: read |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 73 | * Set the direction to input, read from the SPI Slave |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 74 | * |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 75 | * Variables: |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 76 | * returns - Response from the SPI slave |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 77 | */ |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 78 | int read(); |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 79 | |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 80 | virtual const struct rpc_method *get_rpc_methods(); |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 81 | static struct rpc_class *get_rpc_class(); |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 82 | |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 83 | protected: |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 84 | |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 85 | void configure(); |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 86 | |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 87 | int _id; |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 88 | |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 89 | int _uid; |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 90 | static int _uidcounter; |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 91 | |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 92 | int _bits, _polarity, _phase, _hz; |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 93 | static int _config[2]; |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 94 | const LPC2300::PortMap* mosi_portmap; |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 95 | }; |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 96 | |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 97 | } |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 98 | |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 99 | #endif |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 100 |
