Delta_G:
It's hard to help when you show "examples" that aren't what really happened. Then we end up chasing some red herring instead of your actual problem. Please be explicit about what's really going on.
Assuming you MUST use String, perhaps the easiest solution is to add a terminator to your ‘dataToSend’, then your receiver can look for that marker to trim off the string of characters after the last character.
If you are getting a ⸮ in the String, then why on earth would you expect the String to change when you tell it to replace all ? with nothing?
If you are sending 25 characters, why are you asking for 32?
You seem to NOT understand just how masters and slaves are supposed to communicate, using I2C. If you need to send a variable amount of data from the master to the slave, you MUST do that in two steps. The first step is to send the amount of data (in binary, NOT ASCII). The second is to send the variable amount of data.
Clearly, on the receive end, you receive one byte, which tells you how many characters to receive. Then, you receive that number of characters.
PaulS:
If you are getting a ⸮ in the String, then why on earth would you expect the String to change when you tell it to replace all ? with nothing?
If you are sending 25 characters, why are you asking for 32?
You seem to NOT understand just how masters and slaves are supposed to communicate, using I2C. If you need to send a variable amount of data from the master to the slave, you MUST do that in two steps. The first step is to send the amount of data (in binary, NOT ASCII). The second is to send the variable amount of data.
Clearly, on the receive end, you receive one byte, which tells you how many characters to receive. Then, you receive that number of characters.
Yes, you are right. I started to learn I2C protocol from yesterday, so...
Anyway, after that I figured out something, because my config is like this:
Master receiver (reader)
Slave transmitter (writer)
So, what I did:
First, I'm sending command from Master to Slave to get the size of the prepared data.
Second, Then pasting the received data byte size and requesting the data by size from the Slave.