I have successfully used a W5500 to behave as a TCP server on several ports, but I am trying to send a UDP request to a NTP server, but whenever I send a Send via Sn_CR the Sn_IR always reports 0x08 (ie a timeout error), although setting up and opening the port is always ok.
According to Wireshark, the only traffic on the network is an ARP request to 0.0.0.0.
I am using fixed IPs and the Destination IP and port (123) in Sn_DIPR and Sn_DPORT respectively, 1024 in Sn_PORT (not 100% sure this is correct though) and havent written anything into Sn_DHAR.
The W5500s MAC, IP, mask, and gateway is set in SHAR, SIPR, SUBR, and GAR.
PORT INIT:
unsigned long Timeout;
unsigned short int SrcPort = 1024;//anything over 1023
unsigned char ServerIP[4], SR;
NetworkSettingsStruct NetSettings;
WriteByteToWiznet5500( SOCKET_MR, BSB_Socket, SOCKET_MODE_UDP ); // sets TCP/UDP mode
WriteByteToWiznet5500( ADDR_RCR, BSB_Socket, 3 );
GetModbusEthernetSettings( &NetSettings );
ServerIP[0] = (unsigned char)NetSettings.NTSAddress[0];
ServerIP[1] = (unsigned char)NetSettings.NTSAddress[1];
ServerIP[2] = (unsigned char)NetSettings.NTSAddress[2];
ServerIP[3] = (unsigned char)NetSettings.NTSAddress[3];
WriteArrayToWiznet5500( SOCKET_DIPR0,
BSB_SOCKET_3_TX,
ServerIP,
4 );
//src
WriteByteToWiznet5500( SOCKET_PORT0, BSB_SOCKET_3_TX, (1024)>>8 );
WriteByteToWiznet5500( SOCKET_PORT1, BSB_SOCKET_3_TX, (1024)&0x00ff );
//dest....typically 123
WriteByteToWiznet5500( SOCKET_DPORT0, BSB_SOCKET_3_TX, (NetSettings.NTS_UDPPort) >>8 );
WriteByteToWiznet5500( SOCKET_DPORT1, BSB_SOCKET_3_TX, (NetSettings.NTS_UDPPort) &0x00ff );
//clear any outstanding interrupt flags
WriteByteToWiznet5500( SOCKET_IR, BSB_Socket, 0x1f );
//Open socket
Timeout = _CP0_GET_COUNT() + WIZZNET_TIMEOUT_500ms;
WriteByteToWiznet5500( SOCKET_CR, BSB_Socket, SOCKET_CMD_OPEN );
while( (SR=ReadByteFromWiznet5500( SOCKET_SR, BSB_Socket )) != SOCKET_STAT_SOCK_UDP )
{
if( _CP0_GET_COUNT()>Timeout )
return 0;
}
return SOCKET_STAT_SOCK_UDP;
PORT SEND:
unsigned short int RxSize, OffsetAddress, i;
NPTStruct NetTimeReq;
unsigned char IR;
unsigned long int Timeout;
//clear the request to all zeros, except the 3 bit VN=4, And Mode=3 (ie client)
memset( &NetTimeReq, 0x00, sizeof(NetTimeReq) );
NetTimeReq.ModeBits = 0x1b;//(4<<2) | (0x03<<5);
OffsetAddress = ReadUINT16FromWiznet5500( SOCKET_TX_WR0, BSB_SOCKET_3_REG);
WriteArrayToWiznet5500( OffsetAddress,
BSB_SOCKET_3_TX,
&NetTimeReq,
sizeof(NetTimeReq) );
OffsetAddress = OffsetAddress + sizeof(NetTimeReq);
WriteUINT16ToWiznet5500( SOCKET_TX_WR0, BSB_SOCKET_3_REG, OffsetAddress );
WriteByteToWiznet5500( SOCKET_CR, BSB_SOCKET_3_REG, SOCKET_CMD_SEND );
Timeout = _CP0_GET_COUNT() + WIZZNET_TIMEOUT_900ms;
while( (IR = ReadByteFromWiznet5500( SOCKET_IR, BSB_SOCKET_3_REG)) == 0x00 )
{
// if( _CP0_GET_COUNT() > Timeout )
// return 0;
}
//clear down the interrupt/flag for next time
WriteByteToWiznet5500( SOCKET_IR, BSB_SOCKET_3_REG, IR );
if( IR == SOCKET_INT_SENDOK )
return 1;
else
return 0;
My only guess so far is might be a setting up the registers problem…any ideas? Thanks