spislave name(mosi, miso, sclk, ssel, int *Data);
宣言すれば割り込み受信して*Dataに値が代入されます。
spislave.cpp@0:a43410d1c82b, 2016-03-17 (annotated)
- Committer:
- sgrsn
- Date:
- Thu Mar 17 14:40:37 2016 +0000
- Revision:
- 0:a43410d1c82b
- Child:
- 1:802fbf02e509
Please use this library with my spi class.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sgrsn | 0:a43410d1c82b | 1 | #include "mbed.h" |
sgrsn | 0:a43410d1c82b | 2 | #include "spislave.h" |
sgrsn | 0:a43410d1c82b | 3 | |
sgrsn | 0:a43410d1c82b | 4 | spislave::spislave(PinName mosi, PinName miso, PinName sclk, PinName ssel, int *Data) : SPISlave(mosi, miso, sclk, ssel), MyInterrupt(ssel) |
sgrsn | 0:a43410d1c82b | 5 | { |
sgrsn | 0:a43410d1c82b | 6 | MySPISlave = new SPISlave(mosi, miso, sclk, ssel); |
sgrsn | 0:a43410d1c82b | 7 | getData = Data; |
sgrsn | 0:a43410d1c82b | 8 | MyInterrupt.fall(this, &spislave::getdata); |
sgrsn | 0:a43410d1c82b | 9 | } |
sgrsn | 0:a43410d1c82b | 10 | void spislave::getdata() |
sgrsn | 0:a43410d1c82b | 11 | { |
sgrsn | 0:a43410d1c82b | 12 | bool flag=0; |
sgrsn | 0:a43410d1c82b | 13 | while(!flag) |
sgrsn | 0:a43410d1c82b | 14 | { |
sgrsn | 0:a43410d1c82b | 15 | if(SPISlave::receive()) |
sgrsn | 0:a43410d1c82b | 16 | { |
sgrsn | 0:a43410d1c82b | 17 | *getData = SPISlave::read(); |
sgrsn | 0:a43410d1c82b | 18 | SPISlave::reply(*getData); |
sgrsn | 0:a43410d1c82b | 19 | flag=1; |
sgrsn | 0:a43410d1c82b | 20 | } |
sgrsn | 0:a43410d1c82b | 21 | } |
sgrsn | 0:a43410d1c82b | 22 | } |
sgrsn | 0:a43410d1c82b | 23 | void spislave::format(int bits, int mode) |
sgrsn | 0:a43410d1c82b | 24 | { |
sgrsn | 0:a43410d1c82b | 25 | SPISlave::format(bits, mode); |
sgrsn | 0:a43410d1c82b | 26 | } |
sgrsn | 0:a43410d1c82b | 27 | void spislave::frequency(int speed) |
sgrsn | 0:a43410d1c82b | 28 | { |
sgrsn | 0:a43410d1c82b | 29 | SPISlave::frequency(speed); |
sgrsn | 0:a43410d1c82b | 30 | } |
sgrsn | 0:a43410d1c82b | 31 | void spislave::reply(int setdata) |
sgrsn | 0:a43410d1c82b | 32 | { |
sgrsn | 0:a43410d1c82b | 33 | SPISlave::reply(setdata); |
sgrsn | 0:a43410d1c82b | 34 | } |