Skip to content

Added W5100S for W5100S Ethernetshield #101

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@ EthernetNoHardware LITERAL1
EthernetW5100 LITERAL1
EthernetW5200 LITERAL1
EthernetW5500 LITERAL1
EthernetW5100S LITERAL1
1 change: 1 addition & 0 deletions src/Ethernet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ EthernetLinkStatus EthernetClass::linkStatus()
EthernetHardwareStatus EthernetClass::hardwareStatus()
{
switch (W5100.getChip()) {
case 50: return EthernetW5100S;
case 51: return EthernetW5100;
case 52: return EthernetW5200;
case 55: return EthernetW5500;
Expand Down
3 changes: 2 additions & 1 deletion src/Ethernet.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ enum EthernetHardwareStatus {
EthernetNoHardware,
EthernetW5100,
EthernetW5200,
EthernetW5500
EthernetW5500,
EthernetW5100S
};

class EthernetUDP;
Expand Down
8 changes: 4 additions & 4 deletions src/EthernetServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ EthernetClient EthernetServer::available()
chip = W5100.getChip();
if (!chip) return EthernetClient(MAX_SOCK_NUM);
#if MAX_SOCK_NUM > 4
if (chip == 51) maxindex = 4; // W5100 chip never supports more than 4 sockets
if (chip == 51 || chip == 50) maxindex = 4; // W5100 chip never supports more than 4 sockets
#endif
for (uint8_t i=0; i < maxindex; i++) {
if (server_port[i] == _port) {
Expand Down Expand Up @@ -81,7 +81,7 @@ EthernetClient EthernetServer::accept()
chip = W5100.getChip();
if (!chip) return EthernetClient(MAX_SOCK_NUM);
#if MAX_SOCK_NUM > 4
if (chip == 51) maxindex = 4; // W5100 chip never supports more than 4 sockets
if (chip == 51 || chip == 50) maxindex = 4; // W5100 chip never supports more than 4 sockets
#endif
for (uint8_t i=0; i < maxindex; i++) {
if (server_port[i] == _port) {
Expand All @@ -108,7 +108,7 @@ EthernetServer::operator bool()
{
uint8_t maxindex=MAX_SOCK_NUM;
#if MAX_SOCK_NUM > 4
if (W5100.getChip() == 51) maxindex = 4; // W5100 chip never supports more than 4 sockets
if (W5100.getChip() == 51 || W5100.getChip() == 50) maxindex = 4; // W5100 chip never supports more than 4 sockets
#endif
for (uint8_t i=0; i < maxindex; i++) {
if (server_port[i] == _port) {
Expand Down Expand Up @@ -165,7 +165,7 @@ size_t EthernetServer::write(const uint8_t *buffer, size_t size)
chip = W5100.getChip();
if (!chip) return 0;
#if MAX_SOCK_NUM > 4
if (chip == 51) maxindex = 4; // W5100 chip never supports more than 4 sockets
if (chip == 51 || chip == 50) maxindex = 4; // W5100 chip never supports more than 4 sockets
#endif
available();
for (uint8_t i=0; i < maxindex; i++) {
Expand Down
4 changes: 2 additions & 2 deletions src/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ uint8_t EthernetClass::socketBegin(uint8_t protocol, uint16_t port)
chip = W5100.getChip();
if (!chip) return MAX_SOCK_NUM; // immediate error if no hardware detected
#if MAX_SOCK_NUM > 4
if (chip == 51) maxindex = 4; // W5100 chip never supports more than 4 sockets
if (chip == 51 || chip == 50) maxindex = 4; // W5100 chip never supports more than 4 sockets
#endif
//Serial.printf("W5000socket begin, protocol=%d, port=%d\n", protocol, port);
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
Expand Down Expand Up @@ -132,7 +132,7 @@ uint8_t EthernetClass::socketBeginMulticast(uint8_t protocol, IPAddress ip, uint
chip = W5100.getChip();
if (!chip) return MAX_SOCK_NUM; // immediate error if no hardware detected
#if MAX_SOCK_NUM > 4
if (chip == 51) maxindex = 4; // W5100 chip never supports more than 4 sockets
if (chip == 51 || chip == 50) maxindex = 4; // W5100 chip never supports more than 4 sockets
#endif
//Serial.printf("W5000socket begin, protocol=%d, port=%d\n", protocol, port);
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
Expand Down
53 changes: 49 additions & 4 deletions src/utility/w5100.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,29 @@ uint8_t W5100Class::init(void)
writeSnTX_SIZE(i, 0);
}
#endif
// Try W5100 last. This simple chip uses fixed 4 byte frames
// Try W5100S. Brandnew based W5100.
} else if (isW5100S()) {
CH_BASE_MSB = 0x04;
#ifdef ETHERNET_LARGE_BUFFERS
#if MAX_SOCK_NUM <= 1
SSIZE = 8192;
writeTMSR(0x03);
writeRMSR(0x03);
#elif MAX_SOCK_NUM <= 2
SSIZE = 4096;
writeTMSR(0x0A);
writeRMSR(0x0A);
#else
SSIZE = 2048;
writeTMSR(0x55);
writeRMSR(0x55);
#endif
SMASK = SSIZE - 1;
#else
writeTMSR(0x55);
writeRMSR(0x55);
#endif
// Try W5100 last. This simple chip uses fixed 4 byte frames
// for every 8 bit access. Terribly inefficient, but so simple
// it recovers from "hearing" unsuccessful W5100 or W5200
// communication. W5100 is also the only chip without a VERSIONR
Expand Down Expand Up @@ -210,7 +232,7 @@ uint8_t W5100Class::softReset(void)
uint8_t mr = readMR();
//Serial.print("mr=");
//Serial.println(mr, HEX);
if (mr == 0) return 1;
if (mr == 0 || (mr == 3 && chip == 50)) return 1;
delay(1);
} while (++count < 20);
return 0;
Expand All @@ -231,6 +253,23 @@ uint8_t W5100Class::isW5100(void)
return 1;
}

uint8_t W5100Class::isW5100S(void)
{
chip = 50;
//Serial.println("w5100.cpp: detect W5100S chip");
if (!softReset()) return 0;
writeMR(0x13);
if (readMR() != 0x13) return 0;
writeMR(0x03);
if (readMR() != 0x03) return 0;
int ver = readVERSIONR_W5100S();
//Serial.print("version=");
//Serial.println(ver);
if (ver != 81) return 0;
//Serial.println("chip is W5100S");
return 1;
}

uint8_t W5100Class::isW5200(void)
{
chip = 52;
Expand Down Expand Up @@ -275,6 +314,12 @@ W5100Linkstatus W5100Class::getLinkStatus()

if (!init()) return UNKNOWN;
switch (chip) {
case 50:
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
phystatus = readPHYCFGR_W5100S();
SPI.endTransaction();
if (phystatus & 0x01) return LINK_ON;
return LINK_OFF;
case 52:
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
phystatus = readPSTATUS_W5200();
Expand All @@ -296,7 +341,7 @@ uint16_t W5100Class::write(uint16_t addr, const uint8_t *buf, uint16_t len)
{
uint8_t cmd[8];

if (chip == 51) {
if (chip == 51 || chip == 50) {
for (uint16_t i=0; i<len; i++) {
setSS();
SPI.transfer(0xF0);
Expand Down Expand Up @@ -387,7 +432,7 @@ uint16_t W5100Class::read(uint16_t addr, uint8_t *buf, uint16_t len)
{
uint8_t cmd[4];

if (chip == 51) {
if (chip == 51 || chip == 50) {
for (uint16_t i=0; i < len; i++) {
setSS();
#if 1
Expand Down
7 changes: 5 additions & 2 deletions src/utility/w5100.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,10 @@ class W5100Class {
__GP_REGISTER16(UPORT, 0x002E); // Unreachable Port address in UDP mode (W5100 only)
__GP_REGISTER8 (VERSIONR_W5200,0x001F); // Chip Version Register (W5200 only)
__GP_REGISTER8 (VERSIONR_W5500,0x0039); // Chip Version Register (W5500 only)
__GP_REGISTER8 (VERSIONR_W5100S, 0x0080); // Chip Version Register (W5100S only)
__GP_REGISTER8 (PSTATUS_W5200, 0x0035); // PHY Status
__GP_REGISTER8 (PHYCFGR_W5500, 0x002E); // PHY Configuration register, default: 10111xxx
__GP_REGISTER8 (PHYCFGR_W5100S, 0x003C); // PHY Status


#undef __GP_REGISTER8
Expand Down Expand Up @@ -300,6 +302,7 @@ class W5100Class {
static uint8_t ss_pin;
static uint8_t softReset(void);
static uint8_t isW5100(void);
static uint8_t isW5100S(void);
static uint8_t isW5200(void);
static uint8_t isW5500(void);

Expand All @@ -313,14 +316,14 @@ class W5100Class {
static const uint16_t SMASK = 0x07FF;
#endif
static uint16_t SBASE(uint8_t socknum) {
if (chip == 51) {
if (chip == 51 || chip == 50) {
return socknum * SSIZE + 0x4000;
} else {
return socknum * SSIZE + 0x8000;
}
}
static uint16_t RBASE(uint8_t socknum) {
if (chip == 51) {
if (chip == 51 || chip == 50) {
return socknum * SSIZE + 0x6000;
} else {
return socknum * SSIZE + 0xC000;
Expand Down