Сan't open socket in MACRAW protocol

I’m trying to open soket 0 in the MACRAW protocol, but when I check S0_SSR, it becomes 0x0100. This happens even if I try to open a socket in another protocol.

In this case, ping is valid, reading other registers is working correctly!

This is my code:

#define S0_MR 0x0200
#define S0_CR 0x0202
#define S0_CR 0x0208

void WriteReg (uint16_t Addr, uint16_t Data)

CS(0); WR(0); // WR+CS = 0
CS(1); WR(1); // WR+CS = 1


uint16_t ReadReg (uint16_t Addr)
uint16_t data;
DIR_CLR(0,4,0xFF); DIR_CLR(0,15,0xFF);
CS(0); RD(0); // RD+CS = 0
data = DATA;
CS(1); RD(1); // RD+CS = 1
DIR(0,4,0xFF); DIR(0,15,0xFF);
return (data);

WriteReg(S0_MR, 0x0004); /* sets MACRAW mode *
WriteReg(S0_CR, 0x0001); /* sets OPEN command */
temp1 = ReadReg(S0_SSR);
} while(temp1 != 0x0042);


You did not define the S0_SSR and defined the S0_CR twice.
If this is not the case, try the read ID register and tell me about the result.

Thank you for your answer!!!

Just made a mistake when I copying!
In my code:

#define S0_SSR 0x0208

And ID register: 0x5300

It looks like there is no problem.
When CR is set and command execution is completed, the CR register is cleared.
Please also check this out.

You are right, the CR register is cleared!
But according to the instruction from the datasheet:

/* sets MAC raw mode /
S0_MR = 0x04;
sets OPEN command /
wait until Sn_SSR is changed to SOCK_MACRAW */

Sorry, but I still could not run the W5300! Data does not arrive, register S0_RX_RSR2 is clean. Can anyone help me?

For data to arrive, you must

  • ensure that chip is reset properly;
  • ensure that you configure chip properly - at least MAC address;
  • ensure there’re any packets on the interface to be captured by W5300.

I wrote above that ping is working, here’s the code:

void main(void) {
// Hardware reset
delay_us(10); //delay 10 us
delay_us (100); //delay 100us

WriteReg (SHAR, 0x0008);
WriteReg (SHAR2, 0xDC11);
WriteReg (SHAR4, 0x0203);
//IP-addr GAW:
WriteReg (GAR, 0x0A0A);  
WriteReg (GAR2, 0x1401); 
WriteReg (SUBR, 0xFFFF);
WriteReg (SUBR2, 0xFF00);
// IP-addr W5300:
WriteReg (SIPR, 0x0A0A);  
WriteReg (SIPR2, 0x1450); 

#if 1
while (1) {}
WriteReg(S0_MR, 0x0004); /* sets MACRAW mode *
WriteReg(S0_CR, 0x0001); /* sets OPEN command */
temp1 = ReadReg(S0_SSR);
} while(temp1 != 0x0042);



It may mean that W5300 initialized successfully.

However if your application is not startup timing critical, increase this delay to 2 ms as per datasheet.

These settings are not required in for MACRAW mode because they make no sense. They make sense if you use other sockets for IPRAW/TCP/UDP communication.

This algorithm actually is not correct, even if it present in the datasheets for all W5x00 products. The right one is:

    WriteReg(S0_MR, 0x0004); /* sets MACRAW mode *
    WriteReg(S0_CR, 0x0001); /* sets OPEN command */
    while(ReadReg(S0_CR));    /* waits until W5x00 completes command */
} while(ReadReg(S0_SSR) != 0x0042);

I removed temp1 from the code, you may still keep it for debugging purposes. You also must implement some timeout scheme so that code does not stuck in case of something goes wrong.

In MACRAW mode chip will receive only packets dedicated for its configured MAC address, and (I guess) MAC broadcast packets (with destination MAC address of FF:FF:FF:FF:FF:FF).
You can see what is going on the network using Wireshark (e.g. installing it on bridge computer), and only then state that W5300 does not get any packets and there’s an issue with W5300 or its configuration. When you ping W5300, I think these ICMP packets are intercepted before socket stack and they will not appear in any socket RX buffer.
It may also happen that you address wrong register to receive RX data size. Not possible to know because you do not detail code MACRAW_session(); you have issue in.

Thank you very much for your answers!

I increased the delay to 2 - 10 ms, but it did not help. I checked with an oscilloscope.

I tried your algorithm, but it also did not bring me success.

I also tried the UDP protocol, but it did not work either!

Full program code in the application.
main.zip (2,9 КБ)

You must explain how it did not work.


Are you sure your code is not stuck here - that sysinit does not return with 0?

void Resive_UDP_pocket (void)

I do not see code of this routine doing things required in datasheet:

Received DATA?
First method :
if (Sn_IR(RECV) == ‘1’) Sn_IR(RECV) = ‘1’; goto Receiving Process stage;
/* In this case, if the interrupt of SOCKETn is activated, interrupt occurs. Refer to IR, IMR
Sn_IMR and Sn_IR. */
Second Method :
if (Sn_RX_RSR != 0x00000000) goto Receiving Process stage;

Allocating 8 kilobytes of memory for each socket. I did this only for the sake of verification, since I understand that after reset the memory will be distributed in a similar way!

This function is performed correctly! (1)

The program does not reach the function Resive_UDP_pocket() and so I did not understand it yet, because I see that there is no response about setting the desired mode in the register S0_SSR!

Thanks again for your help!