I am using a W5200 with a PIC32MX360F512L to implement an UDP communication between my embedded application and a PC. Everything is going perfectly fine until the RX memory overflow (2048 in my configuration)
Indeed, after the overflow, the RX_WR pointer does not return to the RX_RD value, which I compute perfectly well.
For exemple, If the W5200 have already received 2000 bytes that I have read and acknowledge, I have both RX_WR et RX_RD equal to this value; pretty normal. But if I send 50 more bytes, i will of course detect the overflow and compute RX_RD = 2050%2048 = 2. I write it in the register (I am sure it is correctly written as I have checked by reading back the RX_RD register at the correct address 0x4028). Nevertheless, The RX_WR goes to 2050. Therefore, the next received data are written in socket 1 memory and the RX_RSR register indicates 2048 received bytes (RX_WR-RX_RD = 2050-2 = 2048!).
I have of course tried to write “manually” the RX_WR register when the overflow is detected but his register seems to be read-only, even if it is indicated as [R/W] in the datasheet.
Therefore, my question is: how do I get the RX_WR pointer the correct value at the RX memory overflow?
Here you will find my receiving alogrithm.
- Read S0_RX_RD
- Compute address offset and physical address
- Read the header (8 bytes) and compute the data length (overflow correctly detected and processed)
- Read the data (overflow also correctly detected and processed)
- Compute new value of S0_RX_RD = (S0_RX_RD + 8 + DataLength) & 2047
- Write it in the W5200 register 0x4028 and 0x4029
- Proceed with the RCV command
- Clear the Sn_IR register by writting 1 in the according bits
I have already checked all my registers address and the my Write/REad functions. They work perfectly.
Moreover, I have already read all that was to read in the documentation and the forum.
So please, tell me what I am doing wrong ?
I have been on this problem for almost a entire week and the project allowed time is near its end. Therefore, a very quick answer would be greatly appreciated
Thanks in advance!