22/*
33 * Copyright (C) 2013 Henrik Ekblad <henrik.ekblad@gmail.com>
44 *
5- * Contribution by a-lurker
5+ * Contribution by a-lurker and Anticimex
66 *
77 * This program is free software; you can redistribute it and/or
88 * modify it under the terms of the GNU General Public License
4242 * 7 Radio error LED (optional) +5V -> LED -> 270-330 Ohm resistor -> pin 7.
4343 * 6 Radio SPI Slave Select
4444 * 5 Radio Chip Enable
45+ * 4 Ethernet SPI Enable (optional if using a shield/module that manages SPI_EN signal)
4546 * 3 Inclusion mode button (optional) GND-> Button -> Pin3
4647 * 2 Radio IRQ pin (optional)
4748 * -----------------------------------------------------------------------------------------------------------
6768#define INCLUSION_MODE_TIME 1 // Number of minutes inclusion mode is enabled
6869#define INCLUSION_MODE_PIN 3 // Digital pin used for inclusion mode button
6970
71+ #define W5100_SPI_EN 4 // Ethernet SPI enable
7072#define RADIO_CE_PIN 5 // radio chip enable
7173#define RADIO_SPI_SS_PIN 6 // radio SPI serial select
7274
@@ -93,26 +95,46 @@ EthernetServer server = EthernetServer(IP_PORT);
9395char inputString[MAX_RECEIVE_LENGTH] = " " ; // A string to hold incoming commands from serial/ethernet interface
9496int inputPos = 0 ;
9597
98+ void w5100_spi_en (boolean enable)
99+ {
100+ #ifdef W5100_SPI_EN
101+ if (enable)
102+ {
103+ // Pull up pin
104+ pinMode (W5100_SPI_EN, INPUT);
105+ digitalWrite (W5100_SPI_EN, HIGH);
106+ }
107+ else
108+ {
109+ // Ground pin
110+ pinMode (W5100_SPI_EN, OUTPUT);
111+ digitalWrite (W5100_SPI_EN, LOW);
112+ }
113+ #endif
114+ }
96115
97116void output (const char *fmt, ... ) {
98117 va_list args;
99118 va_start (args, fmt );
100119 vsnprintf_P (serialBuffer, MAX_SEND_LENGTH, fmt, args);
101120 va_end (args);
102121 Serial.print (serialBuffer);
122+ w5100_spi_en (true );
103123 server.write (serialBuffer);
124+ w5100_spi_en (false );
104125}
105126
106-
107127void setup ()
108128{
129+ w5100_spi_en (false );
109130 // Initialize gateway at maximum PA level, channel 70 and callback for write operations
110131 gw.begin (incomingMessage, 0 , true , 0 , RF24_PA_LEVEL_GW, RF24_CHANNEL, RF24_DATARATE);
111132 // Setup pipes for radio library
112133 gw.openReadingPipe (WRITE_PIPE, BASE_RADIO_ID);
113134 gw.openReadingPipe (CURRENT_NODE_PIPE, BASE_RADIO_ID);
114135 gw.startListening ();
115-
136+
137+ w5100_spi_en (true );
116138 Ethernet.begin (mac, myIp);
117139 setupGateway (RADIO_RX_LED_PIN, RADIO_TX_LED_PIN, RADIO_ERROR_LED_PIN, INCLUSION_MODE_PIN, INCLUSION_MODE_TIME, output);
118140
@@ -128,6 +150,7 @@ void setup()
128150
129151 // start listening for clients
130152 server.begin ();
153+ w5100_spi_en (false );
131154
132155 // output(PSTR("0;0;%d;0;%d;Gateway startup complete.\n"), C_INTERNAL, I_GATEWAY_READY);
133156
@@ -144,6 +167,7 @@ void loop()
144167
145168 // if an incoming client connects, there will be
146169 // bytes available to read via the client object
170+ w5100_spi_en (true );
147171 EthernetClient client = server.available ();
148172
149173 if (client) {
@@ -163,6 +187,7 @@ void loop()
163187 // echo the string to the serial port
164188 Serial.print (inputString);
165189
190+ w5100_spi_en (false );
166191 parseAndSend (gw, inputString);
167192
168193 // clear the string:
@@ -178,8 +203,7 @@ void loop()
178203 }
179204 }
180205 }
206+ w5100_spi_en (false );
181207}
182208
183209
184-
185-
0 commit comments