WIZnet Developer Forum

Problem on receiving continuous buffer data from w5500

Hi,

I am using w5500 chip with 2kB transmit buffer to send data to PC using TCP protocol. I am able to send some data from PC to w5500 and hence establish a connection, then I receive the buffer data once from wizchip. My expectation was that I should receive the buffer data continuosly but this does not happen and I have to again send some bytes from PC to receive the next buffer content… seems like a new connection, but I do not see any disconnection messages in the wireshark. I do not understand why the buffer data is not being sent continuously… can someone tell me where do I look for the problem!??
I have attached the wireshark data trace…

could you please share your code for sending and receiving data to/from the PC?

Look into the W5500 driving code. Most probably driver is looping looking for incoming data, and incoming data (RX size !=0) triggering driver executing sending code.

[quote=“randomizer”]could you please share your code for sending and receiving data to/from the PC?[/quote]

void W5500_Write_TXBuf(unsigned char SocketNr, unsigned char *z, unsigned int len)
{
unsigned char /z[] =“Hallo ich bin da, wer noch?”,/ i, AdrHi, AdrLo;
unsigned int Adr;
// z[0]=169; z[1]=254;z[2]=101;z[3]=2;z[4]=0x13;z[5]=0x88;z[6]=0;z[7]=10;

TIMER_START(74);
#ifdef SEND_BLOCK

//       (<-        BSB            ->|<-  nR/W   ->|<-   OP ->, ADRHI, ADRLO)
//SPI_Block(CNTRL_Sn(Nr) | CNTRL_TXBUF | CNTRL_WRITE | CNTRL_VDM, AdrHi, AdrLo);	// ControlByte
// 13 + Rec BYTES
SPI_Block(SocketNr);
//SPI_BLOCK_MAC(AdrHi, AdrLo, CNTRL_Sn(Nr) | CNTRL_TXBUF | CNTRL_WRITE | CNTRL_VDM);

#else

// Page 56/65 (WizChip Datasheet 1.0):
// Sn_TX_WR
// 1. READ THE STARTING...(aka Sn_TX_RD):

// Lies Pointer (wohin Daten im Buffer?)
// 5 BYTES
GPO_ptr[3]  =  0x00 | FREQ_BIT | CS_BIT            ;	// Freq & nCS
SPI_Byte(0x00);											// 1. AdrByte
SPI_Byte(0x22);											// 2. AdrByte
//      (<-        BSB                ->|<-  nR/W   ->|<-   OP ->)
SPI_Byte(CNTRL_Sn(SocketNr) | CNTRL_REG | CNTRL_READ  | CNTRL_VDM);	// ControlByte
AdrHi = SPI_Byte(0xFF);		// DummyByte for Read
AdrLo = SPI_Byte(0xFF);		// DummyByte for Read
GPO_ptr[3]  =  0x00 | FREQ_BIT                     ;	// Freq
/////////////////////////////////////////////////////////

// 2. SAVE THE TRANSMITTING.. (write to Buffer starting @Adr

// Schreiben von Sn_TX_RD
// 3 BYTES + Rec
GPO_ptr[3]  =  0x00 | FREQ_BIT | CS_BIT            ;	// Freq & nCS
SPI_Byte(AdrHi);										// 1. AdrByte
SPI_Byte(AdrLo);										// 2. AdrByte
//      (<-        BSB                  ->|<-  nR/W   ->|<-   OP ->)
SPI_Byte(CNTRL_Sn(SocketNr) | CNTRL_TXBUF | CNTRL_WRITE | CNTRL_VDM);		// ControlByte
Adr = (AdrHi<<8) | AdrLo;

#ifdef DEBUG
xil_printf(“Sn_TX_WR: Adr = 0x%x %x %x\n\r”, Adr, AdrHi, AdrLo);
#endif

i=0;
while(i<len)
{

#ifdef DEBUG
xil_printf(" TX-S%d Byte %d 0x%x = 0x%x %d %c\n\r", 0, i, i, z[i], z[i], z[i]);
#endif
SPI_Byte(z[i++]);
Adr++;
}
GPO_ptr[3] = 0x00 | FREQ_BIT ; // Freq
/////////////////////////////////////////////////////////
AdrHi = (Adr & 0xFF00)>>8;
AdrLo = (Adr & 0x00FF) ;

// 3. AFTER SAVING... (update Sn_TX_WR to ADR)

// Schreiben von Sn_TX_WR
// 5 BYTES
GPO_ptr[3]  =  0x00 | FREQ_BIT | CS_BIT            ;	// Freq & nCS
SPI_Byte(0x00);											// 1. AdrByte
SPI_Byte(0x24);											// 2. AdrByte
//      (<-        BSB           ->|<-   nR/W  ->|<-   OP ->)
SPI_Byte(CNTRL_Sn(SocketNr) | CNTRL_REG  | CNTRL_WRITE | CNTRL_VDM);	// ControlByte
SPI_Byte(AdrHi);											// 1. AdrByte
SPI_Byte(AdrLo);											// 2. AdrByte
GPO_ptr[3]  =  0x00 | FREQ_BIT                     ;	// Freq
/////////////////////////////////////////////////////////

#ifdef DEBUG
xil_printf(“Sn_TX_WR: Adr = 0x%x %x %x\n\r”, Adr, AdrHi, AdrLo);
#endif

#endif
TIMER_STOPP(74);

}

void W5500_Send_TXBuf(unsigned char SocketNr)
{
W5500_SocketCmd(SocketNr, 0x20);
}

void W5500_SocketCmd(unsigned char SocketNr, unsigned char Cmd)
{

// 4. Socket 0, SEND:
// 4 BYTES
GPO_ptr[3]  =  0x00 | FREQ_BIT | CS_BIT            ;	// Freq & nCS
SPI_Byte(0x00);											// 1. AdrByte
SPI_Byte(0x01);											// 2. AdrByte
//      (<-         BSB               ->|<-   nR/W  ->|<-   OP ->)
SPI_Byte(CNTRL_Sn(SocketNr) | CNTRL_REG | CNTRL_WRITE | CNTRL_VDM);	// ControlByte
SPI_Byte(Cmd);
GPO_ptr[3]  =  0x00 | FREQ_BIT                     ;	// Freq
/////////////////////////////////////////////////////////

}

void W5500_Read_TXBuf(unsigned char SocketNr)
{
// Nur 10 Byte lesen…
unsigned char z,/z[] =“Hallo ich bin da, wer noch?”,/ i, AdrHi, AdrLo;
unsigned int Adr;
// z[0]=169; z[1]=254;z[2]=101;z[3]=2;z[4]=0x13;z[5]=0x88;z[6]=0;z[7]=10;

// Lies Pointer (wohin Daten im Buffer?)
GPO_ptr[3]  =  0x00 | FREQ_BIT | CS_BIT            ;	// Freq & nCS
SPI_Byte(0x00);											// 1. AdrByte
SPI_Byte(0x22);											// 2. AdrByte
//      (<-        BSB                ->|<-  nR/W  ->|<-   OP ->)
SPI_Byte(CNTRL_Sn(SocketNr) | CNTRL_REG | CNTRL_READ | CNTRL_VDM);	// ControlByte
AdrHi = SPI_Byte(0xFF);		// DummyByte for Read
AdrLo = SPI_Byte(0xFF);		// DummyByte for Read
GPO_ptr[3]  =  0x00 | FREQ_BIT                     ;	// Freq
/////////////////////////////////////////////////////////
Adr = (AdrHi<<8) + AdrLo;
Adr = Adr - 10;
AdrHi = (Adr & 0xFF00)>>8;
AdrLo = (Adr & 0x00FF)   ;

GPO_ptr[3]  =  0x00 | FREQ_BIT | CS_BIT            ;	// Freq & nCS
SPI_Byte(AdrHi);										// 1. AdrByte
SPI_Byte(AdrLo);										// 2. AdrByte
//      (<-        BSB                  ->|<-  nR/W  ->|<-   OP ->)
SPI_Byte(CNTRL_Sn(SocketNr) | CNTRL_TXBUF | CNTRL_READ  | CNTRL_VDM);	// ControlByte
i=0;
while(i<10)
{
	z = SPI_Byte(0xFF);
	xil_printf("  TX-S%d Byte %d 0x%x = 0x%x %d %c\n\r", 0, i, i, z, z, z);
	i++;
}
GPO_ptr[3]  =  0x00 | FREQ_BIT                     ;	// Freq
/////////////////////////////////////////////////////////

}

void W5500_Read_RXBuf(unsigned char SocketNr)
{
unsigned int i, Adr, Len;
unsigned char z, AdrHi, AdrLo, LenHi, LenLo;

// Lies Start-Adresse (wo beginnen Daten im Buffer?)
// 7 BYTES
GPO_ptr[3]  =  0x00 | FREQ_BIT | CS_BIT            ;	// Freq & nCS
SPI_Byte(0x00);											// 1. AdrByte
SPI_Byte(0x26);											// 2. AdrByte
//      (<-        BSB                ->|<-  nR/W  ->|<-   OP ->)
SPI_Byte(CNTRL_Sn(SocketNr) | CNTRL_REG | CNTRL_READ | CNTRL_VDM);	// ControlByte
LenHi = SPI_Byte(0xFF);		// Anzahl	0x26
LenLo = SPI_Byte(0xFF);		//			0x27

AdrHi = SPI_Byte(0xFF);		// Adr1		0x28
AdrLo = SPI_Byte(0xFF);		// Adr2		0x29
GPO_ptr[3]  =  0x00 | FREQ_BIT                     ;	// Freq
/////////////////////////////////////////////////////////

Len = (LenHi<<8) + LenLo;	//
Adr = (AdrHi<<8) + AdrLo;	//

#ifdef DEBUG
xil_printf(“Adr = 0x%x %x %x\n\rLen = %d %x %x\n\r”, Adr, AdrHi, AdrLo, Len, LenHi, LenLo);
#endif

/////////////////////////////////////////////////////////
// Auslesen von RX-Buffer von Socket SockNr, ab Adresse Adr, Anzahl Len:
// 3 + LEN
GPO_ptr[3]  =  0x00 | FREQ_BIT | CS_BIT            ;	// Freq & nCS
SPI_Byte(AdrHi);										// 1. AdrByte
SPI_Byte(AdrLo);										// 2. AdrByte
//      (<-        BSB                  ->|<-  nR/W  ->|<-   OP ->)
SPI_Byte(CNTRL_Sn(SocketNr) | CNTRL_RXBUF | CNTRL_READ | CNTRL_VDM);	// ControlByte

for(i=0; i < Len; i++)
{
	z = SPI_Byte(0xFF);		// DummyByte for Read
	xil_printf("  RX-S%d Byte %d 0x%x = 0x%x %d %c 0x%x\n\r", 0, i, i, z, z, z, Adr+i);
	if(i==7) xil_printf("\n\r");
}
GPO_ptr[3]  =  0x00 | FREQ_BIT                     ;	// Freq
/////////////////////////////////////////////////////////

// Start-Adresse updaten (Adr = Adr + Len)
// 5 BYTES
Adr = Adr + Len;
AdrHi = (Adr & 0xFF00)>>8;
AdrLo = (Adr & 0x00FF)   ;
//
GPO_ptr[3]  =  0x00 | FREQ_BIT | CS_BIT            ;	// Freq & nCS
SPI_Byte(0x00);											// 1. AdrByte
SPI_Byte(0x28);											// 2. AdrByte
//      (<-        BSB                      ->|<-  nR/W  ->|<-   OP ->)
SPI_Byte(CNTRL_Sn(SocketNr) | CNTRL_REG       | CNTRL_WRITE | CNTRL_VDM);	// ControlByte
SPI_Byte(AdrHi);											// 1. AdrByte
SPI_Byte(AdrLo);											// 2. AdrByte
GPO_ptr[3]  =  0x00 | FREQ_BIT                     ;	// Freq
/////////////////////////////////////////////////////////

// RECV-Command !
// 4 BYTES
GPO_ptr[3]  =  0x00 | FREQ_BIT | CS_BIT            ;	// Freq & nCS
SPI_Byte(0x00);											// 1. AdrByte
SPI_Byte(0x01);											// 2. AdrByte
//      (<-         BSB               ->|<-   nR/W  ->|<-   OP ->)
SPI_Byte(CNTRL_Sn(SocketNr) | CNTRL_REG | CNTRL_WRITE | CNTRL_VDM);	// ControlByte
SPI_Byte(0x40);											// RECV
GPO_ptr[3]  =  0x00 | FREQ_BIT                     ;	// Freq
/////////////////////////////////////////////////////////

// In Summe: 7 + 3 + LEN + 5 + 4 == 19 + LEN BYTES

}

Copyright © 2017 WIZnet Co., Ltd. All Rights Reserved.