What SDK are you using?
I am currently adapting the W5500 into a w80x-arduino-iot project. Closer to the new year I will publish how to use WizNet chips together with LWIP library.
@JiangXianSen Okay. I'm using this SDK as well
@JiangXianSen No.
I recently ported the uIP stack to HAL 0. 0. 6. with EnC28J60 support.
http: //ask. winnermicro. com/article/209. html
I received the WizNet chips recently and have not started working with them yet. I plan to start the next day or the day after tomorrow
无法通过 spi 读写 W5500 寄存器, 通过 ioLibrary_Driver 库简单的配置 IP 信息, 然后再读取, 或者直接读取 W5500 版本信息, 都不行.
@JiangXianSen Disable unnecessary subsystems in the SDK
I noticed that the HSPI&LSPI options affect the resulting output. I had to disable them to make the SPI class work properly
@JiangXianSen 具体描述下 SPI 的问题, 比如做主做从, 模式是否配置对了, pin 脚用的那些, 错误的现象是什么, 是否有尝试用逻辑分析仪做波形, 最好有代码.
@abcd
`
//#include "wm_include. h"
//#include "wm_demo. h"
//#define VERSIONR (_W5500_IO_BASE_ + (0x0039 8) + (WIZCHIP_CREG_BLOCK 3) )
void spi_init ()
{
printf ("spi init\n") ;
wm_spi_cs_config (SPI_CSI) ;
wm_spi_ck_config (SPI_CLK) ;
wm_spi_di_config (SPI_MISO) ;
wm_spi_do_config (SPI_MOSI) ;
if (0 == TYPE)
{
tls_spi_trans_type (0) ;
}
else
{
tls_spi_trans_type (2) ;
}
tls_spi_setup (TLS_SPI_MODE_3, TLS_SPI_CS_HIGH, CLOCK_RATE) ;
//tls_spi_setup (TLS_SPI_MODE_1, TLS_SPI_CS_LOW, CLOCK_RATE) ;
//tls_spi_setup (TLS_SPI_MODE_2, TLS_SPI_CS_LOW, CLOCK_RATE) ;
//tls_spi_setup (TLS_SPI_MODE_3, TLS_SPI_CS_LOW, CLOCK_RATE) ;
}
void spi_init (void)
{
wm_spi_ck_config (SPI_CLK) ;
wm_spi_di_config (SPI_MISO) ;
wm_spi_do_config (SPI_MOSI) ;
tls_spi_trans_type (0) ;
tls_spi_setup (TLS_SPI_MODE_0, TLS_SPI_CS_LOW, 1000000) ;
tls_gpio_cfg (SPI_CSI, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_PULLHIGH) ;
tls_gpio_write (SPI_CSI, 1) ;
}
void cs_select (void)
{
tls_spi_setup (TLS_SPI_MODE_0, TLS_SPI_CS_LOW, CLOCK_RATE) ;
//spi_set_chipselect_mode (TLS_SPI_CS_LOW) ;
//tls_gpio_write (SPI_CSI, 0) ;
}
void cs_deselect (void)
{
tls_spi_setup (TLS_SPI_MODE_0, TLS_SPI_CS_HIGH, CLOCK_RATE) ;
//spi_set_chipselect_mode (TLS_SPI_CS_HIGH) ;
//tls_gpio_write (SPI_CSI, 1) ;
}
uint8_t spi_readbyte ()
{
uint8_t rb[2] = {0, 0};
tls_spi_read ( (u8 *) rb, 1) ;
return rb[0];
}
void spi_writebyte (uint8_t wb)
{
uint8_t _wb[2] = {0, 0};
_wb[0] = wb;
tls_spi_write ( (u8 *) _wb, 1) ;
}
void spi_readburst (uint8_t* pBuf, uint16_t len)
{
tls_spi_read ( (u8 *) pBuf, len) ;
}
void spi_writeburst (uint8_t* pBuf, uint16_t len)
{
tls_spi_write ( (u8 *) pBuf, len) ;
}
void w5500_reset ()
{
tls_gpio_cfg (W5500_RESET, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_PULLLOW) ;
//tls_gpio_cfg (W5500_RESET, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_PULLHIGH) ;
tls_gpio_write (W5500_RESET, 0) ;
tls_os_time_delay (200) ;
tls_gpio_write (W5500_RESET, 1) ;
tls_os_time_delay (50) ;
}
static wiz_NetInfo NetConf = {
{0x0c, 0x29, 0xab, 0x7c, 0x04, 0x02}, // mac 地址
{192, 168, 2, 133}, // 本地 IP 地址
{255, 255, 255, 0}, // 子网掩码
{192, 168, 2, 1}, // 网关地址
{0, 0, 0, 0}, // DNS 服务器地址
NETINFO_STATIC // 使用静态 IP
};
void configNet ()
{
printf ("configNet: \n") ;
wiz_NetInfo conf = {0};
for (int i = 0; i sizeof (wiz_NetInfo) ; i ++)
{
printf ("%02X ", ( (char *) &conf) [i]) ;
}
ctlnetwork (CN_SET_NETINFO, (void *) &NetConf) ;
ctlnetwork (CN_GET_NETINFO, (void *) &conf) ;
if (memcmp (&conf, &NetConf, sizeof (wiz_NetInfo) ) == 0)
{
// 配置成功
printf ("\nYes\n") ;
}else
{
// 配置失败
printf ("\nNo\n") ;
}
for (int i = 0; i sizeof (wiz_NetInfo) ; i ++)
{
printf ("%02X ", ( (char *) &conf) [i]) ;
}
printf ("\n") ;
}
int w5500_init ()
{
printf ("w5500_init: \n") ;
uint8_t ar[16] = {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}; // 全部收发缓冲区设为 2KB (默认)
char id[6];
w5500_reset () ;
spi_init () ;
reg_wizchip_spi_cbfunc (spi_readbyte, spi_writebyte) ;
reg_wizchip_spiburst_cbfunc (spi_readburst, spi_writeburst) ;
reg_wizchip_cs_cbfunc (cs_select, cs_deselect) ;
if (ctlwizchip (CW_INIT_WIZCHIP, ar) == -1)
{
printf ("ctlwizchip err\n") ;
return -1;
}
configNet () ;
}
void w5500_test ()
{
uint8_t dest_ip[4] = {192, 168, 2, 59};
uint16_t dest_port = 8080;
uint8_t dataBuffer[DATA_BUF_SIZE] = {0x0};
printf ("w5500_test: \n") ;
if (w5500_init () 0)
{
printf ("w5500 init failed\n") ;
return ;
}
uint16_t time_delay = 10000;
while (1)
{
loopback_tcpc (0x0, dataBuffer, dest_ip, dest_port) ;
printf ("tls_os_time_delay: %d\n", time_delay) ;
tls_os_time_delay (time_delay) ;
}
}
void SpiReadReg (uint8_t addr, uint32_t addr_len, uint8_t data, uint8_t data_len)
{
tls_gpio_write (SPI_CSI, 0) ;
tls_spi_read_with_cmd (addr, addr_len, data, data_len) ;
tls_gpio_write (SPI_CSI, 1) ;
}
void SpiWriteReg (uint8_t addr, uint32_t addr_len, uint8_t data, uint8_t data_len)
{
tls_gpio_write (SPI_CSI, 0) ;
tls_spi_write_with_cmd (addr, addr_len, data, data_len) ;
tls_gpio_write (SPI_CSI, 1) ;
}
void SpiReadData (uint8_t *data, uint32_t len)
{
tls_gpio_write (SPI_CSI, 0) ;
tls_spi_read (data, len) ;
tls_gpio_write (SPI_CSI, 1) ;
}
void SpiWriteData (uint8_t *data, uint32_t len)
{
tls_gpio_write (SPI_CSI, 0) ;
tls_spi_write (data, len) ;
tls_gpio_write (SPI_CSI, 1) ;
}
void SpiTest (void)
{
uint8_t addr[4] = {0x90, 0x00, 0x00, 0x00};
uint8_t data[2] = {0x00, 0x00};
spi_init () ;
printf ("data = %x %x\n", data[0], data[1]) ;
SpiReadReg (addr, 4, data, 2) ;
printf ("data = %x %x\n", data[0], data[1]) ;
}
void UserMain (void)
{
printf ("\n user task \n") ;
CreateDemoTask () ;
printf ("\n Test \n") ;
w5500_test () ;
//SpiTest () ;
//用户自己的 task
}
`这是测试代码
@JiangXianSen wm_main. c 里面 spi pin 脚的初始化注释掉, 如楼下截图所示. 另外 cs 如果不想自己控制就调用 wm_spi_cs_config 初始化就行了, 如果想自己控制就调用 tls_gpio_cfg 初始化, 然后用 tls_gpio_write 来拉高拉低.
@isme 好的