Sn_IR multiple '1' bits at the same time

Hello
I use w5500 to have connection with PLC in modbus tcp/ip protocol , we have 10 boards that has w5500 and one PLC and PLC is TCP Client and 10 boards are TCP Server , In our 10 boards we have some data that should read by PLC and I use Socket 0 of w5500

  • PLC executes this algorithm :: Send “Connect” Command to board #1 then send “Receive” Command and then send “Disconnect” command after that Send “Connect” Command to board #2 then “Receive” Command and then send “Disconnect” command after that #3 #4#10
  • MCU executes this algorithm :: at the first go to Listen mode to accept the connection request and sensitive to Falling edge INT pin to detect “connect receive disconnect” Commands from PLC
    for this MCU algorithm I set S0_IMR to 0x07 and when I have interrupt I read the S0_IR to detect type of command , my problem is sometime the value of S0_IR is 0x06 or 0x05 or some value that has multiple ‘1’ !! and I don’t know why the reason of this
    after I read S0_IR I write 0x07 to this register to clear interrupt bits but I think at the one time S0_IR should has one bit as ‘1’
    Please help

Absolutely not. Each bit indicates event which happened in the past after you cleared flags last time.

thank you for reply
When PLC send “Disconnect” command to w5500 , Should I send disconnect command to W5500 by MCU Sn_CR (0x08) ?

Look at the W5100 datasheet chapter 5. It is best practice to send disconnect packet before closing the socket, the difference may be in the need to wait for response to discon (client mode) or not wait and proceed closing the socket after the discon command is accepted (for server mode). In this case W5500 is a server thus just send discon and close the socket with subsequent reopen into listen mode.

thank you
I make PLC code smaller for one board and PLC send connect command then receive and then disconnect command , in this status , sometimes when I read Sn_IR value , it equals to 0x05
it means connect & receive at the same time
do you have any idea for this event ?

It means W5500 has been connected and has received something.

what can I do to prevent multiple ‘1’ at the same time ?

You think in wrong direction. You can do nothing to “prevent” it. If you have specific flags set, your software must act accordingly (or knowingly not act). These flags are for information for your application, it is your choice to use them for something or just reset them if you are not going to use them.

thank you for quick reply
In PLC code , should I insert any delay between commands to give time to w5500 for processing command in hardware layer , for example between connect and receive command ? or between receive and disconnect ? or between disconnect and next connect ??

No, you do not need any delay if chapter 5 of W5100 datasheet does not state so. As I know there’s nothing about delays as is, the important loop is to wait for CR to zero after you issued any command into it. Again, these status bits show you (you software) what have happened in the past since you cleared these bits last time. They are status bits, and unless your network/socket access algorithm explicitly does something extra to flow explained in chapter 5, then there may be a need to wait for specific condition bit.

should I initial INTLEVEL register any value or default value is OK ??

What is your use case to change the value from default 0?

I think when we read S0_IR value and the value is 0x05 or 0x06 , the reason is w5500 doesn’t lowered INT pin as soon as possible , I read datasheet of w5500 page 34 (description of INTLEVEL register) , I think w5500 has some delay to falling edge of INT pin in multiple interrupt status

You again think in wrong direction.
I see that you have real problem with more than one bit being set in the socket interrupt register.
Before searching for black cat in dark room, can you please explain WHY having more than one bit set in this register is such a problem? Why you can’t process two bits at a single interrupt time? Do you really need ideal “real-time” interrupt at the time specific time it happens? 0x05 means that connection has been established and some data had been received, and it is overall system performance issue that it has read Sn_IR after both events have happened. 0x06 means data had been received, and remote node has already sent discon packet. Does it anyhow impact your data workflow?

OK thank you
I want to explain about MCU reaction depends on type of PLC command , please verify

  • 0x01 → Connect : I do nothing
  • 0x02 → Disconnect : I send “Disconnect” command to w5500 with S0_CR (0x08)
  • 0x04 → Receive : I send some data to plc according to register address
  • 0x05 → I think I should do the same as 0x04
  • 0x06 → I think I should do the same as 0x04
  • 0x07 → I don’t what should I do ?
    sometimes we have 0x07 value in my tests

thanks a lot dear

This is bitmap register. It means you must act not basing on the overall register value, but on the value of each individual bit.

bit 0 set means connect has happened. do you need to do anything about it? (edit: probably yes - if someone connected to you but did not send data within specific time you may consider communication broken and reset it - but it is kind of advanced behavior, try making without this at the first step)
bit 1 set means disconnect has been received. send discon, close socket, reopen it and return back to listen state
bit 2 set means some data had been received. go get it from the buffer and work on it
bit 3 set means some error happened. start error processing
bit 4 set means the data you asked socket to send had been actually sent. do you need to do anything on it?

thank so much for individual ‘1’ bits
please guide me about reaction for multiple ‘1’

  • bit 0 and bit 2 together (0x05) ?
  • bit 1 and bit 2 together (0x06) ?
  • bit 0 and bit 1 and bit 2 together (0x07) ?

correct.

I have another question
I added reaction to my code and it works very well and very fast without delay , thank you so much
When I connect 1 board to PLC , " Connect Receive Disconnect " works very well and all thing is OK
but when I connect other board to my switch and all 10 boards is connected to network , these commands is not working good in w5500, especially response to Connect command
Is there any impact together when all w5500 IC is networked ??

When you start talking about more than one board using same firmware/software, first thing is to check if all of them are having unique MAC addresses (and then IP addresses).