/* Code to test wiznet WIZ810MJ module See: Current features: * Initial W5100 driver port: + new-style network configuration + socket creation/listening/closing + Sending/Receiving okay + example "echo" server * Terrible hacked-together code Author: follower@rancidbacon.com License: LGPL Version: 20071106-0005+ */ #include // Define SPI-related pins #define PIN_DATA_OUT 11 // MOSI (Master Out / Slave In) #define PIN_DATA_IN 12 // MISO (Master In / Slave Out) #define PIN_SPI_CLOCK 13 // SCK (Serial Clock) #define PIN_SLAVE_SELECT 10 // SS (Slave Select) // #define PIN_RESET 9 // WIZnet module /RESET #define PIN_RESET 8 // WIZnet module /RESET SOCKET testSocket; byte ip[6]; void configureSPI() { /* Configure pins and registers required for SPI communication. */ // Configure I/O pins pinMode(PIN_DATA_OUT, OUTPUT); pinMode(PIN_DATA_IN, INPUT); pinMode(PIN_SPI_CLOCK, OUTPUT); pinMode(PIN_SLAVE_SELECT, OUTPUT); digitalWrite(PIN_SLAVE_SELECT, HIGH); // Disable slave /* Configure SPI Control Register (SPCR) (All values initially 0) Bit Description 7 SPI Interrupt Enable -- disable (SPIE --> 0) 6 SPI Enable -- enable (SPE --> 1) 5 Data Order -- MSB 1st (DORD --> 0) (Slave specific) 4 Master/Slave Select -- master (MSTR --> 1) 3 Clock Polarity -- (CPOL --> 0) (Slave specific) ("Mode") 2 Clock Phase -- (CPHA --> 0) (Slave specific) 1 SPI Clock Rate Select 1 -- } (SPR1 --> 0) 0 SPI Clock Rate Select 0 -- } fOSC/4 (SPR0 --> 0) ("Fastest" but see SPI2X in SPSR) */ SPCR = (1< 0) { dataLength = getSn_RX_RSR(testSocket); if (dataLength >= MAX_RX_BUFFER_SIZE) { // TODO: blah, blah... dataLength = MAX_RX_BUFFER_SIZE-1; } Serial.print("dataLength: "); Serial.println(dataLength, HEX); Serial.print("recv result: "); Serial.println(recv(testSocket, bytesReceived, dataLength), DEC); // NOTE: Throws away unread portion? bytesReceived[dataLength]=0x00; Serial.println((char *)bytesReceived); Serial.print("send result: "); Serial.println(send(testSocket, bytesReceived, dataLength), DEC); sendPrompt(bytesReceived); }} disconnect(testSocket); close(testSocket); Serial.println("End test W5100 socket..."); }