Kevin Moloney
/
spi-master-demo
test
main.cpp@0:57242c7f2b63, 2017-06-02 (annotated)
- Committer:
- kevin1990
- Date:
- Fri Jun 02 09:18:26 2017 +0000
- Revision:
- 0:57242c7f2b63
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kevin1990 | 0:57242c7f2b63 | 1 | #include "mbed.h" |
kevin1990 | 0:57242c7f2b63 | 2 | |
kevin1990 | 0:57242c7f2b63 | 3 | #define VALUE_SENT 0xFA |
kevin1990 | 0:57242c7f2b63 | 4 | |
kevin1990 | 0:57242c7f2b63 | 5 | Serial pc(SERIAL_TX, SERIAL_RX); |
kevin1990 | 0:57242c7f2b63 | 6 | SPI spi(D11, D12, D13); |
kevin1990 | 0:57242c7f2b63 | 7 | |
kevin1990 | 0:57242c7f2b63 | 8 | DigitalOut chipSelect(D10); |
kevin1990 | 0:57242c7f2b63 | 9 | |
kevin1990 | 0:57242c7f2b63 | 10 | int main() |
kevin1990 | 0:57242c7f2b63 | 11 | { |
kevin1990 | 0:57242c7f2b63 | 12 | int masterVal = VALUE_SENT; |
kevin1990 | 0:57242c7f2b63 | 13 | chipSelect = 1; // Deselect device |
kevin1990 | 0:57242c7f2b63 | 14 | |
kevin1990 | 0:57242c7f2b63 | 15 | spi.format(8,3); // Setup: bit data, high steady state clock, 2nd edge capture |
kevin1990 | 0:57242c7f2b63 | 16 | spi.frequency(1000000); //1MHz |
kevin1990 | 0:57242c7f2b63 | 17 | |
kevin1990 | 0:57242c7f2b63 | 18 | chipSelect = 0; // Select device |
kevin1990 | 0:57242c7f2b63 | 19 | |
kevin1990 | 0:57242c7f2b63 | 20 | spi.write(masterVal); |
kevin1990 | 0:57242c7f2b63 | 21 | |
kevin1990 | 0:57242c7f2b63 | 22 | wait(2); |
kevin1990 | 0:57242c7f2b63 | 23 | chipSelect = 1; // Deselect device |
kevin1990 | 0:57242c7f2b63 | 24 | } |