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

Thread: Teensy++ 2.0 in Arduino, can't control PORTF

  1. #1
    Junior Member
    Join Date
    May 2019
    Posts
    7

    Teensy++ 2.0 in Arduino, can't control PORTF

    Hi all, I couldn't find any results for this, so I thought I'd ask here.

    I've been playing with this Teensy using Teensyduino, and was trying to figure out my some of my pins on PORTF weren't behaving properly. Basically, PORTF 0-3 can be toggled low or high with no trouble, but 4-7 always stay HIGH, no matter what. I've tried port manipulation, pinMode, setting as input...but they always stay high. I checked the documentation and couldn't see what was wrong here. my test code is just a switch case, testing different methods of controlling the pins, but like I said PF4-PF7 don't respond.

    Code:
    void loop() {
      // put your main code here, to run repeatedly:
      char input = Serial.read();
    
      switch (input)
      {
        case 'T':
        DDRF = 0xFF; //output
        PORTF = 0x00; //set low
        break;
    
        case 'Q':
        pinMode(42, OUTPUT); //pin 42 is PF4 according to documentation
        digitalWrite(42, LOW);
        break;
    
        case 'E':
        pinMode(42, INPUT);
        break;
    
        case 'F':
        pinMode(41, OUTPUT); //pin 41 is PF3 according to documetation
        digitalWrite(41, HIGH);
        break;
    
        case 'J':
        DDRF = 0xFF; //SET OUTPUT
        PORTF = 0xFF; //TURN ALL PINS HIGH
        break;
    
        case 'H':
        DDRF = 0x00; //SET AS INPUT
        break;
      }
    }
    None of the above do anything to the pins PF4-PF7.

    Anyone able to tell me what might be going on?
    Last edited by KurtE; 05-19-2019 at 03:20 PM. Reason: code tag

  2. #2
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,074
    Maybe check your soldering or provide a photo of your board? PF0-7 work for me with voltmeter and this little sketch
    Code:
    void setup() {
      pinMode(6, OUTPUT);
      DDRF = 0xff;  //  output mode
    }
    
    void loop() {
      digitalWrite(6, HIGH);
      PORTF = 0xff;
      delay(5000);
      digitalWrite(6, LOW);
      PORTF = 0;
      delay(5000);
    }

  3. #3
    Junior Member
    Join Date
    May 2019
    Posts
    7
    Did you check that with a Teensy++ 2.0? Also, soldering isn't an issue as it's just the Teensy in a breadboard.

    Something else I found while testing just now, is if I make a C sketch NOT in Arduino IDE, and set the PORTF = 0x00 then it actually puts all PF0-PF7 pins low like it should! So this seems to only be an issue in Arduino IDE for me. I'm running the most recent Teensyduino install and Arduino 1.8.

  4. #4
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,074
    Quote Originally Posted by jwiggams View Post
    Did you check that with a Teensy++ 2.0? Also, soldering isn't an issue as it's just the Teensy in a breadboard.
    Yep, i was testing with PJRC Teensy++2 with 1.8.8 and teensyduino 1.47-beta2.

    Did you run my little sketch and check with voltmeter?

    Maybe add Serial.println(PORTF,HEX); and Serial.printf(DDRF,HEX); to see if things are set as you expect....
    Last edited by manitou; 05-21-2019 at 08:52 PM.

  5. #5
    Junior Member
    Join Date
    May 2019
    Posts
    7
    OK, i've upgraded to 1.8.9, installed the same teensyduino version you're running, and STILL having the same issue. Again, if I use a different compiler like Atmel studio and set PORTF to 0x00 it works fine, it only does this in Arduino...which is why it's so confusing. If it did it in any other compiler I'd say its a hardware fault, but this doesn't make sense.

    I set the Serial.println as you suggested as well, and it shows DDRF shows FF as output in hex constantly, and PORTF goes FF when high and 0 when low...but these 4 pins never change. What is also interesting is that the pins stay around 3.26V constantly, whereas the other PORTF pins PF0-PF3 change from 0V to ~4.5V. Any ideas on that?

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,301
    Any chance you could show us photos of how you're testing, with clear shots of the Teensy++ 2.0 hardware and all wires?

    Hoping to clear up 2 things:

    1: Sometimes we see misunderstandings about connections that are only apparent with a photo. Seems unlikely in this case, but still...

    2: Wondering if you have a genuine Teensy or a counterfeit.

    I'm still traveling, writing this from my laptop in a hotel room without access to my workbench & tools. Returning later today, so tomorrow I can do some test on real hardware to try to understand what's going on here.

  7. #7
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,074
    Quote Originally Posted by jwiggams View Post
    What is also interesting is that the pins stay around 3.26V constantly, whereas the other PORTF pins PF0-PF3 change from 0V to ~4.5V. Any ideas on that?
    As Paul notes, may be a counterfeit. Where did you purchase? Here are approved distributors
    https://forum.pjrc.com/threads/23601...l-Distributors

  8. #8
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,301
    I tested just now with a genuine Teensy++ 2.0 and Arduino 1.8.9 with Teensyduino 1.47-beta2 running on Linux x86 64 bit. I connected a Fluke 87 multimeter between PF7 and GND.

    When I ran the used from msg #1, adding only an empty setup() function to get it to compile. Clicked Verify, then pressed the button on the Teensy++ 2.0 board. Then I selected the port and opened the serial monitor. When I type "J" and press enter, the voltage is 4.83 volts. When I type "T" and enter, the voltage is 0.007 volts.

    If there's something else I should do to try recreating the problem, please be very specific about the steps I should follow. I tried as best I could using the info on this thread and as far as I can tell, pin PF7 works fine. During one of the times it was high, I also quickly measured PF0 to PF6. All those were high as well, But I only watched PF7 actually change as I sent the commands from the serial monitor.

  9. #9
    Junior Member
    Join Date
    May 2019
    Posts
    7
    Thanks for the comments guys. After reading Paul's comment, I checked with who I got this from and found out that yes, this is a clone from Aliexpress. No wonder I've been having issues. But I think I've solved it!
    It seems that JTAG is still active on this clone. Reading through the datasheet for the AT90USB1286, PF4-7 is for JTAG, and there is a fuse that can be changed to disable it.

    I went into the "pins_teensy.c" file and added this:
    MCUCR = (1<<JTD) | (1<<IVCE) | (0<<PUD);
    MCUCR = (1<<JTD) | (0<<IVSEL) | (0<<IVCE) | (0<<PUD);

    This has successfully turned off JTAG on this clone teensy, and now PF4-7 are working as intended. Thanks everyone for the help!

Posting Permissions

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