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

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include <mbed.h>
00002 DigitalOut myled(LED1);
00003 I2CSlave slave(D14, D15);
00004 int check = 0;
00005 char buf[1];
00006  
00007 i2c_rcv()
00008 void i2c_rcv()
00009 {
00010     int check = slave.receive();
00011 if(check == I2CSlave::WriteAddressed:) {
00012     if(check == I2CSlave::WriteAddressed) {
00013         slave.read(buf,1);
00014     }
00015 }
00016  
00017 int main()
00018 void check_data()
00019 {
00020  
00021     slave.address(0xA0);
00022  
00023         i2c_rcv();
00024  
00025         if(buf[0] == 0x01) {
00026             myled = 0;
00027         } else {
00028             myled = 1;
00029         {
00030             if(buf[0] == 0x01) {
00031                 myled = 0;
00032             } else {
00033                 myled = 1;
00034             }
00035  
00036         }
00037     }
00038  
00039     int main() {
00040         slave.address(0xA0);
00041         while (1) {
00042             i2c_rcv();
00043             check_data();
00044         }
00045     }