Sending from arduino slave to beaglebone black master

Hello community,

I apologise for my previous topic. I have a problem where I want to send data from an arduino slave to a beagle bone black master using I2C. I have connected both the devices with wires from SDA and SCL. Nothing too difficult. I have written a little arduino code and the arduino slave is being detected with i2cdetect -r 2, so that is good. Now I have also sent some data with Wire.onRequest(handler). When I do this every register gets a value of 0x30. I use i2cdump and i2cget to check this. I am not really understanding why this happens so I would appreciate some help on this. I would like to be able to send data to a certain register and also to make it something else than 0x30 all the time. Below is the code I have now. Thank you in advance.

#include <Wire.h>

#define SLAVE_ADDRESS 0x04


void setup() {

Wire.begin(SLAVE_ADDRESS);
Wire.onReceive(receiveEvent);
Wire.onRequest(requestEvent);
Serial.begin(9600);

}

void loop() {


}

void receiveEvent(int howMany) {
  while(2000 < Wire.available())
  {
    char c = Wire.read();
    Serial.print(c);
  }

  int x = Wire.read();
  Serial.println(x);
}

void requestEvent() {

Wire.write("0xFF");
  
}

Greetings

I have a problem where I want to send data from an arduino slave to a beagle bone black master using I2C.

Of course you have, this is not possible. You can only answer requests by the master, the slave cannot send data by itself.

void receiveEvent(int howMany) {
  while(2000 < Wire.available())
  {
    char c = Wire.read();
    Serial.print(c);
  }

  int x = Wire.read();
  Serial.println(x);
}

How did you get to the 2000? I hope you can see that this while loop will never run, the I2C buffer is 32 bytes.

And never use any method of the Serial object in interrupt context! It depends on interrupts to work but in interrupt context all interrupts are disabled. receiveEvent() and requestEvent() are called in interrupt context.

When I do this every register gets a value of 0x30.

Because that’s the value you send:

Wire.write("0xFF");

Hint: the ASCII value of “0” is 0x30.