I’m having problems with sending packets using UDP sockets. The issue is that I can’t set DIPR and DPORT registers, reading them always returns 0’s.
I was wondering if this is a known problem. I believe that my socket configuration and packet sending function is correct, as I am using these for both UDP and TCP comunication, the latter working correctly.
I included my open socket and data send functions. I hope someone will be able to help me locate the source of this problem.
W5300_write_TMP.c (2.49 KB)
Which registers you initialize, and with which information - in both main registers area and respective socket area, before you have problems?
I am using standard initialization written using the documentation. MR is all 0’s. Iahve two sockets active, one for each protocol.
I just noticed one thing. I can open the socket as TCP, write to DIPR and and DPORT, and then close it and open again as UDP. Then the values are kept and packets do get send. This is obviously no solution to the problem, just an observation.
Four LSB of Sn_MR zero means socket is closed, and of course nothing will be sent. Sn_MR should have value 02.
Flow is the following:
- you ensure you have functional gateway IP address in GAR, proper IP address in SIPR and mask in SUBR, and proper MAC address in SHAR;
- you set up Sn_MR with 02;
- you set up source port Sn_PORT;
- you open socket;
- you set up destination port Sn_DPORT and destination IP address Sn_DIPR;
- and now you can send packets.
Oh, I meant the main Mode Register, I obviously set the protocol in Sn_MR. I also don’t think the problem is with the configuration (as I said, I am able to send packets using some weird workarounds), but I’ll double check everything to be sure.
Sequence of register initialization matters, and there’re some circumstances when register will read 0s until you perform some action - I do not remember exactly, but like in TCP mode after you open socket you set up remote IP address, but until you issue CONNECT request you read 0s from IP address registers. Only after connection request is made these fields read what you would expect them to read
Yes, I noticed this. Obviously there is no CONNECT request in UDP, I was wondering if there is another operation thet would validate data written to the registers. I believe that my code is analogical to the one in documentation, but I will check it again to be sure. Thank you for your help, do let me know if you think of something to add