Hello This is my first forum on Ardiono site. i really need help.
this is my problem im working on a project to send data from a arduino nano to another arduino nano with i2c. one is the master writer one is the slave receiver. but both of them send and receive from each other at the same time it works fine but i have one problem. the master keeps receiving data from the slave non stop that is what i need, but the slave receives only once and that's it i need the slave also to keep receiving non stop. i tried to reverse the code many times but no result.
This is the master code:
while (Wire.available());
Serial.print("Recieving floats as String...");
Serial.println();
Serial.println();
Serial.print("Full Array: ");
Serial.print(string);
Serial.println();
Serial.print(" Rendement belasting " );
Serial.print(RB);//as a string
//Serial.print(P);//as afloatSerial.println();
Serial.print(" Koppel belasting motor " );
Serial.print(KBM);
Serial.println();
Serial.print(" Vermogen belasting motor " );
Serial.print(VBM);
Serial.println();
Serial.print(" Temperatuur " );
Serial.print(TMP);
delay(1000);
Serial.println();
delay(1000);I2C_IN_Data_Array_Invullen();
Wire.beginTransmission(2); // transmit to device #8
dtostrf(Max_Verm, 5, 2, I2C_IN_Data_Array);
Wire.write(I2C_IN_Data_Array); // appx 8 bytes
dtostrf(Max_Snelhd, 5, 2, I2C_IN_Data_Array);
Wire.write(I2C_IN_Data_Array); // appx 8 bytes
dtostrf(Max_Temp, 5, 2, I2C_IN_Data_Array);
Wire.write(I2C_IN_Data_Array); // appx 8 bytes
dtostrf(Verm_Setpoint, 5, 2, I2C_IN_Data_Array);
Wire.write(I2C_IN_Data_Array); // appx 8 bytes
Wire.endTransmission(); // stop transmitting}
As you can see the first part is receiving from the slave and second part is sending to the same slave it works very good.
This is code of the slave:
void I2C_IN_Start(int howMany)
{
do
{
char c = Wire.read(); // receive byte as a character
I2C_IN_fulldata = I2C_IN_fulldata + c; //Keep saving whatever is comming
MV = I2C_IN_fulldata.substring(0, 5); //slpit String from 0 to 5
MS = I2C_IN_fulldata.substring(5, 10); // Split from 6 to 12
MT = I2C_IN_fulldata.substring(10, 15);// split from 13 to 18
VS = I2C_IN_fulldata.substring(15);//tot aan het einde van array
}
while (1<Wire.available()); // loop through all but the last
{// I2C_IN_Data_Array_Invullen();
Serial.print(" Hele string" );
Serial.println();
delay(1000);
Serial.print(I2C_IN_fulldata);
Serial.println();
Serial.println();
delay(1000);
Serial.print(MV);
Serial.println();
delay(1000);
Serial.print(MS);
Serial.println();
delay(1000);
Serial.print(MT);
Serial.println();
Serial.print(VS);
delay(1000);
}}
This is the interrupt of receiving here is the problem i guess it receives only once with out repeating.
I need to know why do i have this problem please. Thanks