Bluetooth and i2c

Slave

#include "mbed.h"

I2CSlave    slave( p28, p27 );        // sda, scl
DigitalOut myled(LED1);
DigitalOut myleds(LED2);
int main()
{
    slave.address(0xC0);
    while(1) {
        int i = slave.receive();
        switch(i) {
            case I2CSlave::ReadAddressed:
             //    printf("read from me\n");
                break;
            case I2CSlave::WriteGeneral:
             //    printf("%write to all\n");
                break;
            case I2CSlave::WriteAddressed:
               //  printf("%write to me\n");
                break;
            case I2CSlave::NoData:
              //   printf("No data\n");
                break;
        }
        int k = slave.read();
        printf("%d\n",k);
                
        }
}

Master

#include "mbed.h"

Serial rn42(p9,p10);
DigitalOut myled(LED1);
I2C i2c (p28,p27);

int main() {

    rn42.baud(115200);

    while (1) {
        if (rn42.readable()) {
            int x = rn42.getc();
            printf("%d\n",x);
            i2c.start();
            i2c.write(0xC0);
            i2c.write(x);
            i2c.stop();
            myled = !myled;
        }
    }
}


Please log in to post comments.