Socket write pointer S0_TX_WR given random initial value

Hello!

When I have initialised my W5100 and start writing to the socket 0 memory space, the write pointer (offset from base address, named S0_TX_WR in the data sheet) starts at some random number rather than at zero. This makes the first packet I send smaller than I intend it to be as the offset reaches my TCP_PACKET_SIZE maximum before being incremented TCP_PACKET_SIZE times.

I know I could do subtraction of that initial value in my own code to compensate for this problem but I would like to keep the execution time as low as I possibly can, and would therefore want to avoid that. It is also nice to know that the system will behave in the exact same way each time it is switched on.

Why does S0_TX_WR start at a value other than 0? And how can I make the S0_TX_WR offset start at exactly 0 without messing up the way W5100 accesses the TX buffer?

hello, LukasWikander

Thank you for your question with W5100.

After TCP connection, as you know, the TX_WR has random value. And it is normal operation.

There is no problem with it. because TX_RD has same value with TX_WR as well.

If you send data packet, you will understand there is no data lose.

If you have any questions, please feel free to ask here

Thank you

You will have to use the address value after connection is established (or socket open for UDP mode).

Buffer is cyclical, thus you will have full buffer size free anyway. For example, if socket’s buffer is 2K and pointer after connecting is 839a, absolute location in the TX buffer will be 0x4000 + socket_base_offset + (0x839a & 0x7ff), “virtual” position within socket’s buffer is 0x839a & 0x7ff = 0x39a and you have 0x466 space for contiguous write, then you will have to reset absolute pointer to the beginning of socket’s buffer to write remaining 0x39a bytes to completely fill the TX buffer.

Note that after you write bytes TX_WR should still keep 16-bits, e.g. with 0x839a you write 0x10 bytes you update TX_WR with 0x83aa.