WIZnet Developer Forum

ATMEGA164P + Wiznet W5500 Development module PING Issue

ello Everyone

I have an ATMEGA164P brd to which I am trying to connect Ethernet Wiz Click W5500 Development Board (https://www.digikey.com/product-detail/en/mikroelektronika/MIKROE-1718/1471-1413-ND/5258596). I am not able to get the PING working.
The connections between the two boards are as follows

Atmega164P ----- ETH CLICK Brd
MOSI ------------- SDI
MISO ------------- SDO
SCLK -------------- SCK
CS (PORTB.4) ------ CS
PORTB.3 ---------- RST

I cannot get the ping working. On the development board LINK STAT LED glows showing LINK is established but CRS LED blinks GREEN at times.
I use BASCOM AVR for coding. This is my 1st post I don’t know if there is a special way to post code.

$regfile = "M164pdef.dat"
$crystal = 3686400
$baud = 57600

$hwstack = 80
$swstack = 80
$framesize = 80

Config Serialin = Buffered , Size = 8


Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 4 , Noss = 0
Spiinit

Config Pinb.3 = Output
Config Portb.4 = Output
W5500_nreset Alias Portb.3
Wiz5500_cs Alias Portb.4


'Common registers
'Mode register
Const W5500_mr = &H0000
'Gateway address registers
Const W5500_gar0 = &H0001
Const W5500_gar1 = &H0002
Const W5500_gar2 = &H0003
Const W5500_gar3 = &H0004
'Subnet mask Address registers
Const W5500_subr0 = &H0005
Const W5500_subr1 = &H0006
Const W5500_subr2 = &H0007
Const W5500_subr3 = &H0008
'Source Hardware Address registers
Const W5500_shar0 = &H0009
Const W5500_shar1 = &H000A
Const W5500_shar2 = &H000B
Const W5500_shar3 = &H000C
Const W5500_shar4 = &H000D
Const W5500_shar5 = &H000E
'Source IP Address registers
Const W5500_sipr0 = &H000F
Const W5500_sipr1 = &H0010
Const W5500_sipr2 = &H0011
Const W5500_sipr3 = &H0012

Dim Value As Byte
Dim Adres As Word
Dim Adresl As Byte At Adres Overlay
Dim Adresh As Byte At Adres + 1 Overlay

Dim Wiz5500_opcode_read As Byte
Wiz5500_opcode_read = &H00
Dim Wiz5500_opcode_write As Byte
Wiz5500_opcode_write = &H04


Declare Sub Wiz5500_writevalue(byval Reg As Word , Byval Value As Byte)
Declare Sub Wiz5500_reset


Enable Interrupts


Call Wiz5500_reset                                          'Hardware reset
'Register reset


Call Wiz5500_writevalue(w5500_mr , &H80)

'Set Gateway Ip Address                                     ' 192.168.1.1
Call Wiz5500_writevalue(w5500_gar0 , &HC0)
Call Wiz5500_writevalue(w5500_gar1 , &HA8)
Call Wiz5500_writevalue(w5500_gar2 , &H01)
Call Wiz5500_writevalue(w5500_gar3 , &H01)

'Set Subnet mask
Call Wiz5500_writevalue(w5500_subr0 , &HFF)                 '255.255.255.0
Call Wiz5500_writevalue(w5500_subr1 , &HFF)
Call Wiz5500_writevalue(w5500_subr2 , &HFF)
Call Wiz5500_writevalue(w5500_subr3 , &H00)

'Set MAC
Call Wiz5500_writevalue(w5500_shar0 , &H00)
Call Wiz5500_writevalue(w5500_shar1 , &H08)
Call Wiz5500_writevalue(w5500_shar2 , &HDC)
Call Wiz5500_writevalue(w5500_shar3 , &H01)
Call Wiz5500_writevalue(w5500_shar4 , &H02)
Call Wiz5500_writevalue(w5500_shar5 , &H03)

'Set own IP address
Call Wiz5500_writevalue(w5500_sipr0 , &HC0)                 '192.168.1.200
Call Wiz5500_writevalue(w5500_sipr1 , &HA8)
Call Wiz5500_writevalue(w5500_sipr2 , &H01)
Call Wiz5500_writevalue(w5500_sipr3 , &HC8)


 Do
 Loop


Sub Wiz5500_writevalue(reg , Value )
Adres = Reg
Reset Wiz5500_cs
Spiout Adresh , 1
Spiout Adresl , 1
Spiout Wiz5500_opcode_write , 1
Spiout Value , 1
Set Wiz5500_cs
End Sub

Sub Wiz5500_reset
W5500_nreset = 1
Waitms 10
W5500_nreset = 0
Waitms 300                                                  'Minimum 20 Β΅s
W5500_nreset = 1
End Sub

After performing soft reset you must read MR in loop checking its bit 7 to become 0. You can continue with GAR only after you ensured MR’s bit 7 is reset, otherwise you may β€œwrite” to the chip while it is in reset mode, thus not setting registers properly.

width=β€œ690” height=β€œ414”>

Hello

I am trying to read the MR register. Here is the issue.

I have uploaded the pics
pic 1.
MOSI (blue) and SCLK (yellow) - the waveform is for writing to MR register. As seen the MOSI line send &H00, &H00, &H04, &H80

pic2.
CS(blue) SCLK (yellow)- It shows the chip select is low when SCLK is present

pic3.
MISO (blue) and SCLK (yellow)- the problem is the MISO line always shows this weird waveform whether I am reading or writing to the registers.

pic4
MOSI (blue) SCLK (yellow)- this is what I send to read the MR register. MOSI line send data correctly &H00, &H00, &H00, &H80 (dummy data)

The MISO line is not responding. That means the w5500 registers are not updating.

Any recommendation. Please help

Looks like pic 2 didn’t upload

CS & SCLK

hello, allsetgo

In W5500, you must set CS low during SPI Frame.

Never set CS low and high each byte in SPI Frame.

  1. set CS Low
  2. Addr H
  3. Addr L
  4. OP
  5. Data
  6. set CS High

If CS goes high during SPI frame, It is reset.

Thank you

lawrence

Thanks Lawrence

The PING works. I will get in touch if I have problem with setting up the TCP

Glad to hear that!!

Sure! anything you want, feel free to ask!

Thank you,

Lawrence

1 Like

Hi Lawrence

Here is my issue with setting up the TCP. I am using W5500 in TCP server mode.
Here is the sequence in addition to above code.
My PING IS working i.e. my module is part of the network.

I am using SOCKET0
Start

  1. Write Sn_MR = 0x01
  2. Set Socket0 Port = 80
  3. Set SIMR = 0x01
  4. Set S0_CR= 0x01 (OPEN)
  5. Read Value of Sn_SR
  6. If Sn_SR=&H13 (SOCKET INITIALIZED) ELSE CLOSE SOCKET AND GOTO START
  7. Once Initialized Write Sn_CR= 0x02 (LISTEN)
  8. Read Value of Sn_SR
  9. If Sn_SR=&H14 (SOCKET In Listen Mode) ELSE CLOSE SOCKET AND GOTO START
  10. Once Socket is in Listen Mode I read value of Sn_SR to see if it has changed to 0x17 (Established ) Else keep checking it till it goes in Established Mode

The Initialize and LISTEN mode works well. But I am not able to ESTABLISH a connection. My Sn_SR stays in Listen Mode.

Can you help me in how to send connection request from Client.
All I do is open my Mozilla browser and type the Ethernet Module IP that I have set 192.168.1.200
It says unable to Connect

Also, how does the Socket Port plays role here. If I set it to 5000, how should I sent request to connect to 192.168.1.200 over port 5000 in my browser.

Hello, allsetgo

I want to know about 2 things.

First,
In TCP connection from web browser, you do not need to do anything because PC will do connect automatically.
But, you have to add PC network address β€œ192.168.1.x” in Ethernet Adapter.

Second,
The network condition. Do you connect W5500 and PC directly or though hub or switch?
In both case, you should catch the packet with wireshark.
wireshark is open tool and it will show you the connection packet.
If you feel hard to use it, please let me know. I will guide you.

At the end,
If you connect β€œ192.168.1.200” β€œport=500” in browser, you must type β€œ192.168.1.200:5000” in browser.

Thank you

lawrence

Hi Lawrence

Thanks again. I connect W5500 module and PC via a hub. As you recommended
typing β€œ192.168.1.200:5000” established the connection.
I am trying to perform a read operation now on W5500 module.
I read the size of the data sent which turns out to be correct. i.e reading
RSn_RX_RSR
Next I read my Sn_RX_RD for socket 0 i.e (offset addr = [0x0028}, Control
= &H08)
this reads out to be 0

My question is how should I read the RX buffer
Since Sn_RX_RD=0 my start address for socket 0 RX buffer is 0x0000 ?
now if I perform a read from address 0x0000 and read the no of bytes as per
the size I received RSn_RX_RSR gives me wrong data.
i.e. I set addr=[0x0000], control=[0x18]

I have never used wireshark before. Any help would be great.

hello, allsetgo

Sn_RX_RD is not automatically updated with new pointer value.

After read the RX buffer, user must write Sn_RX_RD with the data size user read from buffer.

And do Sn_CR[RECV]. Then Sn_RX_RD value changed.

When user want to read data from RX buffer, easy way is using ioLibrary, especaily, β€œint32_t recv ()” function in ioLibrary

I am not sure about how you program it.

But I recommand to use iolbrary. it is way easier.

https://github.com/Wiznet/ioLibrary_Driver (download link).

please refer the recv() in socket.c in Ethernet folder in ioLibrary

And also in W5500 datasheet, Figure12,13 and Figure20, there is the physical memory address for accessing.

To read RX memory, user must directly access to physical memory and read it.

If I tell you whole receiving processor at here, it will make more confusing you.

Please refer the ioLibrary -> Ethernet -> socket.c / w5500

And also anything feel free to ask

Thank you

lawrence

Hi Lawrence

I am using W5500 development brd with my custom ATMEGA164P board. I use BASCOM AVR for coding.

I was able to read the data correctly and the no. of bytes sent.

I now need help with Sending data. When I read Sn_TX_RD it reads different values all the time

Call Wiz5500_readvalue_16bit(sock_tx_fsr , &H08)
Print Hex(read_val_16h) ; ":" ; Hex(read_val_16l)  ' Reads 0x0800

Call Wiz5500_readvalue_16bit(sock_tx_RD , &H08)
Print Hex(read_val_16h) ; ":" ; Hex(read_val_16l)  '  Reads random data such as 0x8368 and keeps changing even if I do not issue the send command

Call Wiz5500_readvalue_16bit(sock_tx_WR , &H08)
Print Hex(read_val_16h) ; ":" ; Hex(read_val_16l)  '  Reads same value as Sn_TX_RD

Call Wiz5500_writevalue_socket(Addr , &H14 , Data)    ' here addr I used was same as what I read from Sn_TX_RD i.e 0x8368

Call Wiz5500_writevalue_socket(w5500_cr , &H0C , &H20)   ' Sn_CR= SEND 

Do 
Loop

Sub Wiz5500_readvalue_16bit(reg , Value)
Adres = Reg
Reset Wiz5500_cs
Spiout Adresh , 1
Spiout Adresl , 1
Spiout Value , 1
Spiin Read_val_16h , 1
Spiin Read_val_16l , 1
Set Wiz5500_cs
End Sub

Sub Wiz5500_writevalue_socket(reg , Value1 , Value2 )
Adres = Reg
Reset Wiz5500_cs
Spiout Adresh , 1
Spiout Adresl , 1
Spiout Value1 , 1
Spiout Value2 , 1
Set Wiz5500_cs
End Sub

Hi Lawrence

I am using W5500 development brd with my custom ATMEGA164P board. I use
BASCOM AVR for coding.

I was able to read the data correctly and the no. of bytes sent.

I now need help with Sending data. When I read Sn_TX_RD it reads different
values all the time

Call Wiz5500_readvalue_16bit(sock_tx_fsr , &H08)
Print Hex(read_val_16h) ; β€œ:” ; Hex(read_val_16l) ’ Reads 0x0800
Call Wiz5500_readvalue_16bit(sock_tx_RD , &H08)
Print Hex(read_val_16h) ; β€œ:” ; Hex(read_val_16l) ’ Reads random
data such as 0x8368 and keeps changing even if I do not issue the send
command
Call Wiz5500_readvalue_16bit(sock_tx_WR , &H08)
Print Hex(read_val_16h) ; β€œ:” ; Hex(read_val_16l) ’ Reads same value
as Sn_TX_RD
Call Wiz5500_writevalue_socket(Addr , &H14 , Data) ’ here addr I
used was same as what I read from Sn_TX_RD i.e 0x8368

Call Wiz5500_writevalue_socket(w5500_cr , &H0C , &H20) ’ Sn_CR= SEND
Do Loop

Sub Wiz5500_readvalue_16bit(reg , Value)
Adres = RegReset Wiz5500_cs
Spiout Adresh , 1
Spiout Adresl , 1
Spiout Value , 1
Spiin Read_val_16h , 1
Spiin Read_val_16l , 1Set Wiz5500_csEnd Sub

Sub Wiz5500_writevalue_socket(reg , Value1 , Value2 )
Adres = RegReset Wiz5500_cs
Spiout Adresh , 1
Spiout Adresl , 1
Spiout Value1 , 1
Spiout Value2 , 1Set Wiz5500_csEnd Sub

Hi Lawrence

I tried using the Socket 1 Tx Buffer to send data. I am still not able to.
no packet is seen on wireshark.

Call Wiz5500_readvalue_16bit(sock_tx_fsr , &H28) ’ &H28
is control byte , I receive output as 0x0800

Call Wiz5500_readvalue_16bit(sock_tx_pointer , &H28) ’ &H28
is control byte, I receive data as 0x0000

Call Wiz5500_writevalue_socket(start_addr_tx , &H34 , &H09) *'
start_addr_tx = 0x0000 (as received from S1_RD ), &H34 is control byte,
&H09 is data value. sending only 1 data *
Call Wiz5500_writevalue_socket(w5500_cr , &H2C , &H20) * ’ &H2C is
control byte, S1_CR=SEND *

Please let me know what I am missing.

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