SPI frame , as I understand it

SPI frame , as I understand it.
the ww5500 have collection of registers.
one action to read or Write “the chip” consists of 3 bytes. 2 bytes (16 bits) are the register we want to read or write (call me : Address Phase ) and one byte the collection of registers. in this byte the 5 high bits is the collection , bit 3 choose the read or write to . . . and bit 1,2 choose how many bytes we will read or write. if these bits are 0,0 this means that CS pin terminates the read or write proses. there are combinations to read or write 1,2,4 bytes. In my functions I use 0,0 and CS.
So, we have 1 collection with registers governing all the chip . eg ip , mask gateway etc (Common Registers) all other ““collections”” govern the sockets. (see datasheet page 15 2.2.2 Control phase bits [7:3] table)
example 1 for common register to read the 2nd number of the IP → 168
as we can see at Table 3. Offset Address for Common Register (call me address phase) the second ip number is at 0x0010 pseudo (SIPR1) . The “collection” (see page 15) is (binary) 00000 Selects Common Register. (5 bits) At these 5 bits we add 0 (bit 3 =read) 0 0 (bit 1,0 = CS controls how many bytes we will read) so the all the byte is (binary) 00000 0 00 (if we OR with 0x4 binary 00000 1 00 we will write into the register)
with MikroC SPI function we will sent 0x00 0x10 0x0 spi_write(0x0) spi_write(0x10) spi_write(0x0) and we read the content with theData=spi_read() (if we debug the theData will be : 168)
below are the functions for Microchip dsPic and MikroC (a gift to people who use microchip dspic and microC)

[code]//This function writes the data into W5500 Common registers.

void CommonRegister_WRITE(unsigned int CommonRegister, char TheData){
// CommonRegister represent the Offset Address at SPI frame , conrolPhase ==04 for commonreg W VDL
char i;
unsigned char ControlPhaseforWrite=0x4;
WizEnablePin = 0x0; Delay_us(2); // /SCS ACTIVE LOW begine frame
i=((CommonRegister & 0xFF00) >> 8);
SPI1_Write (i);
i= (CommonRegister & 0x00FF);
SPI1_Write(i);
SPI1_Write(ControlPhaseforWrite);
SPI1_Write( TheData);
WizEnablePin = 0x01; // /SCS end the SPI frame
delay_us(2);
}

//This function reads the value from W5500 Common registers.

char CommonRegister_READ(unsigned int CommonRegister){
//CommonRegister represent the Offset Address at SPI frame , conrolPhase ==00 for commonreg R VDL
char Thedata,i;
unsigned char ControlPhaseforRead=0x00; // variable data lenght
WizEnablePin=0; Delay_us(2); // /SCS ACTIVE LOW begin SPI frame
i=((CommonRegister & 0xFF00) >> 8);
SPI1_Write(i);
i=(CommonRegister & 0x00FF);
SPI1_Write(i);
SPI1_Write(ControlPhaseforRead);

       Thedata = SPI1_Read(i);                // read data
       WizEnablePin = 0x01;                   //  /SCS  end SPI frame
       delay_us(2);
    return Thedata;

}

[/code]

for socket

void SocketRegister_WRITE(unsigned int AddressPhase,unsigned char ControlPhase, char TheData){
//   CommonRegister represent the Offset Address at SPI frame , conrolPhase ==04  for commonreg W VDL
     char i;
unsigned char ControlPhaseforWrite;
           ControlPhaseforWrite= ControlPhase | 0x4;     // rise Rw bit
           WizEnablePin = 0x0; Delay_us(2);   // /SCS  ACTIVE LOW  begine frame
           i=((AddressPhase & 0xFF00) >> 8);
           SPI1_Write (i);
           i= (AddressPhase & 0x00FF);
           SPI1_Write(i);
           SPI1_Write(ControlPhaseforWrite);
           SPI1_Write( TheData);
           WizEnablePin = 0x01;             //  /SCS    end the SPI frame
           delay_us(2);
           
  }

//This function reads the value from W5500 Common registers.

char SocketRegister_READ(unsigned int AddressPhase,unsigned char DataPhase){
//CommonRegister represent the Offset Address at SPI frame , conrolPhase ==00  for commonreg R VDL
        char Thedata,i;
unsigned char ControlPhaseforRead;
           ControlPhaseforRead=DataPhase ;     // 000 [3:0] Read , variable data lenght
           WizEnablePin=0; Delay_us(2);        // /SCS   ACTIVE LOW   begin SPI frame
           i=((AddressPhase & 0xFF00) >> 8);
           SPI1_Write(i);
           i=(AddressPhase & 0x00FF);
           SPI1_Write(i);
           SPI1_Write(ControlPhaseforRead);

           Thedata = SPI1_Read(i);                // read data
           WizEnablePin = 0x01;                   //  /SCS  end SPI frame
           delay_us(2);

    //   UART_Write_Text("Address phase ");    IntToStr(AddressPhase,IntTxT);  UART_Write_Text(IntTxT); UART_Write_Text("   ");
    //   UART_Write_Text("Control phase ");    ByteToStr(ControlPhaseforRead,ByteTxt),  UART_Write_Text(ByteTxt);UART_Write_Text("   ");
    return Thedata;
}

Hi, minas!!

Thank you for your interesting in W5500 and the example driver of dsPic and MikroC.