PC->USB->UART->XMEGA->ISP->ATMEGA

Go To Last Post
26 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yet another crazy idea, I know.

These crazy ideas are the result of me having no money for things so I always seek for alternatives and make improvizations.

 

I cannot find a programming device for my ATMEGA8 in my country. The programming devices are pretty expensive. On eBay, they're cheap, but eBay is not an option for me because I don't have a credit card or a job.

I was thinking about using my ATXMEGA128A1 to program ATMEGA8 by connecting XMEGA's SPI pins to ATMEGA's ISP pins.

I tried Google searching for an XMEGA programmer's source code where XMEGA is NOT the one being programmed, but THE programmer! But Google is never precise in what I want, but only in what's relevant.

That's how I couldn't find an XMEGA version of anything USBasp-ish.

 

Then I decided to write my own code. Here's my idea:

The upload from the program goes from an MFC program for Windows that I make that sends user's hex file via USB-UART to XMEGA. XMEGA processes it and sends instructions via SPI to ATMEGA'S ISP to flash bytes on addresses.

I tried to search for some documentation on how ISP works and found none. Which byte goes when and how to access certain registers.

 

Is there any documentation about ISP programming and is there a programmer written in XMEGA's assembler with XMEGA's registers and not ATMEGA's?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Where are you, Foxy?

The largest known prime number: 282589933-1

In my humble opinion, I'm always right. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Surely there is a "chicken/egg" problem here? If you want to turn the Xmega 128A1 into a programmer you are first going to need a PDI programmer to put the ISP programming code into it. But if you have a device capable of doing PDI programming then it's almost 99.9% certaink it can also do ISP anyway.

 

So how does the xmega128A1 actually help in this?

 

ANYWAY the fact is that Dean Camera has written code to use AVr I/O pins to do ISP a couple of times (well one was really just a modified version of the other). First he wrote "Buttload". That was actually for an atmega169 based "AVR Butterfly" but it's written in C and it should be fairly easy to port that ISP code to just about any AVR - either another mega or an Xmega (perhaps fractionally more work?). Later he wrote LUFA which is a support library for AVRs that have USB built in. Amongst the many examples he has code that turns a USB AVR into a clone of Atmel's AVRISPmkII programmer. To do that it must also be able to do ISP and so it uses some code that's actually pretty close to the original Buttload ISP code.

 

Either of these should form a good model for writing your own ISP implementation.

 

But it would surely be much easier to just pay $2..$3 on ebay for a USBAsp? I know you said about credit card/job but surely you know someone who owns a credit card (or a paypal account) who can buy things from ebay for you? Just buy them a beer and they could buy you a $3 USBAsp.

 

Another alternative to get over the chicken/egg bootstrapping problem is to buy a chip that already has a bootloader preloaded. But a mega328 with the Optiboot Arduino bootloader already loaded is probably going to cost $2..$3 anyway and on top of that you would silt need a USB-TTL cable and they are another $2..$3 from ebay too.

 

Really - your best bet it is to just find a thread who can buy you a $3 item from ebay to get started.

 

Failing all that, if you could find a really old PC that had a parallel port (or serial) you could use 2 resistors to build a "DAPA" programmer for AVRs and drive it with avrdude. But there aren't many such old PCs around these days.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Foxcat385 wrote:
On eBay, they're cheap, but eBay is not an option for me because I don't have a credit card or a job.
Typically one can gather a wee bit of cash then can meet with one who can transfer into your Bitcoin, or such, account in exchange for some cash.

CoinTelegraph.com

You Can Now Buy Ebay Giftcards With Bitcoin, Litecoin and Dogecoin

by Ian DeMartino @ 2014-12-18 09:16 PM

http://cointelegraph.com/news/113143/you-can-now-buy-ebay-giftcards-with-bitcoin-litecoin-and-dogecoin

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I program my ATXMEGA128A1 without a programming device. To be more precise, my programming device is USARTC0 + ATXMEGA128A1's bootloader section + VLSI's USART/USB converting chip + USB cable + USART/USB converting driver for Windows + MikroBootloader for XMEGA by Mikroelektronika. That's not the problem. All I need is a non-GPL code of a ISP programming device so that I can make my ATXMEGA128A1 translate the HEX file that I upload via HyperTerminal using the file upload function into the ISP code that the ATMEGA8 understands.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oh. I see. You can already load programs into your xmega and use the uart to send it info. You just need to know how to work the spi, then you'll make a program to receive hex files and send the proper commands out the spi to program the chip.

 

I'll bet it'd be easier to buy a $3 programmer, but sometimes we do things the hard way to learn how.

 

Basic SPI on an xmega is pretty easy. You can google xMega SPI, or go to http://barefootelectronics.com/N... and roll down till you find my SPI code. The rest of the article doesn't apply to you unless you decide to do it wirelessly. Then you need to study the part of the datasheet that I've never bothered to read to know what the SPI commands for programming a chip are.

The largest known prime number: 282589933-1

In my humble opinion, I'm always right. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Foxcat385 wrote:

I program my ATXMEGA128A1 without a programming device. To be more precise, my programming device is USARTC0 + ATXMEGA128A1's bootloader section + VLSI's USART/USB converting chip + USB cable + USART/USB converting driver for Windows + MikroBootloader for XMEGA by Mikroelektronika. That's not the problem. All I need is a non-GPL code of a ISP programming device so that I can make my ATXMEGA128A1 translate the HEX file that I upload via HyperTerminal using the file upload function into the ISP code that the ATMEGA8 understands.

Another approach is to flip the  problem around a little, and first find PC Programmer Software that supports the most devices from the PC.

I think that is Avrdude ?

 

You then emulate the Serial-SPI interface that AvrDude needs.

 

Does anyone know which AvrDude supported HW (UART-SPI)  is the smallest/easiest firmware  ?

 

That means you can pgm ALL the devices Avrdude supports.

 

Addit:
If price matters more than speed , I see these line in AvrDude

 

ponyserponyserponyser    design ponyprog serial, reset=!txd sck=rts mosi=dtr miso=cts << Best ?

c2n232ic2n232i    serial port banging, reset=dtr sck=!rts mosi=!txd miso=!cts
dasa       serial port banging, reset=rts sck=dtr mosi=txd miso=cts
dasa3      serial port banging, reset=!dtr sck=rts mosi=txd miso=cts

 

That likely works best on a genuine Serial port + level shifters (where you can wiggle rts etc faster) but should work on a USB_ser ?

If you have anything with FT2232H on it, that can wiggle a little faster, but still slower than a genuine serial port.
(can anyone confirm avrdude with ponyser serial lines connected as above, works slowly but reliably on USB serial ports ?)

Last Edited: Tue. Feb 10, 2015 - 09:07 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Does anyone know which AvrDude supported HW (UART-SPI)  is the smallest/easiest firmware  ?

USBtinyISP - almost everything is done inside avrdude with virtually nothing in the (2K!) AVR. I imagine it would be portable to an Xmega.

Last Edited: Wed. Feb 11, 2015 - 11:48 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I found some code and when I tried translating, I've seen so much software style waiting and software SPI. I'd rather use the hardware solution without interrupts so I'm learning from XMEGA documentation and reading from the source code which character is sent when to ATMEGA8. That will be fair enough information for me to learn about ISP.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A bit more reading finds AvrDude mentions an Atmel Appnote AVR910, as a simple programming UART-SPI bridge code.

 

The Web turns up this, that covers AVR910,

https://people.kth.se/~joakimar/...

 

& that links to this that has revisions of AVR910

http://www.serasidis.gr/circuits...

 

and I found this comment

"Only a modified version of the AVR910.ASM supports Universal commands so all chips can be programmed."

 

Foxcat385 wrote:
... I've seen so much software style waiting and software SPI. I'd rather use the hardware solution without interrupts so I'm learning from XMEGA documentation and reading from the source code which character is sent when to ATMEGA8.

 

You can of course, modify the SW wrser: routine in the AVR910.asm, to use HW, but keep in mind SW SPI can keep up with most

downloads, so I would get it working first with SW SPI and change to HW when proven to see if you gain speed.

 

I see the AVR910.ASM (Universal command) lacks a length byte, so always sends 4 bytes and echos 1 - not sure how universal that really is ?

 

Addit : Looks like stk500v2 is more flavour of the month, and this site claims to have stk500v2 code in about half a atmega8

(ie ~ 4k)

http://tuxgraphics.org/electroni...

 

Last Edited: Wed. Feb 11, 2015 - 09:46 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It is trivial to write an ISP programmer to run on an Xmega.   The problems come if your punters want to connect the ATmega8 to 5V.

 

I have a STK500-clone programmer that will run on an AVR or on a M*crochip.  

It just takes commands from the USART and sends the appropriate SPI sequence to the target AVR.

i.e. it needs low-level USART functions and SPI functions.    The high-level code handles the protocol.   It is easy to write the equivalent Xmega USART and SPI functions.

 

Personally,   I think that you would be better off with a class full of Arduinos.    Clones are pretty cheap.

Alternatively,   let each student have a USBASP.   But you still need some form of UART to make meaningful projects with your students.

 

If your job is to go round a class full of students burning their projects one at a time,   tempers will get frayed.    Your Xmega will die.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:

It is trivial to write an ISP programmer to run on an Xmega.   The problems come if your punters want to connect the ATmega8 to 5V.

 

Good point, - Since the OP has both ATmega8 and ATXMegas, an alternative is to put the code into a ATmega8 - full Vcc compliance.

 

- the last link I gave above does exactly that, right down to a HEX file ATmega8 ready.

It even has a slow pgm, to first get the firmware into the ATmega8, using the UART handshake lines.

Not fast, but also not done often. ( I think Avrdude can also do this slow 1st-pass-bring-up, see the above notes)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:

It is trivial to write an ISP programmer to run on an Xmega.   The problems come if your punters want to connect the ATmega8 to 5V.

 

I have a STK500-clone programmer that will run on an AVR or on a M*crochip.  

It just takes commands from the USART and sends the appropriate SPI sequence to the target AVR.

i.e. it needs low-level USART functions and SPI functions.    The high-level code handles the protocol.   It is easy to write the equivalent Xmega USART and SPI functions.

 

Personally,   I think that you would be better off with a class full of Arduinos.    Clones are pretty cheap.

Alternatively,   let each student have a USBASP.   But you still need some form of UART to make meaningful projects with your students.

 

If your job is to go round a class full of students burning their projects one at a time,   tempers will get frayed.    Your Xmega will die.

 

David.

Again, in case you didn't notice, I'm not a professor. I'm a student working on a final school project for the XMEGAs that the future generations will use on my mentor's classes.

All students have an XMEGA development board and upload their projects on it by using USART & Preloaded MikroBootloader.

 

This XMEGA->ATMEGA8 programming is what I'm doing because I currently have no programmer for ATMEGA8 which is collecting dust here (alright it's not because it's in a sack). If it succeeds, I might use it in the project so that my Monitor Program not only monitors XMEGA, but maybe ATMEGA8 too. All from one USB cable and a terminal.

 

Are you saying that XMEGA works on 5V??! I had no idea! On the development board, I see there are header-solderable holes for 5V and 3.3V supply so I concluded that XMEGA is 3.3V and that 5V is from USB that supplies the board.

 

And if XMEGA and ATMEGA8 were both 3.3V, would that still kill XMEGA? Sorry, I had an F from calculating resistance, current and voltage in different places in a circuit with lots of resistors and I barely got a D from that and it was 3 years ago.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Foxcat385 wrote:

Are you saying that XMEGA works on 5V??!

NO, read the data.

Foxcat385 wrote:

And if XMEGA and ATMEGA8 were both 3.3V, would that still kill XMEGA?

 

Both @ 3v3 is ok, where it gets riskier is 3v3 XMega and 5V Mega8.

If you just want to use one Mega8 you have lying around, then use the low speed programming mentioned above.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why low speed? How much baud rate is that for SPI on XMEGA with a 32MHz crystal?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If it is for your own purposes,   running ISP software on an Xmega to program a ATmega8 @ 3.3V is no problem.   The SCK frequency is dependent on the mega8's clock.   e.g. 250kHz for 1MHz RC.

 

I just would not trust a herd of students with this arrangement.

 

I am not a teacher and have no intention of being a teacher.    Regarding your other topics,    I just don't think it is practical for a teacher to be responsible for having control of the student's AVRs.    If each student has her own PC ad AVR board,   it should be the student who uploads stuff from her local PC or the school server.

 

And I would start them off with something fairly foolproof like an Arduino Bootloader or FLIP Bootloader.

Yes,   they will learn about fuses and debuggers at a later stage in their course.   After they have gained some experience in loading programs,   using libraries,   designing their own programs.

 

I may be cynical,  but if you start students at the deep end,   the teacher will spend all her time rescuing them from drowning.   And have no time left for swimming lessons.

 

David.

Last Edited: Fri. Feb 13, 2015 - 10:36 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:
I am not a teacher and have no intention of being a teacher.    Regarding your other topics,    I just don't think it is practical for a teacher to be responsible for having control of the student's AVRs.    If each student has her own PC ad AVR board,   it should be the student who uploads stuff from her local PC or the school server.

 

And I would start them off with something fairly foolproof like an Arduino Bootloader or FLIP Bootloader.

Yes,   they will learn about fuses and debuggers at a later stage in their course.   After they have gained some experience in loading programs,   using libraries,   designing their own programs.

 

I may be cynical,  but if you start students at the deep end,   the teacher will spend all her time rescuing them from drowning.   And have no time left for swimming lessons.

Look, the students have microcontrollers on their readyboards which have a preloaded bootloader. They run MikroBootloader and upload their HEX file all themselves! Then, they connect with HyperTerminal and see their USART progress. That's how it's been going the previous year, is going this year and will go in the future. So don't worry!

 

Also, in Croatia, according to the educational program, we learn low level first and then high level. Assembler -> C -> C++. In the regular programming subject (without microcontrollers), we have C and then C++.

 

Learning C++ without C is like playing with toys. Cin cout mout bout rout snout blah blah... Learn scanf and printf first! Experience the anger from having fixedly allocated char array and then learn how to dynamically allocate one by using the urge for it which you got when you were trapped in low level environments and now you can finally use string class. Not only that, but you can make sure you'll never corrupt anything in RAM (speaking of which, I know I'm not crazy to overflow an array so don't worry about that either). That's how it goes.

 

All others who have been learning C++ without C or even using microcontrollers without interrupts or robotics with line followers with everything preprogrammed with just drag and drop baby toys have never become professionals and only had glitches, limitations and errors and believed that electronics and programming are so easy and full of playing while there's a lot more happening in the background which one girl, when she found out, got depressed from choosing my school with difficult low level learning. I mean, not really low level, but simple C++ programming even which some teachers teach students without C. She couldn't handle it. I went that way with Multimedia Fusions and Game Makers and QBasics experiencing limitations and errors and making ridiculous unoptimized workarounds all until my mentor told me "Let's learn C".

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes,   we have different opinions.    There are many Forum members that share your views about "low-level first".

 

Quite honestly,    if all the students end up with a good education at the end of the course,   it does not matter which way it is organised.     If a potentially good student drops out because of unsuitable organisation,   I would regard that as failure for the school.    Of course,   if the student was going to fail anyway it does not matter.

 

MikroElektronika produce some excellent hardware.    If your students have to use the MikroElektronika "languages",    I would be very worried about them entering the real world.

 

Regarding the original subject.    I answered it.   Your Xmega can do anything and more than a humble Mega.    (and the mega8 is inferior to the mega88)

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Please excuse me if I have been harsh, but I wanted to make some things clear and I believed that you didn't read me well.

 

Also, we're not using MikroElektronika's compilers. We're using Atmel Studio for programming, simulating and compiling. MikroElektronika's MikroBootloader is there only so we don't have to buy PDI programming devices (hard way), but use the USB cable (easy way).

 

I'm using ATMEGA8 because I am not allowed to solder anything on the readyboard, neither am I good at it (I burned myself a lot and I can't hold the solderer, the soldering iron, the soldering target and the solderee at the same time) so I'm using a breadboard for little projects for simple fun like a little MP3 player or a game engine that loads game parameters from an SD card. I can't really deal with procrastination in any more efficient way than that. As a kid, I've always wanted to manipulate screens and LEDs and LCD display and I have a lot of drawings and ideas of new devices. Now it's the time to make them! :D

 

Thank you very much for your answer and time.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Foxcat385 wrote:

Why low speed? How much baud rate is that for SPI on XMEGA with a 32MHz crystal?

Because it exists right now, as a solution.

Tip: Be prepared to learn from what others have done already, it is a skill employers will value.

 

Get yourself a copy of AvrDude, and look into the great many hardware pathways it can support.

The simplest pathways can be slow, but they work and on almost anything. That is why they are there.

(they do not use XMEGA SPI )

 

eg the Program via Serial handshake is possible and works, but is slow.

Example: This can be a great way to get a first bootloader installed, and thereafter, you use the bootloader.

The time to pgm that first step, really does not matter too much.

 

ISP speed matters if you program thousands of parts.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So how am I supposed to connect AvrDude? On which device should I put it? Please tell me about it. All I know is that it's like my Monitor Program, but not on the same chip, but as an external programming device.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Foxcat385 wrote:

So how am I supposed to connect AvrDude? On which device should I put it? Please tell me about it. All I know is that it's like my Monitor Program, but not on the same chip, but as an external programming device.

Avrdude is a command line AVR/SPI programmer, that runs on a host PC.

Go to their website, and read the explanations.

 

It connects to SPI in a variety of ways, and choices, depending on what ports your available PC(s) have.

Some connections are simple enough to work on a Serial Bridge with nothing added, others expect a bridge device for UART-SPI

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Good news:

A friend of mine helped me buy some stuff from eBay and now I won't use ATMEGA8 because it works on 5V. I'll use ATMEGA1284P which has more SRAM than ATXMEGA128A1 and works on 3.3V. Now, I don't know how to properly connect it with the PC. ATMEGA1284P doesn't have ISP, but JTAG. PC's serial and paralel port is 24V if I'm not mistaken. Correct me if it's different voltage. I'm not sure how to connect without burning anything from overvoltage. Is there a schematic? And which programmer should I use from the list for JTAG?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The ATmega8A works at 3.3V

However the speed is limited to about 12MHz.

 

The ATmega1284P has ISP and JTAG.

 

You could run software on your Xmega to program bothe the mega8 and mega1284 (providing you use 3.3V)

 

I am horrified that you are doing a "microcontroller course" if you have such poor knowledge of basic electronics.

Especially since you have clearly not read the data sheet of the mega8 or mega1284.

 

Or even visited Wikipedia to learn the basic details of a PC port.     Most modern PCs don't even have a serial or parallel port.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't care about electronics. I'm a programming type. All I care about electronics is just enough to not get myself killed XD lol

Also, I have read the datasheet. The ATMEGA8L is 3.3V and slower while ATMEGA8 is 5V and faster.

ATMEGA1284P can be 3.3V or 5V. I don't remember the exact range, but I know that these two numbers are inside of it.

My PC is not modern and it does have both serial and paralel port. And I haven't seen a school PC that doesn't have those.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Foxcat385 wrote:

I don't care about electronics. I'm a programming type.

Wow, and yet you are playing with Microcontrollers ?!

When using Microcontrollers, you certainly DO have to care about electronics. As your own posts prove.

 

If you have PC parallel port, you will of course have read the AvrDude info, and found the options for supporting that ?

Oh wait, connecting that may require trivial electronics. Perhaps find someone else in your class to help ?