I’m new to Wiznet. I have a wiz550io connected to a Microchip 16F1847.
After resetting the wiz550io, I can receive a packet, and send a packet via TCP. I can’t set up for the next packet.
I’m comparing the Sn_RX_RD to the Sn_RX_WR to see if new data came. After reading the packet, I try to advance the Sn_RX_RD to equal the Sn_RX_WR. It doesn’t store the new Sn_RX_RD value. As a consequence, I always think I’ve received new data via TCP.
Please refer to W5100 datasheet wiznet.co.kr/wp-content/uplo … v1.2.6.pdf for detailed explanation of pointer management - starting with Chapter 5 “Functional description”. W5500 is similar to W5100 in design, thus most rules will apply.
You already have register called Sn_RX_RSR, which has the same information you need.
This is correct - to have Sn_RX_RD pointer change you should issue RECV command. Until you do it, RD pointer will read old value.
Even though there’s a window for data - for example 2kB which means relative offset 0-7ff within the socket’s buffer, you should use 16-bit pointers. For example, if Sn_RX_RD is equal to 0x9f76, if you received 0x2e5 bytes, updated pointer you write back is 0xa25b.
Datasheet is clear about it:
Sn_RX_WR (Socket n RX Write Pointer Register) [R] [0x002A-0x002B] [0x0000]
No, 2K is 0x800, thus mask is 0x7ff. Read theory in W5100 datasheet, and you will understand.
is there any way to reset the Sn_RX_WR to 0 ? because eventually Sn_RX_WR will exceed the maximum buffer size (default is 2K which is 0x07FF)
i know if i close/disconnect the socket and reconnect it, the pointers will reset to 0, but i don’t want to do that. I want to keep the connection alive. Please give me suggestion.
i decided not to reset Sn_RX_WR to 0 in order not to change the connection status.
instead i must calculate the size difference between the new pointer and the last pointer to know the size of the received data
it was rather complicated to do it, but it works fine until now.
This problem does not exist. The read and write buffers are circular, while pointers are 16-bit (0-FFFF), their lower bits address the buffer of size you set (or default buffer size).
You do NOT need to reset pointers to 0, you continue reading from (for RX) or writing to (for TX) in circular manner. Example: your buffer is 4K (0x1000), and current pointer is 0x7ec5. You want to write 0x800 bytes. Therefore you perform two transactions: first is T1=0x1000-(0x7ec5 & 0xfff) which is less than 0x800 to fill remainder of the buffer from the current write pointer, and then restart writing at the beginning of the buffer amount of data equal to 0x800-T1, and then update (16-bit!) pointers and issue SEND command.