Could you give an introduction ? Are you transferring data between two Arduino boards ? Which Arduino boards do you use ? What is your project about ?
Please give a complete (minimal) sketch. If you are using two Arduino boards, then please give two complete sketches.
A Arduino as a Slave uses the onRequest and the onReceive handlers. The Wire.requestFrom is for reading data from a sensor as a Master.
The Wire.flush() has no meaning.
This is the source code:
void TwoWire::flush(void)
{
// XXX: to be implemented.
}
There is nothing to implement, because the Arduino Wire library is blocking.
The Wire.readBytes() is from the Stream class. It is okay to use, bu only if you are sure that those bytes are available, since the Wire.readBytes() might wait. That waiting has no meaning for the I2C bus.
Could you use the parameters 'true' and 'false' for Wire.endTransmission() instead of 0 and 1 ?
[EDIT] I found that the Wire library has indeed a flush() function and I changed this post.
I'm using it for sending basically file (.bin) from one ESP32 using RS485 to another ESP32 with RS485.
So main thing what would like to do is to download .bin file from API and while receiving bytes it should transmit it to slave saving to SPIFF. When it's over with receiving on SPIFF it starts with update of FW. Download, save to SPIFF and flash is working now only thing left is to send data from master which download .bin to slave which would update FW.
This is just some of code, whole code is really big, don't know how would I present it here?
Also what is biggest number of bytes to transmit via Write?
In docs it says: Used by the master to request bytes from a slave device. The bytes may then be retrieved with the available() and read() functions.
Is this still good practice to use it for receiving on slave or should I use onReceived? BUt problem is that onReceived should be called inside loop, all of those functions I'm calling inside looop.
I have driver, communication on sending each byte separately is already working, what I want is to send bigger amount of data as know .bin has really big amount of bytes and if would be sending each byte separately it would take soo much time....
For one byte transmition and receiving I'm using this code:
Transmitter:
After all day which I'm into this I have everything done, download FW from API, save it on SPIFF, start transmiting bytes to slave and saving to SPIFF on slave, after transmition ends it flash slave from SPIFF. Everything works but biggest problem is too slow transmition, basically for example 100kb of .bin file size transmit from master to slave around 4min, which means in my case for .bin which is about 1.8mb of size would take about 72 minutes (1 hour and 12 minutes) which is WAY tooo much. Any ideas what to do now?
Meanwhile I have been reading the datasheet.
The read byte and write byte register at register address 0 is for a single byte.
If the FIFO mode is turned on, then that single byte changes into a FIFO buffer.
The FIFO is often used with a interrupt, but the FIFO will also work without interrupt.
You have to turn on the FIFO for both receiving and transmitting.
But the datasheet itself is not enough, not everything is explained.
How fast do you think that the I2C bus is ?
Perhaps you can achieve 20kbyte per second, with a 400kHz I2C bus.
I don't know the baud rate of your RS-485 bus.
What is the distance between the ESP32 boards ? Do you really need RS-485 ?
I would use the extra serial port in full-duplex mode without going through all the extra layers. I read that some have tested a baudrate of 4Mbps, that is 400kbyte per second. Assume some overhead, so it could be between 100kbyte and 200kbyte per second.
Asking a good question to get the answer that you need can be just as hard as answering a question. Have you read the guidelines of this forum ? How to get the best out of this forum