Teensy 3 as AVR ISP programmer?

Status
Not open for further replies.

cmason

Well-known member
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
 

Attachments

  • main_arduino_isp.cpp
    12.6 KB · Views: 789
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.
 
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.
 
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?
 
Hi, that worked like a charm for me. The nice thing is that with you do not even need the capacitor. Thanks!
 
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.
 
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.
 
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
 
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.
 
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?
 
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.
 
Side note:
If you mean programming a teensy 3.1 from another teensy 3.1 over the existing USB, yes, you can.
 
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?
 
Sorry to resurrect this thread can't seem to find anything more appropriate elsewhere.

I have a Teensy 3.6 programming a Atmega 328AU over ICSP AVR 6 pin format. Works great via Teensyduino IDE.

However I would really like to store that program in memory on the teensy and upload it to the 328 without a computer running AVRDUDE/teensyduino/arduinoIDE.

Does anyone know if this has been done. I have searched and searched for variants of "arduino as ISP from memory" etc. but to no avail.

Thanks
 
Yes, this is totally possible.

I have a similar set of tools that I have made for mass programming.
The bigger question is are you wanting to burn a bootloader, program only, or both?

For program only, with a bootloader already in existence, do you want to upload over USB, serial, or ICSP?
 
Thanks xxxajk.

just flashing a new sketch is fine but having the option of teh bootloader would be useful in future potentially.
I managed to find optiloader after a flash of inspiration on search terms and of course the adafruit standalone https://github.com/adafruit/Standalone-Arduino-AVR-ISP-programmer

Only issue is I need to either bitbang SPI or use Serial2 for the programming as this is a retrofit on existing pcbs that are with users across the globe :D

As I say bitbanged SPI works fine with the standard arduinoISP sketch but I really just want to make a library and paste a hex file in there that I can integrate into the teensy sketch to call when I need to do any programming. So to be clear the sketch for the 328 needs to sit in Teensy memory and be sent to the 328 on demand. Without a computer connected.

Here's the alteration that I have done to the example arduino code....just pin number changes

Code:
#define USE_OLD_STYLE_WIRING

#ifdef USE_OLD_STYLE_WIRING

#define PIN_MOSI	18
#define PIN_MISO	30
#define PIN_SCK		31

#endif

// HOODLOADER2 means running sketches on the ATmega16U2 serial converter chips
// on Uno or Mega boards. We must use pins that are broken out:
#else

#define RESET     	32
#define LED_HB    	7
#define LED_ERR   	6
#define LED_PMODE 	5
 
Pin assignment doesn't matter on the host, only the target really matters.
Here's a starting point for you, that uploads a bootloader, it's pretty easy to modify to upload program only.
http://www.gammon.com.au/bootloader
http://www.gammon.com.au/uploader

With some creative thinking, you can ditch the SDcard, and have everything tucked away in flash, which you have more than enough room, even if you were to use a Teensy 3.2.
HTH.
 
Status
Not open for further replies.
Back
Top