Daisuke Yanagihara
/
ref_spi_simplest_master
v2
spi_master.cpp@0:382b3838a100, 2021-01-02 (annotated)
- Committer:
- taiga_prelude
- Date:
- Sat Jan 02 09:02:40 2021 +0000
- Revision:
- 0:382b3838a100
- Child:
- 1:5a1355e57aed
1st upload
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 | |
taiga_prelude | 0:382b3838a100 | 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 | int rdata = to_eps.write(0x00); |
taiga_prelude | 0:382b3838a100 | 26 | cs=1; |
taiga_prelude | 0:382b3838a100 | 27 | |
taiga_prelude | 0:382b3838a100 | 28 | pc.printf("dummy: %d, ",dummy); |
taiga_prelude | 0:382b3838a100 | 29 | pc.printf("rdata: %d\r\n",rdata); |
taiga_prelude | 0:382b3838a100 | 30 | |
taiga_prelude | 0:382b3838a100 | 31 | cmd++; |
taiga_prelude | 0:382b3838a100 | 32 | } |
taiga_prelude | 0:382b3838a100 | 33 | } |