2
2
/*
3
3
* Copyright (C) 2013 Henrik Ekblad <henrik.ekblad@gmail.com>
4
4
*
5
- * Contribution by a-lurker
5
+ * Contribution by a-lurker and Anticimex
6
6
*
7
7
* This program is free software; you can redistribute it and/or
8
8
* modify it under the terms of the GNU General Public License
42
42
* 7 Radio error LED (optional) +5V -> LED -> 270-330 Ohm resistor -> pin 7.
43
43
* 6 Radio SPI Slave Select
44
44
* 5 Radio Chip Enable
45
+ * 4 Ethernet SPI Enable (optional if using a shield/module that manages SPI_EN signal)
45
46
* 3 Inclusion mode button (optional) GND-> Button -> Pin3
46
47
* 2 Radio IRQ pin (optional)
47
48
* -----------------------------------------------------------------------------------------------------------
67
68
#define INCLUSION_MODE_TIME 1 // Number of minutes inclusion mode is enabled
68
69
#define INCLUSION_MODE_PIN 3 // Digital pin used for inclusion mode button
69
70
71
+ #define W5100_SPI_EN 4 // Ethernet SPI enable
70
72
#define RADIO_CE_PIN 5 // radio chip enable
71
73
#define RADIO_SPI_SS_PIN 6 // radio SPI serial select
72
74
@@ -93,26 +95,46 @@ EthernetServer server = EthernetServer(IP_PORT);
93
95
char inputString[MAX_RECEIVE_LENGTH] = " " ; // A string to hold incoming commands from serial/ethernet interface
94
96
int inputPos = 0 ;
95
97
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
+ }
96
115
97
116
void output (const char *fmt, ... ) {
98
117
va_list args;
99
118
va_start (args, fmt );
100
119
vsnprintf_P (serialBuffer, MAX_SEND_LENGTH, fmt, args);
101
120
va_end (args);
102
121
Serial.print (serialBuffer);
122
+ w5100_spi_en (true );
103
123
server.write (serialBuffer);
124
+ w5100_spi_en (false );
104
125
}
105
126
106
-
107
127
void setup ()
108
128
{
129
+ w5100_spi_en (false );
109
130
// Initialize gateway at maximum PA level, channel 70 and callback for write operations
110
131
gw.begin (incomingMessage, 0 , true , 0 , RF24_PA_LEVEL_GW, RF24_CHANNEL, RF24_DATARATE);
111
132
// Setup pipes for radio library
112
133
gw.openReadingPipe (WRITE_PIPE, BASE_RADIO_ID);
113
134
gw.openReadingPipe (CURRENT_NODE_PIPE, BASE_RADIO_ID);
114
135
gw.startListening ();
115
-
136
+
137
+ w5100_spi_en (true );
116
138
Ethernet.begin (mac, myIp);
117
139
setupGateway (RADIO_RX_LED_PIN, RADIO_TX_LED_PIN, RADIO_ERROR_LED_PIN, INCLUSION_MODE_PIN, INCLUSION_MODE_TIME, output);
118
140
@@ -128,6 +150,7 @@ void setup()
128
150
129
151
// start listening for clients
130
152
server.begin ();
153
+ w5100_spi_en (false );
131
154
132
155
// output(PSTR("0;0;%d;0;%d;Gateway startup complete.\n"), C_INTERNAL, I_GATEWAY_READY);
133
156
@@ -144,6 +167,7 @@ void loop()
144
167
145
168
// if an incoming client connects, there will be
146
169
// bytes available to read via the client object
170
+ w5100_spi_en (true );
147
171
EthernetClient client = server.available ();
148
172
149
173
if (client) {
@@ -163,6 +187,7 @@ void loop()
163
187
// echo the string to the serial port
164
188
Serial.print (inputString);
165
189
190
+ w5100_spi_en (false );
166
191
parseAndSend (gw, inputString);
167
192
168
193
// clear the string:
@@ -178,8 +203,7 @@ void loop()
178
203
}
179
204
}
180
205
}
206
+ w5100_spi_en (false );
181
207
}
182
208
183
209
184
-
185
-
0 commit comments