Jump to content
reaper7

[Energia Library] StellarPad EtherCard (enc28j60) library

Recommended Posts

I have been trying to run the dhcp sample code (v6 library) with Stellarpad but code never seems to go beyond "ether.begin" statement. I am using the default SPI bus 2 connections as outlined above. Any suggestions where I should start looking? I have twice verified that the connections are correct. The ENC28J60 modules does work with an Arduino.

Share this post


Link to post
Share on other sites

Which example? testDHCP or getDHCPandDNS ?

I check it tonight...

 

do you tried the previous version of the libraries (<=0.4)?

maybe some is wrong with latest "DHCP fix"...

Share this post


Link to post
Share on other sites

For me getDHCPandDNS working OK:

[getDHCPandDNS]                                                       
My IP: 192.168.0.9                                                    
GW IP: 192.168.0.254                                                  
DNS IP: 192.168.0.254                                                 
Server: 173.194.113.72                                                
                                                                      
>>> REQ                                                               
<<< reply 118 ms                                                      
HTTP/1.0 301 Moved Permanently                                        
Location: http://www.google.com/foo/bar                               
Content-Type: text/html; charset=UTF-8                                
X-Content-Type-Options: nosniff                                       
Date: Wed, 22 May 2013 16:44:02 GMT                                   
Expires: Fri, 21 Jun 2013 16:44:02 GMT                                
Cache-Control: public, max-age=2592000                                
Server: sffe                                                          
Content-Length: 226
...

and testDHCP too:

[testDHCP]                                                            
MAC: 0:4F:49:0:0:4                                                    
Setting up DHCP                                                       
My IP: 192.168.0.9                                                    
Netmask: 255.255.255.0                                                
GW IP: 192.168.0.254                                                  
DNS IP: 192.168.0.254 

so...

1. You must check if You have latest files for SPI lib and all the latest core files

2. or maybe try to change MOSI with MISO

Share this post


Link to post
Share on other sites

Anybody else try this out?  I overwhelmed my home routers and freaked out one at work as well, just using the getDHCPandDNS example.  The tech at work said that if there's too much activity on a port - the routers are configured to shut it off.  Saw some reports that EtherCard tends to have that problem.

Share this post


Link to post
Share on other sites

attachicon.gifEtherCard_v04.zip

before "Implemented a simple UDP listening server, that listens for packets on ports and triggers callbacks"

 

BTW - I don't see any abnormal DHCP broadcast storm on v0.6

I'll test it out.  What I found searching online was that only some hardware had problems with EtherCard.  What did you use for monitoring?  It would be nice to set something up at home to monitor what's going on.

 

I may unfortunately not be able to use this for my intended project - I'm trying to query graph.facebook.com - and apparently they're splitting packets so I only get a partial response.

Share this post


Link to post
Share on other sites

for capture packets I use tcpdump on router or wireshark on desktop, second method is router LEDs :)

This is my dump from tcpdump:

root@onmyhouse:~# tcpdump -vvv -lenx -i br-lan -s 1500 port 67 or port 68
tcpdump: listening on br-lan, link-type EN10MB (Ethernet), capture size 1500 bytes
20:11:32.053660 00:4f:49:00:00:04 > ff:ff:ff:ff:ff:ff, ethertype IPv4 (0x0800), length 312: (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto UDP (17), length 298)
    0.0.0.0.68 > 255.255.255.255.67: [udp sum ok] BOOTP/DHCP, Request from 00:4f:49:00:00:04, length 270, xid 0x9b070000, Flags [none] (0x0000)
          Client-Ethernet-Address 00:4f:49:00:00:04
          Vendor-rfc1048 Extensions
            Magic Cookie 0x63825363
            DHCP-Message Option 53, length 1: Discover
            Client-ID Option 61, length 7: ether 00:4f:49:00:00:04
            Hostname Option 12, length 10: "Stellar-04"
            Parameter-Request Option 55, length 3:
              Subnet-Mask, Default-Gateway, Domain-Name-Server
            END Option 255, length 0
        0x0000:  4500 012a 0000 4000 4011 39c4 0000 0000
        0x0010:  ffff ffff 0044 0043 0116 c1b4 0101 0600
        0x0020:  9b07 0000 0000 0000 0000 0000 0000 0000
        0x0030:  0000 0000 0000 0000 004f 4900 0004 0000
        0x0040:  0000 0000 0000 0000 0000 0000 0000 0000
        0x0050:  0000 0000 0000 0000 0000 0000 0000 0000
        0x0060:  0000 0000 0000 0000 0000 0000 0000 0000
        0x0070:  0000 0000 0000 0000 0000 0000 0000 0000
        0x0080:  0000 0000 0000 0000 0000 0000 0000 0000
        0x0090:  0000 0000 0000 0000 0000 0000 0000 0000
        0x00a0:  0000 0000 0000 0000 0000 0000 0000 0000
        0x00b0:  0000 0000 0000 0000 0000 0000 0000 0000
        0x00c0:  0000 0000 0000 0000 0000 0000 0000 0000
        0x00d0:  0000 0000 0000 0000 0000 0000 0000 0000
        0x00e0:  0000 0000 0000 0000 0000 0000 0000 0000
        0x00f0:  0000 0000 0000 0000 0000 0000 0000 0000
        0x0100:  0000 0000 0000 0000 6382 5363 3501 013d
        0x0110:  0701 004f 4900 0004 0c0a 5374 656c 6c61
        0x0120:  722d 3034 3703 0103 06ff
20:11:32.057591 00:1d:0f:xx:xx:xx > 00:4f:49:00:00:04, ethertype IPv4 (0x0800), length 342: (tos 0x0, ttl 64, id 21903, offset 0, flags [none], proto UDP (17), length 328)
    192.168.0.254.67 > 192.168.0.9.68: [udp sum ok] BOOTP/DHCP, Reply, length 300, xid 0x9b070000, Flags [none] (0x0000)
          Your-IP 192.168.0.9
          Server-IP 192.168.0.254
          Client-Ethernet-Address 00:4f:49:00:00:04
          Vendor-rfc1048 Extensions
            Magic Cookie 0x63825363
            DHCP-Message Option 53, length 1: Offer
            Server-ID Option 54, length 4: 192.168.0.254
            Lease-Time Option 51, length 4: 28800
            RN Option 58, length 4: 14400
            RB Option 59, length 4: 25200
            Subnet-Mask Option 1, length 4: 255.255.255.0
            BR Option 28, length 4: 192.168.0.255
            Default-Gateway Option 3, length 4: 192.168.0.254
            Domain-Name-Server Option 6, length 4: 192.168.0.254
            END Option 255, length 0
            PAD Option 0, length 0, occurs 8
        0x0000:  4500 0148 558f 0000 4011 a1be c0a8 00fe
        0x0010:  c0a8 0009 0043 0044 0134 2df8 0201 0600
        0x0020:  9b07 0000 0000 0000 0000 0000 c0a8 0009
        0x0030:  c0a8 00fe 0000 0000 004f 4900 0004 0000
        0x0040:  0000 0000 0000 0000 0000 0000 0000 0000
        0x0050:  0000 0000 0000 0000 0000 0000 0000 0000
        0x0060:  0000 0000 0000 0000 0000 0000 0000 0000
        0x0070:  0000 0000 0000 0000 0000 0000 0000 0000
        0x0080:  0000 0000 0000 0000 0000 0000 0000 0000
        0x0090:  0000 0000 0000 0000 0000 0000 0000 0000
        0x00a0:  0000 0000 0000 0000 0000 0000 0000 0000
        0x00b0:  0000 0000 0000 0000 0000 0000 0000 0000
        0x00c0:  0000 0000 0000 0000 0000 0000 0000 0000
        0x00d0:  0000 0000 0000 0000 0000 0000 0000 0000
        0x00e0:  0000 0000 0000 0000 0000 0000 0000 0000
        0x00f0:  0000 0000 0000 0000 0000 0000 0000 0000
        0x0100:  0000 0000 0000 0000 6382 5363 3501 0236
        0x0110:  04c0 a800 fe33 0400 0070 803a 0400 0038
        0x0120:  403b 0400 0062 7001 04ff ffff 001c 04c0
        0x0130:  a800 ff03 04c0 a800 fe06 04c0 a800 feff
        0x0140:  0000 0000 0000 0000
20:11:32.061967 00:4f:49:00:00:04 > ff:ff:ff:ff:ff:ff, ethertype IPv4 (0x0800), length 324: (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto UDP (17), length 310)
    192.168.0.9.68 > 255.255.255.255.67: [udp sum ok] BOOTP/DHCP, Request from 00:4f:49:00:00:04, length 282, xid 0x9b070000, Flags [none] (0x0000)
          Client-Ethernet-Address 00:4f:49:00:00:04
          Vendor-rfc1048 Extensions
            Magic Cookie 0x63825363
            DHCP-Message Option 53, length 1: Request
            Client-ID Option 61, length 7: ether 00:4f:49:00:00:04
            Hostname Option 12, length 10: "Stellar-04"
            Requested-IP Option 50, length 4: 192.168.0.9
            Server-ID Option 54, length 4: 192.168.0.254
            Parameter-Request Option 55, length 3:
              Subnet-Mask, Default-Gateway, Domain-Name-Server
            END Option 255, length 0
        0x0000:  4500 0136 0000 4000 4011 7906 c0a8 0009
        0x0010:  ffff ffff 0044 0043 0122 148a 0101 0600
        0x0020:  9b07 0000 0000 0000 0000 0000 0000 0000
        0x0030:  0000 0000 0000 0000 004f 4900 0004 0000
        0x0040:  0000 0000 0000 0000 0000 0000 0000 0000
        0x0050:  0000 0000 0000 0000 0000 0000 0000 0000
        0x0060:  0000 0000 0000 0000 0000 0000 0000 0000
        0x0070:  0000 0000 0000 0000 0000 0000 0000 0000
        0x0080:  0000 0000 0000 0000 0000 0000 0000 0000
        0x0090:  0000 0000 0000 0000 0000 0000 0000 0000
        0x00a0:  0000 0000 0000 0000 0000 0000 0000 0000
        0x00b0:  0000 0000 0000 0000 0000 0000 0000 0000
        0x00c0:  0000 0000 0000 0000 0000 0000 0000 0000
        0x00d0:  0000 0000 0000 0000 0000 0000 0000 0000
        0x00e0:  0000 0000 0000 0000 0000 0000 0000 0000
        0x00f0:  0000 0000 0000 0000 0000 0000 0000 0000
        0x0100:  0000 0000 0000 0000 6382 5363 3501 033d
        0x0110:  0701 004f 4900 0004 0c0a 5374 656c 6c61
        0x0120:  722d 3034 3204 c0a8 0009 3604 c0a8 00fe
        0x0130:  3703 0103 06ff
20:11:32.070796 00:1d:0f:xx:xx:xx > 00:4f:49:00:00:04, ethertype IPv4 (0x0800), length 342: (tos 0x0, ttl 64, id 21904, offset 0, flags [none], proto UDP (17), length 328)
    192.168.0.254.67 > 192.168.0.9.68: [udp sum ok] BOOTP/DHCP, Reply, length 300, xid 0x9b070000, Flags [none] (0x0000)
          Your-IP 192.168.0.9
          Server-IP 192.168.0.254
          Client-Ethernet-Address 00:4f:49:00:00:04
          Vendor-rfc1048 Extensions
            Magic Cookie 0x63825363
            DHCP-Message Option 53, length 1: ACK
            Server-ID Option 54, length 4: 192.168.0.254
            Lease-Time Option 51, length 4: 28800
            RN Option 58, length 4: 14400
            RB Option 59, length 4: 25200
            Subnet-Mask Option 1, length 4: 255.255.255.0
            BR Option 28, length 4: 192.168.0.255
            Default-Gateway Option 3, length 4: 192.168.0.254
            Domain-Name-Server Option 6, length 4: 192.168.0.254
            END Option 255, length 0
            PAD Option 0, length 0, occurs 8
        0x0000:  4500 0148 5590 0000 4011 a1bd c0a8 00fe
        0x0010:  c0a8 0009 0043 0044 0134 2af8 0201 0600
        0x0020:  9b07 0000 0000 0000 0000 0000 c0a8 0009
        0x0030:  c0a8 00fe 0000 0000 004f 4900 0004 0000
        0x0040:  0000 0000 0000 0000 0000 0000 0000 0000
        0x0050:  0000 0000 0000 0000 0000 0000 0000 0000
        0x0060:  0000 0000 0000 0000 0000 0000 0000 0000
        0x0070:  0000 0000 0000 0000 0000 0000 0000 0000
        0x0080:  0000 0000 0000 0000 0000 0000 0000 0000
        0x0090:  0000 0000 0000 0000 0000 0000 0000 0000
        0x00a0:  0000 0000 0000 0000 0000 0000 0000 0000
        0x00b0:  0000 0000 0000 0000 0000 0000 0000 0000
        0x00c0:  0000 0000 0000 0000 0000 0000 0000 0000
        0x00d0:  0000 0000 0000 0000 0000 0000 0000 0000
        0x00e0:  0000 0000 0000 0000 0000 0000 0000 0000
        0x00f0:  0000 0000 0000 0000 0000 0000 0000 0000
        0x0100:  0000 0000 0000 0000 6382 5363 3501 0536
        0x0110:  04c0 a800 fe33 0400 0070 803a 0400 0038
        0x0120:  403b 0400 0062 7001 04ff ffff 001c 04c0
        0x0130:  a800 ff03 04c0 a800 fe06 04c0 a800 feff
        0x0140:  0000 0000 0000 0000
4 packets captured
4 packets received by filter
0 packets dropped by kernel

 

this is only 4 packets (2 from stella, 2 from router) - thats all, less than 1 sec and stella have IP

 

Share this post


Link to post
Share on other sites

Hi,

 

I'm meeting troubles with your library, if I try to compile any example provided, I get this errors :

 

C:\Users\Batto\SkyDrive\Boulot\energia-0101E0011\hardware\lm4f\libraries\EtherCard\enc28j60.cpp: In static member function 'static void ENC28J60::initSPI()':
C:\Users\Batto\SkyDrive\Boulot\energia-0101E0011\hardware\lm4f\libraries\EtherCard\enc28j60.cpp:270:27: error: no matching function for call to 'SPIClass::begin(uint8_t&)'
C:\Users\Batto\SkyDrive\Boulot\energia-0101E0011\hardware\lm4f\libraries\EtherCard\enc28j60.cpp:270:27: note: candidate is:
In file included from C:\Users\Batto\SkyDrive\Boulot\energia-0101E0011\hardware\lm4f\libraries\EtherCard\enc28j60.cpp:15:0:
C:\Users\Batto\SkyDrive\Boulot\energia-0101E0011\hardware\lm4f\libraries\SPI/SPI.h:42:8: note: void SPIClass::begin()
C:\Users\Batto\SkyDrive\Boulot\energia-0101E0011\hardware\lm4f\libraries\SPI/SPI.h:42:8: note:   candidate expects 0 arguments, 1 provided
C:\Users\Batto\SkyDrive\Boulot\energia-0101E0011\hardware\lm4f\libraries\EtherCard\enc28j60.cpp: In function 'void xferSPI(uint8_t)':
C:\Users\Batto\SkyDrive\Boulot\energia-0101E0011\hardware\lm4f\libraries\EtherCard\enc28j60.cpp:285:54: error: no matching function for call to 'SPIClass::transfer(uint8_t&, uint8_t&, int)'
C:\Users\Batto\SkyDrive\Boulot\energia-0101E0011\hardware\lm4f\libraries\EtherCard\enc28j60.cpp:285:54: note: candidate is:
In file included from C:\Users\Batto\SkyDrive\Boulot\energia-0101E0011\hardware\lm4f\libraries\EtherCard\enc28j60.cpp:15:0:
C:\Users\Batto\SkyDrive\Boulot\energia-0101E0011\hardware\lm4f\libraries\SPI/SPI.h:52:11: note: uint8_t SPIClass::transfer(uint8_t)
C:\Users\Batto\SkyDrive\Boulot\energia-0101E0011\hardware\lm4f\libraries\SPI/SPI.h:52:11: note:   candidate expects 1 argument, 3 provided
I seems to have some conflicts between EtherCard and SPI. And if I look into EtherCard I don't think it's correct :
static void xferSPI (uint8_t data) {
SPDR = ENCSPI.transfer(selectPin, data, SPI_CONTINUE);
}
 
and 
 
ENCSPI.setModule(SPImodule);
    ENCSPI.begin(selectPin);
    ENCSPI.setClockDivider(SPI_SPEED);
    delay(50);
It's like you wanted to allow the user to choose between soft and hard SPI. So without wanting to understand the library entierly, I changed to :
 
static void xferSPI (uint8_t data) {


SPDR = ENCSPI.transfer(data);
}


void ENC28J60::initSPI () {
    //pinMode(selectPin, OUTPUT);
    //digitalWrite(selectPin, HIGH);
    ENCSPI.setModule(SPImodule);
    
ENCSPI.begin();
    ENCSPI.setClockDivider(SPI_SPEED);
    delay(50);
}

And the compilation runs well. But accidentally I wire the 3.3V of the ENC to StellarPad VBUS ... And now even if I wire it to the 3.3V it's still getting hot so I think I burned it ... And I can't tell you if my modifications are OK

Share this post


Link to post
Share on other sites

You are using a new energia with newest concept of spi library without SPI_CONTINUE and without "automatic" control CE signal.

 

Try to temporary replace (for tests) oryginal SPI.cpp and SPI.h from \hardware\lm4f\libraries\SPI 

with this:

http://forum.stellarisiti.com/topic/620-two-spi-modules/#entry3346

or this:

http://forum.stellarisiti.com/topic/675-solved%C2%A0launchpad-stellaris-on-energia-miso-erratic-behaviour-on-spi0-and-spi3/#entry3462

 

 

P.S. sorry but I don't have a time to improve enc library to the new version of spi lib :(

I also use the new energia but with old spi library for compatibility :)

Share this post


Link to post
Share on other sites

no, because enc lib have cut  "enableChip" function which was realized by the old versions of the spi library.

In new/current spi library "enable or disable" spi slave device was given to the user implementation.

In this case must be realized by enc library.

 

for me you must additional uncomment in ENC28J60::initSPI:

    pinMode(selectPin, OUTPUT);
    digitalWrite(selectPin, HIGH);

uncomment:

static void enableChip () {
    digitalWrite(selectPin, LOW);
}

and add all calls "enableChip();" like in source file https://github.com/jcw/ethercard/blob/master/enc28j60.cpp

in readOp l.288, writeOp l.299, readBuf l.306 , writeBuf l.316

 

but I have not tested these changes!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×