i want to send 132bytes of data to master but it is being received as garbled.is there a solution to fix it.
Sure. Send multiple packets. Do you have a hardware device that requires it?
The default buffer size is 32 bytes. If you have to send one long packet, rather than breaking it up into multiple 32 byte packets, you will have to edit two library files.
In ...\hardware\arduino\avr\libraries\Wire\src\Wire.h change line 28 to:
#define BUFFER_LENGTH 132
In ...\hardware\arduino\avr\libraries\Wire\src\utility\twi.h change line 32 to:
#define TWI_BUFFER_LENGTH 132
This will require more ram for the larger buffer.
Pete
thanks for replying will check it one more thing can we sync two arduino in spi mode if possible as earlier i was planning to use spi but my code didnt worked
i m recieving weired characters from slave
is my code correct
slave code
digitalWrite(13, Activity);
Serial.println("Readying... Data...");
DataOut+=","+String(((millis()-time)))+"|NODES7S|\n";
Serial.println(DataOut);
DataOut.toCharArray(Buff,200);
isReady=true;
}
}
}
void requestCallback()
{
if((!isProcessing)&&(DataIn!=""))
{
Wire.write("80\n");
isProcessing=true;
}
else if(((isProcessing)&&(isReady))&&(DataIn!=""))
{
Wire.write(Buff);
DataOut="";
DataIn="";
memset(Buff,0,200);
}
else
{
Wire.write(-1);
}
}
master code
int Request()
{
DataIn="";
Wire.requestFrom(8, 150);
while (Wire.available())
{
char c = Wire.read();
if(c!='\n')
{
DataIn.concat(c);
}
else
{
break;
return 1;
}
}
return 0;
}
Two problems.
-
you're now requesting 150 bytes - not 132.
-
using the String library will probably cause you to run out of ram which can cause all sorts of weird crashes or strange output. Change your code to use C null-terminated strings.
-
you didn't post all your code so it's hard to know if those snippets are going to work.
Oh, that's three problems.
Pete
you mean char array right used it didnt work
ashish_13:
you mean char array right used it didnt work
Char arrays have been working since 1969. So you did something wrong.
What ?? can u point out ?
ashish_13:
What ?? can u point out ?
If you post the code, myself or someone else might be able to do that.