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

Thread: Teensy 3 as AVR ISP programmer?

  1. #1

    Teensy 3 as AVR ISP programmer?

    Has anyone succeeded in using the emulated SPI code to run the AVR-ISP program in the arduino examples directory on a teensy 3?

    I'm trying to program a ATMEGA328P-PU and I'm getting the following:


    Code:
    > /usr/local/CrossPack-AVR/bin/avrdude -c arduino -p m328p -P /dev/tty.usbmodem12341 -b 19200
    avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x14
    avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x10
    avrdude: stk500_initialize(): (b) protocol error, expect=0x10, resp=0x01
    avrdude: initialization failed, rc=-1
             Double check connections and try again, or use -F to override
             this check.
    avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x10
    avrdude done.  Thank you.
    I've made some slight changes to the programmer source (attached) mostly just to move the SCK to pin 14 so I can see the LED blink.

    Connections are as follows:

    Teensy ATMEGA
    5V <-> 7,20,21
    GND <-> 8,22
    11 (DO) <-> 17
    12 (DI) <-> 18
    14 (SCK) <-> 19

    I've tried using 3.3V as well, but I think because I'm using a 16Mhz oscillator that I need 5V. Right? Maybe I need a resistor on DI? I'm really unfamiliar with AVR. Is there some way I can verify the connections? I haven't connected reset. I assume this is equivalent to powercycling the chip? Or is it needed for programming?

    This is probably something dumb I'm doing...

    Thanks for any suggestions,

    -c
    Attached Files Attached Files

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,314
    Teensy 3.0's SCK is pin 13, not pin 14.

    Power the AVR from 3.3 volts. Make sure it has a crystal connected (the frequency doesn't matter much).

    Connect the reset signal.

    If that doesn't work, please post again and I'll give it a try here.

  3. #3
    Junior Member
    Join Date
    May 2013
    Posts
    2
    I am trying to do pretty much the same thing, but I'm not having much luck either. I double and triple checked the connections, but I still can't get it to program. When trying to program it with avrdude, it says Invalid device signature. When running avrdude in verbose mode, I get the device signature 0x000000. I presume this means there is something wrong with the connections to the chip?

    I am using the following connections:
    Teensy 3 <-> ATMEGA328P-PU
    3.3V <-> 7
    GND <-> 8
    11 (DOUT) <-> 17
    12 (DIN) <-> 18
    13 (SCK) <-> 19
    10 (Reset) <-> 1

    I also have tried with a 10K resistor between Reset and 3.3V.

    I am really sorry if i missed something obvious here.

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,314
    Those connections seem to be correct.

    If you post a good photo of the wiring, we could all triple check.....

    Looking at the ArduinoISP code, the use of pinMode after SPI is configured might be a problem. Try editing the start_pmode() function, to move spi_init() to the edit. Like this:

    Code:
    void start_pmode() {
      // following delays may not work on all targets...
      pinMode(RESET, OUTPUT);
      digitalWrite(RESET, HIGH);
      pinMode(SCK, OUTPUT);
      digitalWrite(SCK, LOW);
      delay(50);
      digitalWrite(RESET, LOW);
      delay(50);
      pinMode(MISO, INPUT);
      pinMode(MOSI, OUTPUT);
      spi_init();
      spi_transaction(0xAC, 0x53, 0x00, 0x00);
      pmode = 1;
    }
    I haven't tried this... it's only a hunch. Please let me know if this makes it work?

  5. #5
    Junior Member
    Join Date
    May 2013
    Posts
    2
    Thank you very much for the help, moving spi_init(); down appears to fix the issue.

  6. #6
    Junior Member
    Join Date
    Jul 2013
    Posts
    10
    Hi, that worked like a charm for me. The nice thing is that with you do not even need the capacitor. Thanks!

  7. #7
    Junior Member
    Join Date
    Jun 2014
    Posts
    1
    Yep, this worked for me too. Thanks very much.

  8. #8
    Junior Member
    Join Date
    Jul 2015
    Posts
    3
    Will this also work for the Teensy LC?

  9. #9
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,314
    It should work the same on Teensy LC.

    However, LC is not 5V tolerant, so your AVR chip must have 3V power, or you'll need a 5 to 3 volt level shifter on pin 12.

  10. #10
    Junior Member
    Join Date
    Jul 2015
    Posts
    3
    OK thanks.

  11. #11
    Senior Member xxxajk's Avatar
    Join Date
    Nov 2013
    Location
    Buffalo, NY USA
    Posts
    532
    Normally if I am just doing plain uploading I've been using my AVR Dragon, even if I am not doing any debug.
    I just might add this to my tool chest as an alternative to abusing my AVR Dragon..
    Right now I use a Teensy 3.1 as a JTAG programmer, which can handle the 5v.
    SPI programming on AVR would be nice to have as an option/add-on, because I've barely scratched the amount of available flash space on the device.

  12. #12
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,204
    Quote Originally Posted by xxxajk View Post
    N
    Right now I use a Teensy 3.1 as a JTAG programmer, which can handle the 5v.
    This is very interesting! Is it open source ?

  13. #13
    Senior Member xxxajk's Avatar
    Join Date
    Nov 2013
    Location
    Buffalo, NY USA
    Posts
    532
    Yes, but I have not released the openocd driver yet, since it is not stable enough for general consumption.
    You can, however look at the sources on the teensy 3.1 side. I do a really neat trick that increases the speed by about 40% on classic JTAG.
    Note that SWD is not supported, only full JTAG.
    https://github.com/xxxajk/TAGme

  14. #14
    Junior Member
    Join Date
    Jul 2013
    Posts
    10
    Hello Paul
    For me this wireing didn't work, additional I hat to wire:

    teensy3.1 -> atmega328
    GND -> 22 (second GND)
    3,3V -> 20 (AVCC)

    like that it worked, but I have no idea, what this AVCC is.

  15. #15
    Junior Member
    Join Date
    Jul 2013
    Posts
    10
    Before I didn't got an error, it just didn't work

  16. #16
    Junior Member
    Join Date
    Sep 2015
    Posts
    3
    I was wanting to use the Teensy 3.1 to program another Teensy 3.1 similar to an AVR ISP. I am currently using the ArduinoISP sketch and the programmer is set to "Arduino as ISP". The ArduinoISP sketch downloads to the Teensy that will be doing the programming with no problems and an LED shows the heartbeat as active. When I try to "Upload using programmer" the blink sketch, to the teensy which needs to be programmed, I get the following error message: "avrdude: AVR Part "mk20dx256" not found." It then gives me a list of valid parts: uc3a0512 = AT32UC3A0512, c128 = AT90CAN128, c32 = AT90CAN32, c64 = AT90CAN64 etc... As the Teensy is not using an AVR chip is this even possible? Has any else tried downloading code to a Teensy in a similar way with success?

  17. #17
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,204
    Quote Originally Posted by SnowySpark View Post
    As the Teensy is not using an AVR chip is this even possible?
    Simple answer: No.

  18. #18
    Senior Member xxxajk's Avatar
    Join Date
    Nov 2013
    Location
    Buffalo, NY USA
    Posts
    532
    Actually, yes it is possible to program it.

    Yes, I have done this.
    No I am not going to show you how. in fact, I actually can't just do a simple document on how.
    Moreover I wouldn't feel right in showing you how to do this.

    Doing this requires quite a lot of know-how and major skills.
    This isn't something for the everyday inexperienced person.
    You need more than just a program to do this.
    You would need a lot of training and experience in multilayer board repair and modification, literally years of it.

  19. #19
    Senior Member xxxajk's Avatar
    Join Date
    Nov 2013
    Location
    Buffalo, NY USA
    Posts
    532
    Side note:
    If you mean programming a teensy 3.1 from another teensy 3.1 over the existing USB, yes, you can.

  20. #20
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,314
    I know File > Examples > 11.ArduinoISP > ArduinoISP used to work on Teensy 3.0 for programming AVR chips. A very old version had pinMode() lines after SPI.begin(), which turns the SPI pins back to GPIO mode on Teensy3... but it worked fine when those 3 unnecessary pinMode lines were deleted.

    I haven't used AVRDUDE in a very long time and ArduinoISP changed quite a lot. Maybe try Arduino 1.0.6 for the old version?

Posting Permissions

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