Nucleo同士でのi2C通信(受信プログラム)

Dependencies:   mbed

main.cpp

Committer:
BIGBOSS04
Date:
2018-06-26
Revision:
0:f6c56f4e8f3e
Child:
1:fe1e055b834e

File content as of revision 0:f6c56f4e8f3e:

#include <mbed.h>
DigitalOut myled(LED1);
I2CSlave slave(D14, D15);
 
int main() {
   char buf[1];
   //char msg[] = "Slave!";
 
   slave.address(0xA0);
   while (1) {
       int i = slave.receive();
       switch (i) {
          
           case I2CSlave::WriteAddressed:
               slave.read(buf, 1);
               break;
        }
       if(buf[0] == 0x01){
           myled = 0;
        }else{
           myled = 1;
       }
   }
}