WIZnet Developer Forum

W5500 stops to respond to ICMP after writing MSS register

Hi

I’m in the process of writing some code for the W5500. Currently, I’m facing the issue that as soon as I start to set the MSS the chip stops to respond to ICMP. Is this normal?

My code:

void w5500_read_data(uint16_t offset, uint8_t block, unsigned char *data_out, int length) {
    unsigned char *buffer = malloc(3 + length);
    
    buffer[0] = offset >> 8;
    buffer[1] = offset & 0xFF;
    buffer[2] = (block&0xF8) << 3;

    SpiOpenPort(0);
    SpiWriteAndRead(0, buffer, buffer, 3 + length, 0);
    SpiClosePort(0);

    memcpy(data_out, buffer + 3, length);
}

void w5500_write_data(uint16_t offset, uint8_t block, unsigned char *data, int length) {
    unsigned char *buffer = malloc(3 + length);

    buffer[0] = offset >> 8;
    buffer[1] = offset & 0xFF;
    buffer[2] = (block&0xF8) << 3;
    buffer[2] |= 0x04;

    memcpy(buffer + 3, data, length);

    SpiOpenPort(0);
    SpiWriteAndRead(0, buffer, buffer, 3 + length, 0);
    SpiClosePort(0);
}

void w5500_init(void) {
    unsigned char buffer0[1];

    // SW Reset
    buffer0[0] = 0x80;
    w5500_write_data(0x0000, 0x00, buffer0, 1);

    usleep(100 * 1000);
    
    w5500_read_data(0x0039, 0x00, buffer0, 1);

    if(buffer0[0] == 0x04) {
        printf("Detected Chip W5500! \n");
    } else {
        exit(1);
    }
}

void w5500_configure_ip(void) {
    unsigned char buffer0[6];

    // Write Gateway IP Address Register
    buffer0[0] = 172;
    buffer0[1] = 16;
    buffer0[2] = 90;
    buffer0[3] = 1;
    w5500_write_data(0x0001, 0x00, buffer0, 4);

    // Write Subnet Mask Register
    buffer0[0] = 255;
    buffer0[1] = 255;
    buffer0[2] = 255;
    buffer0[3] = 0;
    w5500_write_data(0x0005, 0x00, buffer0, 4);

    // Write Source Hardware Address Register
    buffer0[0] = 0x00;
    buffer0[1] = 0xAA;
    buffer0[2] = 0xBB;
    buffer0[3] = 0xCC;
    buffer0[4] = 0xDE;
    buffer0[5] = 0x02;
    w5500_write_data(0x0009, 0x00, buffer0, 6);

    // Write Source IP Address Register
    buffer0[0] = 172;
    buffer0[1] = 16;
    buffer0[2] = 90;
    buffer0[3] = 150;
    w5500_write_data(0x000f, 0x00, buffer0, 4);
}

void w5500_configure_socket(void) {
    unsigned char buffer0[2];

    // Write Socket n Maximum Segment Size Register - 1460
    buffer0[0] = 0x05;
    buffer0[1] = 0xB4;
    w5500_write_data(0x0012, 0x01, buffer0, 2);

    // Write Socket n Source Port - 5000
    buffer0[0] = 0x13;
    buffer0[1] = 0x88;
    w5500_write_data(0x0004, 0x01, buffer0, 2);
}

void w5500_connect_socket(void) {

}

int main(void) {
    w5500_init();
    w5500_configure_ip();

    w5500_configure_socket();
    //w5500_connect_socket();
}

Ok… Layer8 issue… buffer[2] = (block&0xF8) << 3; should be buffer[2] = (block&0x1F) << 3;

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