cancel
Showing results for 
Search instead for 
Did you mean: 

W5500 library for a STM32F103C8

SGatt.1
Associate II

Hello.

I am working on a project where I nees to communicate 2 STM32F103C8 that are on the same LAN using a W5500 module. Has anybody done something similar? What is the best way to do it?

Although, there is a library for this porpuse? I am trying to adapt an Arduino library to C language because it was programmed on C++

8 REPLIES 8
GOtté.1
Associate II

Hi. Did you find a solution for this? I'm looking for the same. Thanks.

SGatt.1
Associate II

Hi.

Yes. I will copy the web client example project that I did so you can see the library.

https://github.com/samirgattas/WebClient

First of all, I modified the project to a C++ project because I adapted a C++ library because I used the HAL_library of ST. After that, I define the CS pin as you can see in line 18 of the file Core/Inc/W5500.h.

You need all the files that are in the folders Core/Src and Core/Inc to run the library, except stm32f1xx_it.h, stm32f1xx_hal_conf.h, main.h and comunicacion.h.

Please, tell me if there is something that you do not undestand so I will try to help you

GOtté.1
Associate II

Hi, thank you for your quick reply! I will try to get it working, and if I run into some questions, I will come back to you. Thanks for helping me out!

Ayuks.1
Associate II

when debug, everything is good and working. but If I shut down the computer then I cannot connect to the processor again. When you enter the ethernet settings from the control panel and turn the ethernet off and on, it works normally again. how to solve this error. can you help me. my mcu is working tcp server mode. ı am using tcp comunication.

ı am using stm32f407vg .w5500 module .

my code

/* Open socket 0 as TCP_SOCKET with port 5000 /

if((retVal = socket(0, Sn_MR_TCP, 80, SF_TCP_NODELAY)) == 0) {

/ Put socket in LISTEN mode. This means we are creating a TCP server /

if((retVal = listen(0)) == SOCK_OK) {

/ While socket is in LISTEN mode we wait for a remote connection */

while(sockStatus = getSn_SR(0) == SOCK_LISTEN)

delay(600);

/* OK. Got a remote peer. Let's send a message to it */

while(1) {

/* If connection is ESTABLISHED with remote peer */

if(sockStatus = getSn_SR(0) == SOCK_ESTABLISHED) {

/* Retrieving remote peer IP and port number */

getsockopt(0, SO_DESTIP, remoteIP);

getsockopt(0, SO_DESTPORT, (uint8_t*)&remotePort);

sprintf(msg, CONN_ESTABLISHED_MSG, remoteIP[0], remoteIP[1], remoteIP[2], remoteIP[3], remotePort);

PRINT_STR(msg);

while(received_len==0)

{

if((RSR_len = getSn_RX_RSR(0) )> 0)

{

received_len = recv(0, data_buf, RSR_len);

if(data_buf[0] == 1)

{

HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_15);

sprintf(msg,"adc degeri %d",adc_ntc[0]);

send(0, msg, strlen(msg));

}

else

{

sprintf(msg,"adc degeri %d",adc_ntc[0]);

send(0, msg, strlen(msg));

HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_14);

}

}

}

received_len =0;

/* Let's send a welcome message and closing socket */

if(retVal = send(0, GREETING_MSG, strlen(GREETING_MSG)) == (int16_t)strlen(GREETING_MSG))

PRINT_STR(SENT_MESSAGE_MSG);

else { /* Ops: something went wrong during data transfer */

sprintf(msg, WRONG_RETVAL_MSG, retVal);

PRINT_STR(msg);

}

break;

}

else { /* Something went wrong with remote peer, maybe the connection was closed unexpectedly */

sprintf(msg, WRONG_STATUS_MSG, sockStatus);

PRINT_STR(msg);

break;

}

}

else /* Ops: socket not in LISTEN mode. Something went wrong */

PRINT_STR(LISTEN_ERR_MSG);

else { /* Can't open the socket. This means something is wrong with W5100 configuration: maybe SPI issue? */

sprintf(msg, WRONG_RETVAL_MSG, retVal);

PRINT_STR(msg);

}

/* We close the socket and start a connection again */

// disconnect(0);

close(0);

SGatt.1
Associate II

Hello.

I do not understand your problem. Why do you turn off the computer? Is the server running in your computer?

Hello.

I do not understand your problem. Why do you turn off the computer? Is the server running in your computer?

hi , thanks for you'r sharing but link is not working !

can you fix that? i need your code :)

Hi,I am using the same code but when tried to test MODBUS between two controllers i.e., one controller as master and other as slave it's not working and giving me with an error of timeout or socket closed. Can you help me to solve this. Had you tried of existing communication between two controllers?