W5500 Ethernet driver

lib/drivers/w5500.nbl provides register and socket access for a Wiznet W5500 over SPI.

import "lib/boards/voja4.nbl";
import "lib/spi.nbl";
import "lib/drivers/w5500.nbl";

Call spi_init() before using the driver. Pin constants are in Board constants.

Register access

Block-select values are 0 for common registers and 3n+1, 3n+2, 3n+3 for socket n register, TX, and RX blocks. The generic helpers take a 4-bit BSB, which covers socket 0. Use w5500_set_tx_size for sockets whose register block is above 15.

Functions

Call

Returns

Notes

w5500_reset()

void

Drive RST low, delay, then release it high

w5500_read(bsb, addr_hi, addr_lo)

char

Read one register byte

w5500_write(bsb, addr_hi, addr_lo, value)

void

Write one register byte

w5500_read16(bsb, addr_hi, addr_lo)

uint16_t

Read a 16-bit big-endian register

w5500_write16(bsb, addr_hi, addr_lo, value)

void

Write a 16-bit big-endian register

w5500_version()

char

Read VERSIONR

w5500_phy()

char

Read PHYCFGR; bit 0 is link status

w5500_set_tx_size(socket, size)

void

Set a socket’s TX buffer size in KB

w5500_open_udp(port_hi, port_lo)

void

Open socket 0 as UDP

w5500_open_tcp(port_hi, port_lo)

void

Open socket 0 as a TCP listener

w5500_send_flash(msg)

nibble

Send a flash string; returns 0 when the TX buffer has no room

w5500_rx_available()

uint16_t

Bytes waiting in socket 0 RX

w5500_rx_pointer()

uint16_t

Read Sn_RX_RD

w5500_rx_peek(offset)

char

Read one byte without consuming it

w5500_rx_consume(count)

void

Advance Sn_RX_RD and issue RECV

w5500_tx_free()

uint16_t

Free bytes in socket 0 TX

w5500_tx_pointer()

uint16_t

Read Sn_TX_WR

w5500_tx_set_pointer(pointer)

void

Write Sn_TX_WR

w5500_tx_stream_begin(addr_hi, addr_lo)

void

Start a TX buffer write burst

w5500_rx_stream_begin(addr_hi, addr_lo)

void

Start an RX buffer read burst

w5500_stream_end()

void

Release CS after a burst

w5500_send_command()

void

Issue and wait for SEND

w5500_discard_rx()

void

Read and discard up to 200 received bytes

w5500_tx_pointer() is implemented in lib/drivers/asm/w5500.asm and declared with extern fn. See Imported assembly modules.