Report
6 years ago.

Arduino + Mbed i2c?

Hello.

I am currently working on a project that requires me to send data from the mbed to the arduino using i2c... Does anyone have an idea of how i can do this? This is what i have tried so far.

mbed master code

#include "mbed.h"

Serial rn42(p9,p10);
DigitalOut myled(LED1);
I2C i2c (p28,p27);
int x;
int main()
{

    rn42.baud(115200);

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

arduino slave code

#include <Wire.h>

byte y;


void setup()
{

  Serial.begin(115200);
  Wire.begin(0xC0);
}

void loop()
{

Wire.onReceive(receiveEvent);  

}

void receiveEvent(int howMany)
{
  
   y = Wire.read();
   Serial.println (y); 
     
}

Thank you very much.

Comment on this question

2 Answers

1 year ago.

Be aware that mBed i2c addresses are shifted 1 bit to the left. So if you use the I2C address 0x0F (00001111) on the arduino, it will be 0x1E (00011110) on mBed

3 years, 4 months ago.

I'm in the same boat. Arduino (Master) sending messages to mbed (slave or another master). Has this already been mastered?


To post an answer, please log in.