Skip to content
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

FIX for Arduino LEONARDO set default SPI_SC / SS (and add configureSPI) #72

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
5 changes: 5 additions & 0 deletions UIPEthernet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,11 @@ void UIPEthernetClass::configure(IPAddress ip, IPAddress dns, IPAddress gateway,
_dnsServerAddress = dns;
}

void UIPEthernetClass::setSSPIN(uint8_t cs, uint8_t ss) {
Enc28J60Network::CONTROL_CS = cs;
Enc28J60Network::SPI_SS = ss;
}

UIPEthernetClass UIPEthernet;

/*---------------------------------------------------------------------------*/
Expand Down
3 changes: 3 additions & 0 deletions UIPEthernet.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class UIPEthernetClass
// events have been processed. Renews dhcp-lease if required.
int maintain();

static void setSSPIN(uint8_t cs, uint8_t ss);

IPAddress localIP();
IPAddress subnetMask();
IPAddress gatewayIP();
Expand All @@ -95,6 +97,7 @@ class UIPEthernetClass
static void init(const uint8_t* mac);
static void configure(IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet);


static void tick();

static boolean network_send();
Expand Down
15 changes: 12 additions & 3 deletions utility/Enc28J60Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,32 @@ extern "C" {
#endif

// set CS to 0 = active
#define CSACTIVE digitalWrite(ENC28J60_CONTROL_CS, LOW)
#define CSACTIVE digitalWrite(CONTROL_CS, LOW)
// set CS to 1 = passive
#define CSPASSIVE digitalWrite(ENC28J60_CONTROL_CS, HIGH)
#define CSPASSIVE digitalWrite(CONTROL_CS, HIGH)
//
#define waitspi() while(!(SPSR&(1<<SPIF)))

uint16_t Enc28J60Network::nextPacketPtr;
uint8_t Enc28J60Network::bank=0xff;

#if defined(__AVR_ATmega32U4__) // LEONARDO
uint8_t Enc28J60Network::CONTROL_CS = 10;
uint8_t Enc28J60Network::SPI_SS = 10;
#else
uint8_t Enc28J60Network::CONTROL_CS = SS;
uint8_t Enc28J60Network::SPI_SS = SS;
#endif


struct memblock Enc28J60Network::receivePkt;

void Enc28J60Network::init(uint8_t* macaddr)
{
MemoryPool::init(); // 1 byte in between RX_STOP_INIT and pool to allow prepending of controlbyte
// initialize I/O
// ss as output:
pinMode(ENC28J60_CONTROL_CS, OUTPUT);
pinMode(CONTROL_CS, OUTPUT);
CSPASSIVE; // ss=0
//
pinMode(SPI_MOSI, OUTPUT);
Expand Down
10 changes: 8 additions & 2 deletions utility/Enc28J60Network.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@

#include "mempool.h"

#define ENC28J60_CONTROL_CS SS
//#define ENC28J60_CONTROL_CS 10
#define SPI_MOSI MOSI
#define SPI_MISO MISO
#define SPI_SCK SCK
#define SPI_SS SS
//#define SPI_SS 10

#define UIP_RECEIVEBUFFERHANDLE 0xff




//#define ENC28J60DEBUG

/*
Expand Down Expand Up @@ -70,6 +73,9 @@ class Enc28J60Network : public MemoryPool
friend void enc28J60_mempool_block_move_callback(memaddress,memaddress,memaddress);

public:

static uint8_t CONTROL_CS;
static uint8_t SPI_SS;

uint8_t getrev(void);
void powerOn();
Expand Down