I'm using this board - WiFi R3(atmega2560 + esp8266)
...and I trying to send messages to Serial(to ESP8266) with 115200 baud rate, and I get exactly corupted message, for example -
Bad: seupDate
Good: setupDate
...Or
Bad:
*WM:
*WM: AutoConnect
*WM: Connecting as wifi client...
*WM: Status:
*WM: 0
*WM: Using last saved values, should be faster
*WM: Connection result:
*WM: 3
*WM: IP Address:
*WM: 192.168.1.100
Also I know the problem is getting the message because when I see the ESP8266 serial monitor I get a good message.
Some context:
I trying to send about 150 messages less than 1 second. For example here one message: {"pixel":150,"rgb":"0, 0, 0"}
I'm getting messages on atmega2560(send from ESP8266) by Serial3 port
Maybe it's hardware related, the dip-switches are always suspect. Try switching them back and forth a few times, they may be just a little corroded. Your sketch looks fine to me.
I'm sorry, I've been away for a long time. @Deva_Rishi, yes, I have the board you mentioned.
I changed the DIP switches several times (4, to be exact) and it did not help.
Even when my code looks like this, the message is still corrupted:
void loop() {
while (Serial3.available()) doReadSerial();
}
Is there any code in your sketch which relies on interrupts ?
Shouldn't be an issue if you are using hwSerial. I think you can max out the UART of the Mega at 1Mbps (the ESP can do even more )
That shouldn't matter at all. I think you may be overflowing the RX-buffer of the Mega.
The ESP can send so much data that the Mega might not be able to process it all.
For testing purposes, send at a High Baud rate (250Kbps) but never send a message longer than 64 bytes, and wait 1 second in between messages.
Other possibility is of course that the level shifter on the board is just too slow, but that would usually result in 'broken bytes' not missing bytes.
If the Mega is caught up in an interrupt, the RX interrupt will not call the function transferring the data from the FIFO to the buffer.
Or if the read() function isn't called before the RX-buffer is full, any bytes received will be discarded.
To confirm the hardware is working properly, Upload a simple Serial-Passthrough sketch. You know you haven't shared the full sketch, which may include objects that do use interrupts, so we can't be sure.
Then i suggest you use a different method of debouncing. But you know that because of your lack of information (the complete sketch !) we had several different suggestions.
That means that the RX-buffer overflows. The bytes are transferred to the RX-buffer just fine, but you do not read from it in time, probably because Easy button is holding the processor up for too long.
You can increase the size of the RX-buffer i think without to much issue, simply by re-defining it's size, but that does increase the size for all used Serial objects i think (just looking at hardwareSerial.h & .cpp atm.
so
#define SERIAL_RX_BUFFER_SIZE 128 // 256 would be the max or the type of the index needs to be 16 bit.
will probably fix it already. You have the memory available, but it is a tad wasteful.
You have time, but you need to read the buffer before it is full.