I’m using a W5500 with an Atmel AVR XMega MCU. Going pretty well so far. I now want to write polled code to receive from a TCP socket - I don’t have the option to write interrupt driven code because I’m working inside a bootloader and trying to present a virtual serial port (serial data encapsulated in TCP) without making changes to the main bootloader code.
It is possible that the W5500 will receive more than one packet before I poll it. If this happens, I believe the Sn_RX_RSR register will contain the total amount of data received, so I will not be able to tell how many packets have been received - and I will not know how many times to issue a RECV command (Sn_CR = RECV). Is this correct?
This problem does not happen with UDP because received data also includes a header with the sender IP, socket and payload length, so individual packets can be identified. Can these headers be enabled for TCP reception?
I must confess that I’m coding without hardware just now so I’ve not been able to try this. I know the 8 byte information header is there with UDP packets but the documentation I’m looking at is not clear about TCP. If what you say works - fantastic - and thanks!
I will talk about TCP mode. There’s RAW mode, which I never used myself, which, as declared, should have info you are looking for.
Chip will receive all packets which fit into its socket’s buffer.
Yes.
RECV command instructs W5500 to check free space in the buffer (RX_RSR), and request remote host to send next packet in sequence (I simplify things a bit); if then sent packets fit buffer W5500 stores them, if not, discards until it has enough space. Thus you need to issue RECV command only once you freed space in the RX buffer.
In TCP mode - no, it provides stream of data only. Try RAW mode.