Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 18 of 18

Thread: ethernet issues with teensy 2.0 & arduino >1.0.1

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    3

    ethernet issues with teensy 2.0 & arduino >1.0.1

    Hello.

    i'm upgrading my arduino environment to latest version and im running into some issues.
    i have one teensy 2.0 board with the WIZ812 adapter board and the wiz ethernet module.

    if i use arduino 1.0.0 and compile my project ethernet access works, the program can get dhcp address and so on.
    but if i compile the same project with arduino 1.0.1 or 1.0.3 (teensyduino is applied to all 3 of my versions of arduino) ethernet doesnt work.
    even the simple samples like DhcpAddressPrinter fails to get any dhcp respons.

    i have also checked with wireshark on the same subnet and no dhcp broadcasts is sent out when it is compiled under arduino 1.0.1 or 1.0.3
    any idea whats wrong or advice for troubleshooting this?

    clearly the hardware setup is working since 1.0.0 of arduino works.

  2. #2
    Junior Member
    Join Date
    Jan 2013
    Posts
    3
    FYI the ethernet module works just fine in a teensy++ 2.0 with any of the 3 versions of arduino.

  3. #3
    Junior Member
    Join Date
    Feb 2013
    Posts
    7
    Just worked with Paul about this one. I can verify that Paul has fixed the issue with this (using teensyduino 1.12 and arduino 1.01 - 1.03). Paul has stated that he will be releasing the fix in the next version of teensyduino. I would assume that he will issue a 1.13 version of teensyduino with the fix

  4. #4
    Junior Member
    Join Date
    Jan 2013
    Posts
    3
    nice, i had almost given up on getting it to work again.
    looking forward to the next version.

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,681
    If you want the fix now, just copy this file to libraries/Ethernet/utility
    Attached Files Attached Files

  6. #6
    Senior Member Epyon's Avatar
    Join Date
    Apr 2013
    Location
    Belgium
    Posts
    443
    It seems a similar problem occurs on the Teensy 3.0 in combination with Arduino 1.0.4. When compiling a sketch that uses DHCP (Ethernet.begin(mac)), e.g. DnsWebClient, the IDE throws the following exception:
    Code:
    Ethernet\Ethernet.cpp.o: In function `EthernetClass::begin(unsigned char*)':
    C:\Apps\arduino-1.0.4\libraries\Ethernet/Ethernet.cpp:13: undefined reference to `__cxa_guard_acquire'
    C:\Apps\arduino-1.0.4\libraries\Ethernet/Ethernet.cpp:13: undefined reference to `__cxa_guard_release'
    collect2.exe: error: ld returned 1 exit status
    When providing a static ip (Ethernet.begin(mac, ip)) the sketch compiles just fine.

    When selecting Teensy 2.0 as a target, the DHCP sketch does compile.

  7. #7
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,681
    Would you believe I just recently (within the last few days) worked on this and another Ethernet bug, in preparation for the upcoming Teensyduino 1.14 release?

    Here are the files. mk20dx128.c goes into hardware/teensy/cores/teensy3. util.h goes into libraries/Ethernet.
    Attached Files Attached Files
    Last edited by PaulStoffregen; 04-10-2013 at 07:01 PM.

  8. #8
    Senior Member Epyon's Avatar
    Join Date
    Apr 2013
    Location
    Belgium
    Posts
    443
    You're unbelievable, Paul . It compiles without a hitch now. Can't yet test in on hardware because i left my board at work, but i'm sure it'll do just fine now.

    Seeing how the support on the Teensy is often much better than on Arduino, i just might shift all my prototyping to this platform .

  9. #9
    Senior Member Epyon's Avatar
    Join Date
    Apr 2013
    Location
    Belgium
    Posts
    443
    So i tested it on my Teensy 3.0 board, and while the Ethernet library now seems to function quite properly with DHCP and DNS, the Teensy won't boot when using it together with the SD library. It compiles just fine, throws no errors, but refuses to output any messages over serial (which i use as a debugging tool). Even with the plain example code, expanded with the SD code.

    Code:
    #include <SPI.h>
    #include <Ethernet.h>
    #include <SD.h>
    
    File myFile;
    const int chipSelect = 9;
    byte mac[] = {  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
    char serverName[] = "www.google.com";
    
    EthernetClient client;
    
    void setup() {
      Serial.begin(9600);
       while (!Serial) {
      }
      pinMode(10, OUTPUT);  
      if (!SD.begin(chipSelect)) {
        Serial.println("initialization failed!");
        return;
      }
      Serial.println("initialization done.");
      // start the Ethernet connection:
      if (Ethernet.begin(mac) == 0) {
        Serial.println("Failed to configure Ethernet using DHCP");
        // no point in carrying on, so do nothing forevermore:
        while(true);
      }
      // give the Ethernet shield a second to initialize:
      delay(1000);
      Serial.println("connecting...");
    
      // if you get a connection, report back via serial:
      
      if (client.connect(serverName, 80)) {
        Serial.println("connected");
        // Make a HTTP request:
        client.println("GET /search?q=arduino HTTP/1.0");
        client.println();
      } 
      else {
        // kf you didn't get a connection to the server:
        Serial.println("connection failed");
      }
    }
    
    //here comes rest of the code
    However when i put the following lines in comments, it does execute properly.
    Code:
      if (!SD.begin(chipSelect)) {
        Serial.println("initialization failed!");
        return;
      }
    Could it be something to do with the chipselect pin? When using just the SD library on the same CS pin, it does execute properly though.

  10. #10
    Senior Member
    Join Date
    Mar 2013
    Posts
    126
    what is the pinMode(10,OUTPUT); intended to do?
    Did you mean pinMode(chipSelect, OUTPUT) ?

  11. #11
    Senior Member
    Join Date
    Mar 2013
    Posts
    126
    Thanks Paul. I was able to confirm that our OSC library (oscuino) works with the Wiznet/Teensy 3.0 combination.

  12. #12
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,681
    Thanks. I've tested the Wiznet module and the SD adaptor, but not both at the same time with Teensy 3.0.

    Will do it soon....

  13. #13
    Senior Member Epyon's Avatar
    Join Date
    Apr 2013
    Location
    Belgium
    Posts
    443
    Quote Originally Posted by adrianfreed View Post
    what is the pinMode(10,OUTPUT); intended to do?
    Did you mean pinMode(chipSelect, OUTPUT) ?
    Pin 10 needs to be set as output to make the Arduino SD library work, even if you don't use it.

    Quote Originally Posted by PaulStoffregen View Post
    Thanks. I've tested the Wiznet module and the SD adaptor, but not both at the same time with Teensy 3.0.

    Will do it soon....
    I used the Arduino Ethernetshield Rev 3 (Wiz5100), with the Ethernet CS wired to Teensy pin 10 (CS0) and the SD card CS wired to Teensy pin 9 (CS1). If i wire the SD card CS to pin 6, the Teensy seems to boot (i get feedback over serial) and the SD card gets initialized, but it hangs on initializing the Ethernet connection.

  14. #14
    Senior Member Epyon's Avatar
    Join Date
    Apr 2013
    Location
    Belgium
    Posts
    443
    I did some more tinkering today, and the behavior of the Teensy is very erratic. By commenting out the pinMode(10,OUTPUT) line and connecting the SD card CS to pin 6 i got the board to boot properly, activate it's Ethernet connection, print it's IP address and write/read something to the SD card. However, the DHCP provided IP the board reported was 192.0.0.0, which is impossible, and it's MAC also didn't show up on my routers DHCP clients. So it probably didn't actually receive an IP at all.

    The most problematic thing, however, is the fact that the Teensy sometimes does boot, but most of the times it doesn't. You upload the compiled code (i use the Arduino IDE), the Teensy loader reports that the reboot is ok, but the Teensy doesn't do a thing and the serial output remains idle. Sometimes, by unplugging and replugging the Teensy and uploading the code anew, it does boot properly, but when uploading new code (even with no difference in the code) the board hangs again.

    I did found out that unplugging and replugging the Teensy is necessary when using Ethernet, because a reset of the Teensy doesn't reset the Wiznet 5100 chip. But still, it takes a lot of replugging before the Teensy actually boots properly.

  15. #15
    Senior Member Epyon's Avatar
    Join Date
    Apr 2013
    Location
    Belgium
    Posts
    443
    Finally got around hooking up my Teensy 3.0 to the scope and checking how the CS pins behave. So when I execute the following sketch, which reads a file from the SD card and uploads it to a webserver, ..
    Code:
    #include <SD.h>
    #include <SPI.h>
    #include <Ethernet.h>
    
    
    File fh;
    EthernetClient dclient;
    byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x58, 0x67 }; 
    IPAddress ip( 192, 168, 1, 123 );    
    IPAddress gateway( 192, 168, 1, 1 );
    IPAddress subnet( 255, 255, 255, 0 );
    IPAddress server( xxx,xxx,xxx,xxx );
      
    void setup(){
      Serial.begin(9600);
      pinMode(10,OUTPUT);
      digitalWrite(10,HIGH);
    
      if(SD.begin(9) == 0) //change to 4 when using Arduino
      {
        Serial.println(F("SD init fail"));          
      }
    
      Ethernet.begin(mac, ip, gateway, gateway, subnet);
      delay(2000);
      Serial.println(F("Ready."));
    }
    
    void loop(){
      char fileName[14] = "test.txt"; 
    
      if (dclient.connect(server, 80)) {
        dclient.print(F("PUT /app/arduino/put.php HTTP/1.1\nHost: ")); //Host is mandatory in HTTP 1.1 and resolves issues when uploading to a server with more than one hostnames
        dclient.print(serverName);
        dclient.print(F("\nContent-Length: 5794 \nConnection: close\n\n")); //Content-Length is mandatory in HTTP 1.1 and must be at least the size of the uploaded data
        fh = SD.open(fileName,FILE_READ);
        byte clientBuf[64];
        int clientCount = 0;
        Serial.println(F("Writing"));
        while(fh.available())
        {
          clientBuf[clientCount] = fh.read();
          clientCount++;
      
          if(clientCount > 63)
          {
            dclient.write(clientBuf,64);
            clientCount = 0;
          }
        }
      
        if(clientCount > 0) dclient.write(clientBuf,clientCount);
          }
        dclient.stop();
        fh.close();
      for(;;)
            ;
      }
    ..on a Arduino Uno with an Ethernet shield, I get the following:

    Click image for larger version. 

Name:	TEK00004.PNG 
Views:	167 
Size:	5.2 KB 
ID:	467
    Yellow: Wiznet CS
    Blue: SD card CS

    But the same sketch running on the Teensy gives me:

    Click image for larger version. 

Name:	TEK00007.PNG 
Views:	175 
Size:	4.3 KB 
ID:	468
    On the same timebase for comparison, but even when viewed on a smaller timebase, it doesn't seem the SD card CS toggles on/off. Also, the Teensy doesn't even execute the sketch, it just gets stuck at the setup() loop.

    Looks like the SPI library used by Teensyduino doesn't handle multiple slaves really well?

  16. #16
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,681
    I built a board to test and I can confirm I have reproduced the bug here.

    Click image for larger version. 

Name:	ethernet_and_sd_test.jpg 
Views:	167 
Size:	65.6 KB 
ID:	469

    I probably will not be able to really investigate and fix this until next week (after Maker Faire). But I wanted to at least let you know I will work on this soon, especially now that I have this board sitting on my desk!

    Here's the code I'm using.... (does not depend on specific network settings or a private server)

    Code:
    #include <SD.h>
    #include <SPI.h>
    #include <Ethernet.h>
    
    byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x58, 0x67 }; 
    char serverName[] = "www.pjrc.com";
    EthernetClient client;
    
    void setup() {
     // Open serial communications and wait for port to open:
      Serial.begin(9600);
      
      pinMode(4, OUTPUT);
      digitalWrite(4, HIGH);   // SD card CS on pin 4
      pinMode(10, OUTPUT);
      digitalWrite(10, HIGH);  // Ethernet CS on pin 10
      
      while (!Serial) ; // wait arduino serial monitor
      Serial.println("Ethernet + SD Test");
    
      if (0) {
        if (SD.begin(4)) {
          Serial.println("SD init ok");
        } else {
          Serial.println("SD init failed");
        }
      }
    
      // start the Ethernet connection:
      if (Ethernet.begin(mac)) {
        Serial.print("Ethernet ok.  Our IP number is ");
        Serial.println(Ethernet.localIP());
      } else {
        Serial.println("Failed to configure Ethernet using DHCP");
        while(true);
      }
      // give the Ethernet shield a second to initialize:
      delay(1000);
      Serial.println("connecting...");
      
      if (client.connect(serverName, 80)) {
        Serial.print("connected to ");
        Serial.println(serverName);
        // Make a HTTP request:
        client.println("HEAD / HTTP/1.1");
        client.print("Host: ");
        client.println(serverName);
        client.println("Connection: close");
        client.println();
        while (client.connected()) {
          if (client.available()) {
            char c = client.read();
            Serial.print(c);
          }
        }
        client.stop();
      } else {
        Serial.println("connection failed");
      }
    }
    
    void loop() {
    }

  17. #17
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,681
    I believe I've found a workaround for this bug. Please give this file a try. It goes into libraries/SD/utility.

    Please let me know is this solves the problem you're seeing?
    Attached Files Attached Files

  18. #18
    Senior Member Epyon's Avatar
    Join Date
    Apr 2013
    Location
    Belgium
    Posts
    443
    Quote Originally Posted by PaulStoffregen View Post
    I believe I've found a workaround for this bug. Please give this file a try. It goes into libraries/SD/utility.

    Please let me know is this solves the problem you're seeing?
    Works like a charm. Thx a bunch, Paul!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •