I2C requestfrom trouble

Hello,
I 2 arduino UNO boards. One is a master and the other is a slave. The SD card is connected to the master and the Adafruit blufruit is connected to the slave. The SD card talks to the master through the SPI bus and the bluetooth talks to the slave using UART interface.

/WHAT I WANT TO DO ?*/
I am trying to send data from my phone to the bluetooth, connected to the slave and send that data to the master through I2C bus and write that data into the SD card connected via a SPI bus.

/I GOT THIS WORKING ALREADY/
I used Wire.requestFrom to request some bytes of data from the slave and used the Wire.Onrequest(requestEvent) to get the data. I used Wire.write("hello") inside the requestEvent to get the data. I successfully transferred the data from the slave to the SD card.

/My problem/
Now i have attached the adafruit blufruit to the slave arduino UNO board. I was able to get the data from bluetooth and print it on the Slave's serial terminal. I am using blu.read() to get the data storing it in a char and then printing it to display it on the terminal.

I am passing the same char to Wire.write() function. When i do this i am getting y and 2 dots on the top of it as data. When i tried changing it to int it was 255. I see that it is a high voltage saying that there is some data on the bus.

/MY RESULTS/

  1. I believe that the master is not looking for the data at the right time. There is a time conflict.
  2. I used both Wire.available() and Wire.read() inside the while loop on the master side to check for the data. None helped.
  3. I also used a static char buffer which is included in a header for storing the bluetooth data and i tried to extract the information from that buffer. This didn't work either.

All i get is a y with 2 dots over it.

Any help is appreciated. Thanks.

  1. I believe that the master is not looking for the data at the right time. There is a time conflict.

Without actually seeing your code, it sounds like you are sending data to the slave, and expecting the slave to interrupt the master, to tell it that it has data to share. That illustrates a fundamental lack of understanding of master/slave relationships. A master asks for data. A slave supplies data. A slave can't ask the master to do anything.

  1. I used both Wire.available() and Wire.read() inside the while loop on the master side to check for the data. None helped.

The master didn't ask for anything. So, it is unreasonable to expect the slave to supply anything.

So, both the master and slave are on the same i2c bus so the flow of data would be from the phone (over bluetooth) -> adafruit bluetooth module -> uno 1 slave -> uno master.

If both unos are sharing the same bus, once the data is sent from the phone to the slave sends data (over bluetooth) to the shared i2c bus, can't that trigger the master to read the data on the bus?

This is the working code for the I2C bus

On the Master side:

//Arduino I2C tutorial
/**********************************M*A*S*T*E*R*****************************/
#include<Wire.h>

void setup() {
  Wire.begin();         //join the i2c bus
  Serial.begin(115200);   //start serial transfer - output
}

void loop() {
  Wire.requestFrom(2,27);  //request 6 bytes from slave device 2
  while(Wire.available())
  {
    char c = Wire.read(); //receive the bytea
    Serial.print(c);      //print the received information
  }
    delay(500);
   
}

On the slave side its:
/******************************************S*L*A*V*E*8**************************/
#include<Wire.h>
void setup() {
  Wire.begin(2);                //join i2c bus
  Wire.onRequest(requestEvent); //register an event

}

void loop() {
  delay(100);
}

void requestEvent()
{
  Wire.write("Slave 1 responding - COM 8\n");  //this statement gets displayed on the masters side
  Wire.write(c);   //c is the char variable which  stores the data from the bluetooth. The data from bluetooth
                         // gets transferred to the serial byte by byte. The bluetooth data is getting printed on the 
slaves terminal but it is not getting transmitted via wire.write(c).
}

I had a character delivered to the master once. I sent holla over bluetooth from my phone. I saw an a on the master the rest are y with 2 dots on the top. I think this is an timing issue. Any ideas on how to sync the slave and the master.

P.S Both are on the same I2C bus.

I2C is a master and one or more slaves network.
No slave is permitted to talk, unless the master asks them to.

So, what you need to do, is store the data in a buffer in the slave, until the master asks for it.

Have the master ask on a regular/reasonable time frame.

quote: "I think this is an timing issue."
Yes, I2C does require pretty strict timing issues. If the master asks a slave to talk, and the slave does not respond, then there can be several problems, one is the system may block any other functions.