Nucleo同士でのi2C通信(受信プログラム)
Dependencies: mbed
Diff: main.cpp
- Revision:
- 1:fe1e055b834e
- Parent:
- 0:f6c56f4e8f3e
--- a/main.cpp Tue Jun 26 07:32:13 2018 +0000 +++ b/main.cpp Tue Jun 26 07:34:58 2018 +0000 @@ -1,25 +1,45 @@ #include <mbed.h> DigitalOut myled(LED1); I2CSlave slave(D14, D15); +int check = 0; +char buf[1]; -int main() { - char buf[1]; - //char msg[] = "Slave!"; +i2c_rcv() +void i2c_rcv() +{ + int check = slave.receive(); +if(check == I2CSlave::WriteAddressed:) { + if(check == I2CSlave::WriteAddressed) { + slave.read(buf,1); + } +} + +int main() +void check_data() +{ + + slave.address(0xA0); + + i2c_rcv(); - 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; + { + if(buf[0] == 0x01) { + myled = 0; + } else { + myled = 1; + } + } - if(buf[0] == 0x01){ - myled = 0; - }else{ - myled = 1; - } - } -} - + } + + int main() { + slave.address(0xA0); + while (1) { + i2c_rcv(); + check_data(); + } + } \ No newline at end of file