Daisuke Yanagihara
/
ref_spi_simplest_master
v2
spi_master.cpp@2:6d9572f5523e, 2021-01-07 (annotated)
- Committer:
- Yanagihara
- Date:
- Thu Jan 07 10:14:58 2021 +0000
- Revision:
- 2:6d9572f5523e
- Parent:
- 1:5a1355e57aed
- Child:
- 3:894278e5d918
v2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
taiga_prelude | 0:382b3838a100 | 1 | #include "mbed.h" |
taiga_prelude | 0:382b3838a100 | 2 | |
taiga_prelude | 0:382b3838a100 | 3 | SPI to_eps(p5,p6,p7); |
taiga_prelude | 0:382b3838a100 | 4 | DigitalOut cs(p8); |
taiga_prelude | 0:382b3838a100 | 5 | |
taiga_prelude | 0:382b3838a100 | 6 | Serial pc(USBTX,USBRX); |
taiga_prelude | 0:382b3838a100 | 7 | |
taiga_prelude | 0:382b3838a100 | 8 | #define DTIME 0.1 |
taiga_prelude | 0:382b3838a100 | 9 | |
taiga_prelude | 0:382b3838a100 | 10 | int main() |
taiga_prelude | 0:382b3838a100 | 11 | { |
taiga_prelude | 0:382b3838a100 | 12 | pc.printf("--Hi,this is cdh(master).\r\n"); |
taiga_prelude | 0:382b3838a100 | 13 | cs = 1; |
taiga_prelude | 0:382b3838a100 | 14 | |
Yanagihara | 2:6d9572f5523e | 15 | to_eps.format(8,3); |
taiga_prelude | 0:382b3838a100 | 16 | to_eps.frequency(1000000); |
taiga_prelude | 0:382b3838a100 | 17 | int cmd = 0; |
taiga_prelude | 0:382b3838a100 | 18 | |
taiga_prelude | 0:382b3838a100 | 19 | while(1) { |
taiga_prelude | 0:382b3838a100 | 20 | char c = pc.getc(); |
taiga_prelude | 0:382b3838a100 | 21 | pc.printf("count: %d, ",cmd); |
taiga_prelude | 0:382b3838a100 | 22 | |
taiga_prelude | 0:382b3838a100 | 23 | cs=0; |
taiga_prelude | 0:382b3838a100 | 24 | int dummy = to_eps.write(cmd); // send command |
taiga_prelude | 0:382b3838a100 | 25 | cs=1; |
taiga_prelude | 0:382b3838a100 | 26 | |
Yanagihara | 1:5a1355e57aed | 27 | pc.printf("dummy: %x, ",dummy); |
Yanagihara | 1:5a1355e57aed | 28 | |
Yanagihara | 1:5a1355e57aed | 29 | if(cmd == 1){ |
Yanagihara | 1:5a1355e57aed | 30 | wait(1); |
Yanagihara | 1:5a1355e57aed | 31 | cs=0; |
Yanagihara | 1:5a1355e57aed | 32 | int rdata = to_eps.write(0x00); |
Yanagihara | 1:5a1355e57aed | 33 | cs=1; |
Yanagihara | 1:5a1355e57aed | 34 | pc.printf("rdata: %x\r\n",rdata); |
Yanagihara | 1:5a1355e57aed | 35 | } |
Yanagihara | 1:5a1355e57aed | 36 | |
Yanagihara | 1:5a1355e57aed | 37 | if(cmd == 2){ |
Yanagihara | 1:5a1355e57aed | 38 | wait(3); |
Yanagihara | 1:5a1355e57aed | 39 | cs=0; |
Yanagihara | 1:5a1355e57aed | 40 | int rdata1 = to_eps.write(0x00); |
Yanagihara | 1:5a1355e57aed | 41 | int rdata2 = to_eps.write(0x00); |
Yanagihara | 1:5a1355e57aed | 42 | cs=1; |
Yanagihara | 1:5a1355e57aed | 43 | pc.printf("rdata1: %x\r\n",rdata1); |
Yanagihara | 1:5a1355e57aed | 44 | pc.printf("rdata2: %x\r\n",rdata2); |
Yanagihara | 1:5a1355e57aed | 45 | } |
taiga_prelude | 0:382b3838a100 | 46 | |
taiga_prelude | 0:382b3838a100 | 47 | cmd++; |
taiga_prelude | 0:382b3838a100 | 48 | } |
taiga_prelude | 0:382b3838a100 | 49 | } |