-
Notifications
You must be signed in to change notification settings - Fork 48
STM32Ethernet source files #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
febc2e2
Initial source files come from Ethernet library of Arduino 1.8.3
6935488
Update Arduino library properties
da88563
Add Ethernet network driver for LwIP from STM32Cube_FW_F4_V1.16.0
ddc0fd1
Update Ethernet driver for STM32 Arduino.
b8f8332
Rename library entry files to keep compatibility with the default Ard…
1f95d13
Update library classes for STM32
79d3d62
Remove unused files
f5fecc7
Modify examples for the STM32Ethernet library
e02d9ed
Update library documentation
e641f84
Replaced specific HAL include with generic one
2cbafb0
Use the same MAC address in all sketches and remove comments outdated.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
Alberto Panu https://github.com/bigjohnson | ||
Alasdair Allan https://github.com/aallan | ||
Alice Pintus https://github.com/00alis | ||
Adrian McEwen https://github.com/amcewen | ||
Arduino LLC http://arduino.cc/ | ||
Arnie97 https://github.com/Arnie97 | ||
Arturo Guadalupi https://github.com/agdl | ||
Bjoern Hartmann https://people.eecs.berkeley.edu/~bjoern/ | ||
chaveiro https://github.com/chaveiro | ||
Cristian Maglie https://github.com/cmaglie | ||
David A. Mellis https://github.com/damellis | ||
Dino Tinitigan https://github.com/bigdinotech | ||
Eddy https://github.com/eddyst | ||
Federico Vanzati https://github.com/Fede85 | ||
Federico Fissore https://github.com/ffissore | ||
Jack Christensen https://github.com/JChristensen | ||
Johann Richard https://github.com/johannrichard | ||
Jordan Terrell https://github.com/iSynaptic | ||
Justin Paulin https://github.com/interwho | ||
lathoub https://github.com/lathoub | ||
Martino Facchin https://github.com/facchinm | ||
Matthias Hertel https://github.com/mathertel | ||
Matthijs Kooijman https://github.com/matthijskooijman | ||
Matt Robinson https://github.com/ribbons | ||
MCQN Ltd. http://mcqn.com/ | ||
Michael Amie https://github.com/michaelamie | ||
Michael Margolis https://github.com/michaelmargolis | ||
Norbert Truchsess https://github.com/ntruchsess | ||
Paul Stoffregen https://github.com/PaulStoffregen | ||
per1234 https://github.com/per1234 | ||
Richard Sim | ||
Scott Fitzgerald https://github.com/shfitz | ||
Thibaut Viard https://github.com/aethaniel | ||
Tom Igoe https://github.com/tigoe | ||
WizNet http://www.wiznet.co.kr | ||
Zach Eveland https://github.com/zeveland | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
= Ethernet Library for Arduino = | ||
|
||
With the Arduino Ethernet Shield, this library allows an Arduino board to connect to the internet. | ||
|
||
For more information about this library please visit us at | ||
http://www.arduino.cc/en/Reference/Ethernet | ||
|
||
== License == | ||
|
||
Copyright (c) 2010 Arduino LLC. All right reserved. | ||
|
||
This library is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU Lesser General Public | ||
License as published by the Free Software Foundation; either | ||
version 2.1 of the License, or (at your option) any later version. | ||
|
||
This library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Lesser General Public License for more details. | ||
|
||
You should have received a copy of the GNU Lesser General Public | ||
License along with this library; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
Advanced Chat Server | ||
|
||
A more advanced server that distributes any incoming messages | ||
to all connected clients but the client the message comes from. | ||
To use, telnet to your device's IP address and type. | ||
You can see the client's input in the serial monitor as well. | ||
Using an Arduino Wiznet Ethernet shield. | ||
|
||
Circuit: | ||
* Ethernet shield attached to pins 10, 11, 12, 13 | ||
|
||
created 18 Dec 2009 | ||
by David A. Mellis | ||
modified 9 Apr 2012 | ||
by Tom Igoe | ||
redesigned to make use of operator== 25 Nov 2013 | ||
by Norbert Truchsess | ||
|
||
*/ | ||
|
||
#include <SPI.h> | ||
#include <Ethernet.h> | ||
|
||
// Enter a MAC address and IP address for your controller below. | ||
// The IP address will be dependent on your local network. | ||
// gateway and subnet are optional: | ||
byte mac[] = { | ||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED | ||
}; | ||
IPAddress ip(192, 168, 1, 177); | ||
IPAddress myDns(192, 168, 1, 1); | ||
IPAddress gateway(192, 168, 1, 1); | ||
IPAddress subnet(255, 255, 0, 0); | ||
|
||
|
||
// telnet defaults to port 23 | ||
EthernetServer server(23); | ||
|
||
EthernetClient clients[4]; | ||
|
||
void setup() { | ||
// initialize the Ethernet device | ||
Ethernet.begin(mac, ip, myDns, gateway, subnet); | ||
// start listening for clients | ||
server.begin(); | ||
// Open serial communications and wait for port to open: | ||
Serial.begin(9600); | ||
while (!Serial) { | ||
; // wait for serial port to connect. Needed for native USB port only | ||
} | ||
|
||
|
||
Serial.print("Chat server address:"); | ||
Serial.println(Ethernet.localIP()); | ||
} | ||
|
||
void loop() { | ||
// wait for a new client: | ||
EthernetClient client = server.available(); | ||
|
||
// when the client sends the first byte, say hello: | ||
if (client) { | ||
|
||
boolean newClient = true; | ||
for (byte i = 0; i < 4; i++) { | ||
//check whether this client refers to the same socket as one of the existing instances: | ||
if (clients[i] == client) { | ||
newClient = false; | ||
break; | ||
} | ||
} | ||
|
||
if (newClient) { | ||
//check which of the existing clients can be overridden: | ||
for (byte i = 0; i < 4; i++) { | ||
if (!clients[i] && clients[i] != client) { | ||
clients[i] = client; | ||
// clear out the input buffer: | ||
client.flush(); | ||
Serial.println("We have a new client"); | ||
client.print("Hello, client number: "); | ||
client.print(i); | ||
client.println(); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
if (client.available() > 0) { | ||
// read the bytes incoming from the client: | ||
char thisChar = client.read(); | ||
// echo the bytes back to all other connected clients: | ||
for (byte i = 0; i < 4; i++) { | ||
if (clients[i] && (clients[i] != client)) { | ||
clients[i].write(thisChar); | ||
} | ||
} | ||
// echo the bytes to the server as well: | ||
Serial.write(thisChar); | ||
} | ||
} | ||
for (byte i = 0; i < 4; i++) { | ||
if (!(clients[i].connected())) { | ||
// client.stop() invalidates the internal socket-descriptor, so next use of == will allways return false; | ||
clients[i].stop(); | ||
} | ||
} | ||
} |
219 changes: 219 additions & 0 deletions
219
examples/BarometricPressureWebServer/BarometricPressureWebServer.ino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,219 @@ | ||
/* | ||
SCP1000 Barometric Pressure Sensor Display | ||
|
||
Serves the output of a Barometric Pressure Sensor as a web page. | ||
Uses the SPI library. For details on the sensor, see: | ||
http://www.sparkfun.com/commerce/product_info.php?products_id=8161 | ||
|
||
This sketch adapted from Nathan Seidle's SCP1000 example for PIC: | ||
http://www.sparkfun.com/datasheets/Sensors/SCP1000-Testing.zip | ||
|
||
Circuit: | ||
SCP1000 sensor attached to pins 6,7, and 11 - 13: | ||
DRDY: pin 6 | ||
CSB: pin 7 | ||
MOSI: pin 11 | ||
MISO: pin 12 | ||
SCK: pin 13 | ||
|
||
created 31 July 2010 | ||
by Tom Igoe | ||
*/ | ||
|
||
#include <Ethernet.h> | ||
// the sensor communicates using SPI, so include the library: | ||
#include <SPI.h> | ||
|
||
|
||
// assign a MAC address for the Ethernet controller. | ||
// fill in your address here: | ||
byte mac[] = { | ||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED | ||
}; | ||
// assign an IP address for the controller: | ||
IPAddress ip(192, 168, 1, 20); | ||
|
||
|
||
// Initialize the Ethernet server library | ||
// with the IP address and port you want to use | ||
// (port 80 is default for HTTP): | ||
EthernetServer server(80); | ||
|
||
|
||
//Sensor's memory register addresses: | ||
const int PRESSURE = 0x1F; //3 most significant bits of pressure | ||
const int PRESSURE_LSB = 0x20; //16 least significant bits of pressure | ||
const int TEMPERATURE = 0x21; //16 bit temperature reading | ||
|
||
// pins used for the connection with the sensor | ||
// the others you need are controlled by the SPI library): | ||
const int dataReadyPin = 6; | ||
const int chipSelectPin = 7; | ||
|
||
float temperature = 0.0; | ||
long pressure = 0; | ||
long lastReadingTime = 0; | ||
|
||
void setup() { | ||
// start the SPI library: | ||
SPI.begin(); | ||
|
||
// start the Ethernet connection and the server: | ||
Ethernet.begin(mac, ip); | ||
server.begin(); | ||
|
||
// initalize the data ready and chip select pins: | ||
pinMode(dataReadyPin, INPUT); | ||
pinMode(chipSelectPin, OUTPUT); | ||
|
||
Serial.begin(9600); | ||
|
||
//Configure SCP1000 for low noise configuration: | ||
writeRegister(0x02, 0x2D); | ||
writeRegister(0x01, 0x03); | ||
writeRegister(0x03, 0x02); | ||
|
||
// give the sensor and Ethernet shield time to set up: | ||
delay(1000); | ||
|
||
//Set the sensor to high resolution mode tp start readings: | ||
writeRegister(0x03, 0x0A); | ||
|
||
} | ||
|
||
void loop() { | ||
// check for a reading no more than once a second. | ||
if (millis() - lastReadingTime > 1000) { | ||
// if there's a reading ready, read it: | ||
// don't do anything until the data ready pin is high: | ||
if (digitalRead(dataReadyPin) == HIGH) { | ||
getData(); | ||
// timestamp the last time you got a reading: | ||
lastReadingTime = millis(); | ||
} | ||
} | ||
|
||
// listen for incoming Ethernet connections: | ||
listenForEthernetClients(); | ||
} | ||
|
||
|
||
void getData() { | ||
Serial.println("Getting reading"); | ||
//Read the temperature data | ||
int tempData = readRegister(0x21, 2); | ||
|
||
// convert the temperature to celsius and display it: | ||
temperature = (float)tempData / 20.0; | ||
|
||
//Read the pressure data highest 3 bits: | ||
byte pressureDataHigh = readRegister(0x1F, 1); | ||
pressureDataHigh &= 0b00000111; //you only needs bits 2 to 0 | ||
|
||
//Read the pressure data lower 16 bits: | ||
unsigned int pressureDataLow = readRegister(0x20, 2); | ||
//combine the two parts into one 19-bit number: | ||
pressure = ((pressureDataHigh << 16) | pressureDataLow) / 4; | ||
|
||
Serial.print("Temperature: "); | ||
Serial.print(temperature); | ||
Serial.println(" degrees C"); | ||
Serial.print("Pressure: " + String(pressure)); | ||
Serial.println(" Pa"); | ||
} | ||
|
||
void listenForEthernetClients() { | ||
// listen for incoming clients | ||
EthernetClient client = server.available(); | ||
if (client) { | ||
Serial.println("Got a client"); | ||
// an http request ends with a blank line | ||
boolean currentLineIsBlank = true; | ||
while (client.connected()) { | ||
if (client.available()) { | ||
char c = client.read(); | ||
// if you've gotten to the end of the line (received a newline | ||
// character) and the line is blank, the http request has ended, | ||
// so you can send a reply | ||
if (c == '\n' && currentLineIsBlank) { | ||
// send a standard http response header | ||
client.println("HTTP/1.1 200 OK"); | ||
client.println("Content-Type: text/html"); | ||
client.println(); | ||
// print the current readings, in HTML format: | ||
client.print("Temperature: "); | ||
client.print(temperature); | ||
client.print(" degrees C"); | ||
client.println("<br />"); | ||
client.print("Pressure: " + String(pressure)); | ||
client.print(" Pa"); | ||
client.println("<br />"); | ||
break; | ||
} | ||
if (c == '\n') { | ||
// you're starting a new line | ||
currentLineIsBlank = true; | ||
} else if (c != '\r') { | ||
// you've gotten a character on the current line | ||
currentLineIsBlank = false; | ||
} | ||
} | ||
} | ||
// give the web browser time to receive the data | ||
delay(1); | ||
// close the connection: | ||
client.stop(); | ||
} | ||
} | ||
|
||
|
||
//Send a write command to SCP1000 | ||
void writeRegister(byte registerName, byte registerValue) { | ||
// SCP1000 expects the register name in the upper 6 bits | ||
// of the byte: | ||
registerName <<= 2; | ||
// command (read or write) goes in the lower two bits: | ||
registerName |= 0b00000010; //Write command | ||
|
||
// take the chip select low to select the device: | ||
digitalWrite(chipSelectPin, LOW); | ||
|
||
SPI.transfer(registerName); //Send register location | ||
SPI.transfer(registerValue); //Send value to record into register | ||
|
||
// take the chip select high to de-select: | ||
digitalWrite(chipSelectPin, HIGH); | ||
} | ||
|
||
|
||
//Read register from the SCP1000: | ||
unsigned int readRegister(byte registerName, int numBytes) { | ||
byte inByte = 0; // incoming from the SPI read | ||
unsigned int result = 0; // result to return | ||
|
||
// SCP1000 expects the register name in the upper 6 bits | ||
// of the byte: | ||
registerName <<= 2; | ||
// command (read or write) goes in the lower two bits: | ||
registerName &= 0b11111100; //Read command | ||
|
||
// take the chip select low to select the device: | ||
digitalWrite(chipSelectPin, LOW); | ||
// send the device the register you want to read: | ||
int command = SPI.transfer(registerName); | ||
// send a value of 0 to read the first byte returned: | ||
inByte = SPI.transfer(0x00); | ||
|
||
result = inByte; | ||
// if there's more than one byte returned, | ||
// shift the first byte then get the second byte: | ||
if (numBytes > 1) { | ||
result = inByte << 8; | ||
inByte = SPI.transfer(0x00); | ||
result = result | inByte; | ||
} | ||
// take the chip select high to de-select: | ||
digitalWrite(chipSelectPin, HIGH); | ||
// return the result: | ||
return (result); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add dependency with LWIP lib from stm32duino (far all example)