WIZnet Developer Forum

W5500 Variable SPI mode not working

Hi,

I am trying to read back the register i have written. But when i write the value in variable length or fixed length 1 byte mode, i am reading some thing else.

But It is proper for the both 2,4 fixed length modes.

Here is the code:

#include "Wizchip_Conf.h"
#include "W5500.h"
#include "Socket.h"

// ETH WIZ click connections
sbit Wizchip_Rst at LATE1_bit;
sbit Wizchip_CS  at LATE0_bit;
sbit Wizchip_Rst_Direction at TRISE1_bit;
sbit Wizchip_CS_Direction  at TRISE0_bit;
// end of ETH WIZ click connections

// brief Call back function for WIZCHIP select.
void CB_ChipSelect(void)
{
    Wizchip_CS = 0;
}
// brief Call back function for WIZCHIP deselect.
void CB_ChipDeselect(void)
{
    Wizchip_CS = 1;
}
uint8_t i;
uint8_t val[6];

void main(){
    UART1_Init(9600);
    Wizchip_Rst_Direction = 0;
    Wizchip_CS_Direction = 0;
    
    SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV4, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
    
    CB_ChipSelect();
    SPI1_Write(0x00);
    SPI1_Write(0x09);
    SPI1_Write(0x04);
    SPI1_Write(0x0A);
    SPI1_Write(0x0B);
    SPI1_Write(0x0C);
    SPI1_Write(0x0D);
    SPI1_Write(0x0F);
    SPI1_Write(0x0E);
    CB_ChipDeselect();
    
    CB_ChipSelect();
    SPI1_Write(0x00);
    SPI1_Write(0x09);
    SPI1_Write(0x00);
    for(i =0; i<6; i++){
       val[i] =SPI1_Read(0);
    }
    CB_ChipDeselect();
    for(i = 0; i<6; i++){
          UART1_Write(val[i]);
    }
}

Here are my results when i use each of the mode:

1 Byte: 0xD5 0x05 0x00 0x00 0x00 0x00
2 Byte:0xAA 0x0B 0x00 0x00 0x00 0x87
4 Byte: 0xAA 0x0B 0x0C 0x0D 0x00 0x87
variable length mode: 0x55 0x05 0x0C 0x0D 0x00 0x00

Hello,

  1. The above code appears to be written and read in variable mode on the SHAR register. Therefore, it is correct that the written value should be read.
    When you write “0x0A 0x0B 0x0C 0x0D 0x0E”, the Read value is 0x55 0x05 0x0C 0x0D 0x00 0x00?

  2. I want you to tell me more clearly what value you have written and what value you read.

3. Data length is fixed in fixed mode, like the above image. Is it correct to write data of the same size as data length after writing addr and control?

Hi Becky,

I have tried the spi communication in all the modes possible, the above results specific for the mode. I don’t get what your asking in the 3rd question, as far as i understood we can write 4bytes of data (without considering the addr and control byte) in the FDM_LEN4_ mod.

It is right that you understood.

Tell me again what your problem is.
I understand that you tried to write and read data in each mode, which worked well for fixed mode 2byte and 4byte but read the other values in the other modes.
So I asked if you were writing the appropriate size data for each mode.

In addition, I recommend that you verify that the mode settings are correct.
Please refer to datasheet 14-17page
http://wizwiki.net/wiki/lib/exe/fetch.php?media=products:w5500:w5500_ds_v108e.pdf

Thank you

Copyright © 2017 WIZnet Co., Ltd. All Rights Reserved.