WIZnet Developer Forum

One byte transfer in burst mode

Hi.
I’m working on app, which utilizes SPI in DMA mode for communication between STM32F030K6 and Wiz850. I have registered the following functions:

reg_wizchip_cs_cbfunc(SPI_Soft_nSS_On, SPI_Soft_nSS_Off);
reg_wizchip_spiburst_cbfunc( SPI_DMA_Rx_Burst, SPI_DMA_Tx_Burst);

Program works fine till the moment I try to use wizchip_getnetinfo() function. For some reason it calls WIZCHIP_READ function (what I believe it shouldn’t do if I registered SPI burst functions).

uint8_t WIZCHIP_READ(uint32_t AddrSel)
{
uint8_t ret;
uint8_t spi_data[3];

WIZCHIP_CRITICAL_ENTER();
WIZCHIP.CS._select();

AddrSel |= (W5500_SPI_READ | W5500_SPI_VDM_OP);

if(!WIZCHIP.IF.SPI._read_burst || !WIZCHIP.IF.SPI._write_burst) // byte operation
{
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF0000) >> 16);
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x0000FF00) >> 8);
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x000000FF) >> 0);
//ret = WIZCHIP.IF.SPI._read_byte();
}
else // burst operation
{
spi_data[0] = (AddrSel & 0x00FF0000) >> 16;
spi_data[1] = (AddrSel & 0x0000FF00) >> 8;
spi_data[2] = (AddrSel & 0x000000FF) >> 0;
WIZCHIP.IF.SPI._write_burst(spi_data, 3);
}
ret = WIZCHIP.IF.SPI._read_byte();
WIZCHIP.CS._deselect();
WIZCHIP_CRITICAL_EXIT();
return ret;
}

As far as I can see, it has an option for burst as well, but it does not return anything (since it reading byte to be returned) and just keep writing three bytes: 0x00 0x01 0x08

I tried to modify burst part to write/read four bytes and return one as following:

uint8_t WIZCHIP_READ(uint32_t AddrSel) //This function is altered for SPI Burst operations
{
uint8_t ret;
//uint8_t spi_data[3];
uint8_t spi_data[4];

WIZCHIP_CRITICAL_ENTER();
WIZCHIP.CS._select();

AddrSel |= (W5500_SPI_READ | W5500_SPI_VDM_OP);

if(!WIZCHIP.IF.SPI._read_burst || !WIZCHIP.IF.SPI._write_burst) // byte operation
{
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF0000) >> 16);
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x0000FF00) >> 8);
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x000000FF) >> 0);
ret = WIZCHIP.IF.SPI._read_byte();
}
else // burst operation
{
spi_data[0] = (AddrSel & 0x00FF0000) >> 16;
spi_data[1] = (AddrSel & 0x0000FF00) >> 8;
spi_data[2] = (AddrSel & 0x000000FF) >> 0;
WIZCHIP.IF.SPI._read_burst(spi_data, 4);
ret = spi_data[3];
}
//ret = WIZCHIP.IF.SPI._read_byte();
WIZCHIP.CS._deselect();
WIZCHIP_CRITICAL_EXIT();
return ret;
}

In this case I can have two UDP sockets open, but if I try to send out some data, using sendto() in main cycle, it returns SOCKERR_TIMEOUT for first time and SOCKERR_IPINVALID for all attemts after that.

First, I wonder why WIZCHIP_READ is called if I haven’t registered reg_wizchip_spi_cbfunc(), and second if this function has burst operation section, how it is supposed to be returning value?

Any ideas?

Hello,


Please refer to the link above.
This code is to control WIZnet CHIP through DMA communication using STM32F103.
Considering that a Socket INVALID ERROR occurs, your code does not seem to send or receive data properly.

Hi Becky.

Thanks for help.

My code modification is right in this example. There was a hardware issue. Now it is solved.
I managed to get it working with variant I have suggested:

uint8_t WIZCHIP_READ(uint32_t AddrSel) //This function is altered for SPI Burst operations
{
uint8_t ret;
uint8_t spi_data[4];

WIZCHIP_CRITICAL_ENTER();
WIZCHIP.CS._select();

AddrSel |= ( W5500_SPI_READ | W5500_SPI_VDM_OP );

if(!WIZCHIP.IF.SPI._read_burst || !WIZCHIP.IF.SPI._write_burst) // byte operation
{
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF0000) >> 16);
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x0000FF00) >> 8);
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x000000FF) >> 0);
ret = WIZCHIP.IF.SPI._read_byte();
}
else // burst operation
{
spi_data[0] = (AddrSel & 0x00FF0000) >> 16;
spi_data[1] = (AddrSel & 0x0000FF00) >> 8;
spi_data[2] = (AddrSel & 0x000000FF) >> 0;
WIZCHIP.IF.SPI._read_burst(spi_data, 4);
ret = spi_data[3];
}
WIZCHIP.CS._deselect();
WIZCHIP_CRITICAL_EXIT();
return ret;
}

There is a little advantage in speed, as there is no gap between address + control bytes and receiving data byte.
Besides this I do not need to register reg_wizchip_spi_cbfunc. The only functions I have to register are reg_wizchip_cs_cbfunc and reg_wizchip_spiburst_cbfunc.

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