Merge pull request #37 from fallberg/development
Fix for W5100 Ethernet module
This commit is contained in:
@@ -0,0 +1 @@
|
||||
stino.settings
|
||||
@@ -2,7 +2,7 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Henrik Ekblad <henrik.ekblad@gmail.com>
|
||||
*
|
||||
* Contribution by a-lurker
|
||||
* Contribution by a-lurker and Anticimex
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -42,6 +42,7 @@
|
||||
* 7 Radio error LED (optional) +5V -> LED -> 270-330 Ohm resistor -> pin 7.
|
||||
* 6 Radio SPI Slave Select
|
||||
* 5 Radio Chip Enable
|
||||
* 4 Ethernet SPI Enable (optional if using a shield/module that manages SPI_EN signal)
|
||||
* 3 Inclusion mode button (optional) GND-> Button -> Pin3
|
||||
* 2 Radio IRQ pin (optional)
|
||||
* -----------------------------------------------------------------------------------------------------------
|
||||
@@ -67,6 +68,7 @@
|
||||
#define INCLUSION_MODE_TIME 1 // Number of minutes inclusion mode is enabled
|
||||
#define INCLUSION_MODE_PIN 3 // Digital pin used for inclusion mode button
|
||||
|
||||
#define W5100_SPI_EN 4 // Ethernet SPI enable
|
||||
#define RADIO_CE_PIN 5 // radio chip enable
|
||||
#define RADIO_SPI_SS_PIN 6 // radio SPI serial select
|
||||
|
||||
@@ -93,6 +95,23 @@ EthernetServer server = EthernetServer(IP_PORT);
|
||||
char inputString[MAX_RECEIVE_LENGTH] = ""; // A string to hold incoming commands from serial/ethernet interface
|
||||
int inputPos = 0;
|
||||
|
||||
void w5100_spi_en(boolean enable)
|
||||
{
|
||||
#ifdef W5100_SPI_EN
|
||||
if (enable)
|
||||
{
|
||||
// Pull up pin
|
||||
pinMode(W5100_SPI_EN, INPUT);
|
||||
digitalWrite(W5100_SPI_EN, HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Ground pin
|
||||
pinMode(W5100_SPI_EN, OUTPUT);
|
||||
digitalWrite(W5100_SPI_EN, LOW);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void output(const char *fmt, ... ) {
|
||||
va_list args;
|
||||
@@ -100,19 +119,22 @@ void output(const char *fmt, ... ) {
|
||||
vsnprintf_P(serialBuffer, MAX_SEND_LENGTH, fmt, args);
|
||||
va_end (args);
|
||||
Serial.print(serialBuffer);
|
||||
w5100_spi_en(true);
|
||||
server.write(serialBuffer);
|
||||
w5100_spi_en(false);
|
||||
}
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
w5100_spi_en(false);
|
||||
// Initialize gateway at maximum PA level, channel 70 and callback for write operations
|
||||
gw.begin(incomingMessage, 0, true, 0, RF24_PA_LEVEL_GW, RF24_CHANNEL, RF24_DATARATE);
|
||||
// Setup pipes for radio library
|
||||
gw.openReadingPipe(WRITE_PIPE, BASE_RADIO_ID);
|
||||
gw.openReadingPipe(CURRENT_NODE_PIPE, BASE_RADIO_ID);
|
||||
gw.startListening();
|
||||
|
||||
|
||||
w5100_spi_en(true);
|
||||
Ethernet.begin(mac, myIp);
|
||||
setupGateway(RADIO_RX_LED_PIN, RADIO_TX_LED_PIN, RADIO_ERROR_LED_PIN, INCLUSION_MODE_PIN, INCLUSION_MODE_TIME, output);
|
||||
|
||||
@@ -128,6 +150,7 @@ void setup()
|
||||
|
||||
// start listening for clients
|
||||
server.begin();
|
||||
w5100_spi_en(false);
|
||||
|
||||
//output(PSTR("0;0;%d;0;%d;Gateway startup complete.\n"), C_INTERNAL, I_GATEWAY_READY);
|
||||
|
||||
@@ -144,6 +167,7 @@ void loop()
|
||||
|
||||
// if an incoming client connects, there will be
|
||||
// bytes available to read via the client object
|
||||
w5100_spi_en(true);
|
||||
EthernetClient client = server.available();
|
||||
|
||||
if (client) {
|
||||
@@ -163,6 +187,7 @@ void loop()
|
||||
// echo the string to the serial port
|
||||
Serial.print(inputString);
|
||||
|
||||
w5100_spi_en(false);
|
||||
parseAndSend(gw, inputString);
|
||||
|
||||
// clear the string:
|
||||
@@ -178,8 +203,7 @@ void loop()
|
||||
}
|
||||
}
|
||||
}
|
||||
w5100_spi_en(false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user