Best regards:
I am using a Xmega and W5200, I have created a TCP Client with the W5200 and my PC is the server. When I press a button, I send a constant string to the server but the data arrives are random. After trying several times, the data arrives correctly and continues like this for about 50 more times and then the data arrives incorrectly and the loop is repeated. Sometimes after connecting the power the data reaches the server correctly but sometimes it does not.
When I send from the server to the W5200 the data always arrives correctly.
Code after connection is established:
uint16_t Sn_TX_WR0, dst_mask, size;
uint8_t * dst_ptr;
Read_W5200(BufferW5200, Sn_TX_WR, 2);
Sn_TX_WR0 = ((uint16_t)BufferW5200[0] << 8) + BufferW5200[1];
dst_mask = (uint32_t)Sn_TX_WR0 & gS0_TX_MASK;
dst_ptr = (uint8_t *)(gS0_TX_BASE + dst_mask);
if((dst_mask + nbytesBufferTxTCP) > ((uint32_t)gS0_TX_MASK + 1))
{
size = ((uint32_t)gS0_TX_MASK + 1) - dst_mask;
Write_W5200((uint8_t*)BufferTxTCP, (uint16_t)dst_ptr, size);
BufferTxTCP += size;
size = nbytesBufferTxTCP - size;
dst_ptr = (uint8_t *)(gS0_TX_BASE);
Write_W5200((uint8_t*)BufferTxTCP, (uint16_t)dst_ptr, size);
} else{
Write_W5200((uint8_t*)BufferTxTCP, (uint16_t)dst_ptr, nbytesBufferTxTCP);
}
Sn_TX_WR0 += nbytesBufferTxTCP;
BufferW5200[0] = (Sn_TX_WR0 & 0xFF00) >> 8;
BufferW5200[1] = Sn_TX_WR0 & 0x00FF;
Write_W5200((uint8_t*)BufferW5200, Sn_TX_WR, 2);
BufferW5200[0] = SEND;
Write_W5200((uint8_t*)BufferW5200, Sn_CR, 1);
Before to send when data is corrupt (info UART) …
nbytesBufferTxTCP = 001B
Socket 0 TX Free Size (Sn_TX_FSR0_1) = 2000
Socket 0 TX Read Pointer (Sn_TX_RD0_1) = 482C
Socket 0 TX Write Pointer (Sn_TX_WR0_1) = 482C
dst_mask = 002C
dst_ptr = 802C
(dst_mask + len) = 0047
BufferTxTCP = ALC10|948310257846825|40|1|
Reading TX buffer in 804A: ALC10|948310257846825|40|1|
After to send when data is corrupt (info UART) …
Socket 0 TX Free Size (Sn_TX_FSR0_1) = 2000
Socket 0 TX Read Pointer (Sn_TX_RD0_1) = 4847
Socket 0 TX Write Pointer (Sn_TX_WR0_1) = 4847
Before to send when data is OK (info UART) …
nbytesBufferTxTCP = 001B
Socket 0 TX Free Size (Sn_TX_FSR0_1) = 2000
Socket 0 TX Read Pointer (Sn_TX_RD0_1) = 204F
Socket 0 TX Write Pointer (Sn_TX_WR0_1) = 204F
dst_mask = 004F
dst_ptr = 804F
(dst_mask + len) = 006A
BufferTxTCP = ALC10|948310257846825|40|1|
Reading TX buffer in 804A: ALC10|948310257846825|40|1|
After to send when data is OK (info UART) …
Socket 0 TX Free Size (Sn_TX_FSR0_1) = 2000
Socket 0 TX Read Pointer (Sn_TX_RD0_1) = 206A
Socket 0 TX Write Pointer (Sn_TX_WR0_1) = 206A
I read the data written in the TX buffer before the send command and I verify that the data is in the correct position and the data is also correct, but sometimes this data arrives at the server changed but the number of bytes does match.
I attach an image of wireshark and hercules when the data is corrupt and when the data is OK.
Any suggestion?
Thanks.
EP.