From cd1bdecdae4e78457456a46f815da1d24f38ab10 Mon Sep 17 00:00:00 2001 From: follower Date: Mon, 5 Nov 2007 11:12:24 +0000 Subject: [PATCH] Add initial very-rough demo of 'echo' server. git-svn-id: svn+ssh://oldsvn/home/mlalondesvn/svn/cral@58 3ee9b42a-b53c-0410-a25e-f0b6218d5d5b --- .../wiz810mj/src/demo/WizDemo1/WizDemo1.pde | 312 ++++++++++++++++++ 1 file changed, 312 insertions(+) create mode 100644 branches/follower/wiz810mj/src/demo/WizDemo1/WizDemo1.pde diff --git a/branches/follower/wiz810mj/src/demo/WizDemo1/WizDemo1.pde b/branches/follower/wiz810mj/src/demo/WizDemo1/WizDemo1.pde new file mode 100644 index 0000000..900666e --- /dev/null +++ b/branches/follower/wiz810mj/src/demo/WizDemo1/WizDemo1.pde @@ -0,0 +1,312 @@ +/* + + Code to test wiznet WIZ810MJ module + + See: + + + + Current features: + + * Read register/address values + + * Write register/address values + + * Configure networking to enable ping (old style) + + * 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 + + (Although note spi_transfer comes from the Playground originally.) + + 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 + +#define WIZNET_OPCODE_READ 0x0F +#define WIZNET_OPCODE_WRITE 0xF0 + +#define DUMMY_DATA 0xFF + +SOCKET testSocket; +byte ip[6]; + + +void setup () { + Serial.begin(9600); + Serial.println("Setup enter..."); + + Serial.print("SPCR: "); Serial.println(SPCR, BIN); + + // Configure SPI + // 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..."); + + + +} +