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 好的