2
2
/*
3
3
* Copyright (C) 2013 Henrik Ekblad <[email protected] >
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
38
38
* 7 Radio error LED (optional) +5V -> LED -> 270-330 Ohm resistor -> pin 7.
39
39
* 6 Radio SPI Slave Select
40
40
* 5 Radio Chip Enable
41
+ * 4 Ethernet SPI Enable (optional if using a shield/module that manages SPI_EN signal)
41
42
* 3 Inclusion mode button (optional), 10K pull down to GND, button to VCC)
42
43
* 2 Radio IRQ pin (optional), W5100 Int, if linked to pin 2)
43
44
* -----------------------------------------------------------------------------------------------------------
59
60
#define INCLUSION_MODE_TIME 1 // Number of minutes inclusion mode is enabled
60
61
#define INCLUSION_MODE_PIN 3 // Digital pin used for inclusion mode button
61
62
63
+ #define W5100_SPI_EN 4 // Ethernet SPI enable
62
64
#define RADIO_CE_PIN 5 // radio chip enable
63
65
#define RADIO_SPI_SS_PIN 6 // radio SPI serial select
64
66
#define RADIO_ERROR_LED_PIN 7 // Error led pin
@@ -86,30 +88,54 @@ MyGateway gw(RADIO_CE_PIN, RADIO_SPI_SS_PIN, INCLUSION_MODE_TIME);
86
88
char inputString[MAX_RECEIVE_LENGTH] = " " ; // A string to hold incoming commands from serial/ethernet interface
87
89
int inputPos = 0 ;
88
90
91
+ void w5100_spi_en (boolean enable)
92
+ {
93
+ #ifdef W5100_SPI_EN
94
+ if (enable)
95
+ {
96
+ // Pull up pin
97
+ pinMode (W5100_SPI_EN, INPUT);
98
+ digitalWrite (W5100_SPI_EN, HIGH);
99
+ }
100
+ else
101
+ {
102
+ // Ground pin
103
+ pinMode (W5100_SPI_EN, OUTPUT);
104
+ digitalWrite (W5100_SPI_EN, LOW);
105
+ }
106
+ #endif
107
+ }
108
+
89
109
void setup ()
90
110
{
91
- // Initialize gateway at maximum PA level, channel 70 and callback for write operations
92
- gw.begin (RF24_PA_LEVEL_GW, RF24_CHANNEL, RF24_DATARATE, writeEthernet);
93
-
111
+ w5100_spi_en (true );
112
+ Ethernet.begin (mac);
94
113
Ethernet.begin (mac, myIp);
95
114
96
115
// give the Ethernet interface a second to initialize
97
116
delay (1000 );
98
117
118
+ // Initialize gateway at generic GW PA level, channel 70 and callback for write operations
119
+ w5100_spi_en (false );
120
+ gw.begin (RF24_PA_LEVEL_GW, RF24_CHANNEL, RF24_DATARATE, writeEthernet);
121
+
99
122
// start listening for clients
100
123
server.begin ();
101
124
}
102
125
103
126
// This will be called when data should be written to ethernet
104
127
void writeEthernet (char *writeBuffer) {
128
+ w5100_spi_en (true );
105
129
server.write (writeBuffer);
130
+ w5100_spi_en (false );
106
131
}
107
132
108
133
109
134
void loop ()
110
135
{
111
136
// if an incoming client connects, there will be
112
137
// bytes available to read via the client object
138
+ w5100_spi_en (true );
113
139
EthernetClient client = server.available ();
114
140
115
141
if (client) {
@@ -128,7 +154,9 @@ void loop()
128
154
// echo the string to the serial port
129
155
Serial.print (inputString);
130
156
157
+ w5100_spi_en (false );
131
158
gw.parseAndSend (inputString);
159
+ w5100_spi_en (true );
132
160
133
161
// clear the string:
134
162
inputPos = 0 ;
@@ -143,6 +171,7 @@ void loop()
143
171
}
144
172
}
145
173
}
174
+ w5100_spi_en (false );
146
175
gw.processRadioMessage ();
147
176
}
148
177
0 commit comments