I’m trying to create TCP-client with using W5500 and ATmega328P. Now I can configurate chip (send data from atmega to w5500 via SPI) and it connect with server building at TCPIP builder. But I can’t read information (chip version, ip, status) from W5500.
For example there you can see diagram when I write CONNECT command in S0_CR, and it work fine:
I have already tried to change SPI mode to 0,2 and 3 according with this table, but nothing change:
And I have tried to do handle RESET for chip before initialization (RST pin → HIGH, RST pin → LOW, delay, RST pin → HIGH), but in this case SPI don’t function
Thanks for answer!
I just don’t know what I should to do after sending control phase byte. Is it correct that after writing 0 in R/W byte W5500 just send data on MISO?
I’m using this function for reading data from chip:
As you can see from diagrams I can send correct address bytes and control phase byte, but after it CLK signal stop. I have tried to wait before deselect W5500 and in this case there isn’t signal on CLK line.
is having problems. This code is intended to get 8 bits of data into buf[3], but for some reason it does nothing,
Edit: I am not originally familiar with how ot works, but according to this source
SPDR = (uint8_t)((addrbsb & 0x00FF0000)>>16); // load the Address byte 1 to be transmitted
Byte = (uint8_t)((addrbsb & 0x0000FF00)>> 8); // pre-load the Address byte 2 to be transmitted
while ( !(SPSR & _BV(SPIF)) );
SPDR = Byte; // load the Address byte 2 to be transmitted
Byte = (uint8_t)(addrbsb & 0x000000F8); // pre-load the Data Read command
while ( !(SPSR & _BV(SPIF)) );
SPDR = Byte; // load the Data Read command
Byte = 0x5A; // pre-load a dummy byte to be transmitted
while ( !(SPSR & _BV(SPIF)) );
SPDR = Byte; // load a dummy byte to be transmitted
while ( !(SPSR & _BV(SPIF)) );
Byte = SPDR; // copy received byte in case we get swapped out, and lose SPDR.
portEXIT_CRITICAL();
spiDeselect(Wiznet); // CS=1, SPI end, give semaphore
WIZCHIP_ISR_ENABLE();
return Byte;
you must perform the dummy byte write to SPDR (which value does not matter for reading the data) and obtain read data from the same register SPDR. Thus your mistake that you omit writing to SPDR.