sato takumi
/
mbed_slave
a
Diff: main.cpp
- Revision:
- 0:8a10e55fdbab
diff -r 000000000000 -r 8a10e55fdbab main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Nov 01 05:08:54 2022 +0000 @@ -0,0 +1,37 @@ +#include "mbed.h" +Serial pc(USBTX, USBRX); +DigitalOut myleds[]={LED1,LED2}; +SPISlave slave(p11,p12,p13,p14); +DigitalOut pin21(p21); +DigitalOut pin22(p22); +int counter = 0; +int main() { + slave.format(8,0); + slave.frequency(1000000); + while(1){ + if(slave.receive()){ + int val = slave.read();//受信データをvalに格納する + pc.printf("received from master : %d\r\n",val); + if(val==0xAA){ + //myleds[0]=1; + //wait(1.0); + //myleds[0]=0; + pin21=1; + wait(1.0); + pin21=0; + } + + else if(val==0xAB){ + pc.printf("Hello World!\r\n"); + //myleds[1]=1; + //wait(1.0); + //myleds[1]=0; + pin22=1; + wait(1.0); + pin22=0; + } + counter = counter+1; + slave.reply(counter); + } + } +}