Hi there,
I am trying to configure an Arduino Ethernet Shield on top of an Arm Musca-B1 board. As of now, I have the SPI library working as well as the ioLibrary. My code looks like this:
reg_wizchip_cs_cbfunc(cs_sel, cs_desel);
reg_wizchip_spi_cbfunc(spi_rb, spi_wb);
wizchip_init(bufSize, bufSize);
wiz_NetInfo netInfo = {
.mac = {
0xDE,
0xAD,
0xBE,
0xEF,
0xFE,
0xED
}, // Mac address
.ip = {
192,
168,
1,
192
}, // IP address
.sn = {
255,
255,
255,
0
}, // Subnet mask
.gw = {
192,
168,
1,
1
}
}; // Gateway address
wizchip_setnetinfo( & netInfo);
wizchip_getnetinfo( & netInfo);
reconnect:
/* Open socket 0 as TCP_SOCKET with port 5000 */
if ((retVal = socket(0, Sn_MR_TCP, 5000, 0)) == 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)
for (int i = 0; i < 1000; i++);
/* 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) {
uint8_t remoteIP[4];
uint16_t remotePort;
/* 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);
/* 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);
}
break;
} else {
/* Something went wrong with remote peer, maybe the connection was closed unexpectedly */
sprintf(msg, WRONG_STATUS_MSG, sockStatus);
break;
}
}
} else /* Ops: socket not in LISTEN mode. Something went wrong */ {}
}
else {
/* Can't open the socket. This means something is wrong with W5100 configuration: maybe SPI issue? */
sprintf(msg, WRONG_RETVAL_MSG, retVal);
}
/* We close the socket and start a connection again */
disconnect(0);
close(0);
goto reconnect;
I am able to set the network information and ping the board with the IP and MAC chosen.
Nevertheless, when I try to telnet the device I have no output at all. It keeps trying to connect without success.
While debugging I notice that I can’t put the socket to listen, which is maybe related with the SPI communication. I will left some pictures of a SPI sniffer so you can check if there’s any problem with the communication (which I think there is, since on read operations the CS is going high before any byte being write on MISO.