Skip to content

Commit

Permalink
New W5x00 library for STM32F1 series
Browse files Browse the repository at this point in the history
The new library supports the W5100 and W5500 ethernet controllers. The
W5200 should work also but has not been tested yet.
  • Loading branch information
Serasidis committed Aug 23, 2015
1 parent 5dd518a commit 4d0f256
Show file tree
Hide file tree
Showing 34 changed files with 2,777 additions and 464 deletions.
37 changes: 31 additions & 6 deletions README.md
@@ -1,20 +1,45 @@
W5100 ethernet library for STM32F103 micro-controllers
W5x00 ethernet library for STM32F103 micro-controllers
----

That library has been ported from the stock Arduino **Ethernet** library, to STM32F103 microcontrollers.
That library has been ported from the **WIZnet WIZ_Ethernet_Library**, to STM32F103 microcontrollers.
The library supports **W5100** and **W5500** Ethernet controllers. The source code has been modified to support the **W5200** too, but has not been tested (yet) on a real W5200 controller.

Ported to STM32F103 on 23 Aug 2015 by **Vassilis Serasidis**

Library installation
----
Just unzip the file **Ethernet_STM-master.zip** into your Arduino IDE directory

> ...arduino\hardware\Arduino_STM32\STM32F1\libraries
and rename the folder **Ethernet_STM-master** to **Ethernet_STM**

Selecting the Ethernet type controller (W5100, W5200 or W5500)
----
For selecting among those tree chips edit the file:
`Ethernet_STM\src\utility\w5100.h`
and comment-out only the line with the chip you want to use.

By default the **W5500** ethernet chip is selected.

```
//#define W5100_ETHERNET_SHIELD // Arduino Ethenret Shield and Compatibles ...
//#define W5200_ETHERNET_SHIELD // WIZ820io, W5200 Ethernet Shield
#define W5500_ETHERNET_SHIELD // WIZ550io, ioShield series of WIZnet
```
If you edit the **w5100.h** file, save it and re-compile your sketch.

Ported to STM32F103 on 16 Jun 2015 by Vassilis Serasidis


PIN Connections
----
|W5100|STM32F103|
|W5x00|STM32F103|
|:------:|:-----:|
|SS|PA4|
|SCK|PA5|
|MISO|PA6|
|MOSI|PA7|



**DO NOT FORGET TO ADD A RESISTOR 4k7 BETWEEN RESET AND 3.3V (OR RESET AND 5V) PINS ON ETHERNET SHIELD**

![alt tag](http://www.serasidis.gr/images/w5100_shield_1.jpg)
Expand Down
@@ -1,33 +1,35 @@
/*
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
http://www.vti.fi/en/support/obsolete_products/pressure_sensors/
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
modified 12 Aug 2013
by Soohwan Kim
Modified 18 Aug 2015
by Vassilis Serasidis
=========================================================
Ported to STM32F103 on 16 Jun 2015 by Vassilis Serasidis
###### THIS EXAMPLE HAS NOT BEEN TESTED YET ######
Ported to STM32F103 on 18 Aug 2015 by Vassilis Serasidis
<---- Pinout ---->
W5100 <--> STM32F103
W5x00 <--> STM32F103
SS <--> PA4 <--> BOARD_SPI1_NSS_PIN
SCK <--> PA5 <--> BOARD_SPI1_SCK_PIN
MISO <--> PA6 <--> BOARD_SPI1_MISO_PIN
Expand All @@ -43,17 +45,21 @@

// assign a MAC address for the ethernet controller.
// fill in your address here:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};

#if defined(WIZ550io_WITH_MACADDRESS) // Use assigned MAC address of WIZ550io
;
#else
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
#endif

// assign an IP address for the controller:
IPAddress ip(192, 168, 1, 20);
IPAddress gateway(192, 168, 1, 1);
IPAddress ip(192,168,1,20);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255, 255, 255, 0);


// Initialize the Ethernet server library
// with the IP address and port you want to use
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

Expand All @@ -65,8 +71,8 @@ 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 = PA4;
const int dataReadyPin = 6;
const int chipSelectPin = 7;

float temperature = 0.0;
long pressure = 0;
Expand All @@ -77,9 +83,13 @@ void setup() {
SPI.begin();

// start the Ethernet connection and the server:
#if defined(WIZ550io_WITH_MACADDRESS) // Use assigned MAC address of WIZ550io
Ethernet.begin(ip);
#else
Ethernet.begin(mac, ip);
server.begin();
#endif

server.begin();
// initalize the data ready and chip select pins:
pinMode(dataReadyPin, INPUT);
pinMode(chipSelectPin, OUTPUT);
Expand All @@ -99,9 +109,9 @@ void setup() {

}

void loop() {
void loop() {
// check for a reading no more than once a second.
if (millis() - lastReadingTime > 1000) {
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) {
Expand All @@ -125,13 +135,13 @@ void getData() {
temperature = (float)tempData / 20.0;

//Read the pressure data highest 3 bits:
byte pressureDataHigh = readRegister(0x1F, 1);
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);
unsigned int pressureDataLow = readRegister(0x20, 2);
//combine the two parts into one 19-bit number:
pressure = ((pressureDataHigh << 16) | pressureDataLow) / 4;
pressure = ((pressureDataHigh << 16) | pressureDataLow)/4;

Serial.print("Temperature: ");
Serial.print(temperature);
Expand Down Expand Up @@ -165,13 +175,13 @@ void listenForEthernetClients() {
client.println("<br />");
client.print("Pressure: " + String(pressure));
client.print(" Pa");
client.println("<br />");
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;
Expand All @@ -183,7 +193,7 @@ void listenForEthernetClients() {
// close the connection:
client.stop();
}
}
}


//Send a write command to SCP1000
Expand All @@ -195,20 +205,20 @@ void writeRegister(byte registerName, byte registerValue) {
registerName |= 0b00000010; //Write command

// take the chip select low to select the device:
digitalWrite(chipSelectPin, LOW);
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);
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
unsigned int result = 0; // result to return

// SCP1000 expects the register name in the upper 6 bits
// of the byte:
Expand All @@ -217,22 +227,22 @@ unsigned int readRegister(byte registerName, int numBytes) {
registerName &= 0b11111100; //Read command

// take the chip select low to select the device:
digitalWrite(chipSelectPin, LOW);
digitalWrite(chipSelectPin, LOW);
// send the device the register you want to read:
int command = SPI.transfer(registerName);
int command = SPI.transfer(registerName);
// send a value of 0 to read the first byte returned:
inByte = SPI.transfer(0x00);

inByte = SPI.transfer(0x00);
result = inByte;
// if there's more than one byte returned,
// if there's more than one byte returned,
// shift the first byte then get the second byte:
if (numBytes > 1) {
if (numBytes > 1){
result = inByte << 8;
inByte = SPI.transfer(0x00);
result = result | inByte;
inByte = SPI.transfer(0x00);
result = result |inByte;
}
// take the chip select high to de-select:
digitalWrite(chipSelectPin, HIGH);
digitalWrite(chipSelectPin, HIGH);
// return the result:
return(result);
}
}
47 changes: 29 additions & 18 deletions examples/ChatServer/ChatServer.ino
@@ -1,25 +1,29 @@
/*
Chat Server
A simple server that distributes any incoming messages to all
connected clients. 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.
Using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* Analog inputs attached to pins A0 through A5 (optional)
created 18 Dec 2009
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe
modified 12 Aug 2013
by Soohwan Kim
Modified 18 Aug 2015
by Vassilis Serasidis
=========================================================
Ported to STM32F103 on 16 Jun 2015 by Vassilis Serasidis
Ported to STM32F103 on 18 Aug 2015 by Vassilis Serasidis
<---- Pinout ---->
W5100 <--> STM32F103
W5x00 <--> STM32F103
SS <--> PA4 <--> BOARD_SPI1_NSS_PIN
SCK <--> PA5 <--> BOARD_SPI1_SCK_PIN
MISO <--> PA6 <--> BOARD_SPI1_MISO_PIN
Expand All @@ -34,12 +38,15 @@
// 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 gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 0, 0);
#if defined(WIZ550io_WITH_MACADDRESS) // Use assigned MAC address of WIZ550io
;
#else
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
#endif

IPAddress ip(192,168,1, 177);
IPAddress gateway(192,168,1, 1);
IPAddress subnet(255, 255, 255, 0);


// telnet defaults to port 23
Expand All @@ -48,15 +55,19 @@ boolean alreadyConnected = false; // whether or not the client was connected pre

void setup() {
// initialize the ethernet device
#if defined(WIZ550io_WITH_MACADDRESS)
Ethernet.begin(ip, gateway, subnet);
#else
Ethernet.begin(mac, ip, gateway, subnet);
#endif
// start listening for clients
server.begin();
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}


Serial.print("Chat server address:");
Serial.println(Ethernet.localIP());
Expand All @@ -70,11 +81,11 @@ void loop() {
if (client) {
if (!alreadyConnected) {
// clead out the input buffer:
client.flush();
client.flush();
Serial.println("We have a new client");
client.println("Hello, client!");
client.println("Hello, client!");
alreadyConnected = true;
}
}

if (client.available() > 0) {
// read the bytes incoming from the client:
Expand Down

0 comments on commit 4d0f256

Please sign in to comment.