SPI (ISP) and USART

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

hi everybody,

I coded a I2C tranciever so far (mega16 on DSK500, slave on TWI, master in software)
I want to change some settings which are saved in the internal EEPROM from a PC.
And I want to get some data which are in the SRAM.
My problem is now:
At first I wanted to connect the mega16 to a PC -> USART???@mega16 to serial COM Port@PC (handling EEPROM programming with commands over USART in software)
But I will need the SPI to do the initial programming of mega16 on my later board/PCB.
After all my board has to be as small as possible and with nearly no parts exept the mega16.
So I would like to use just one Port(SPI)

Questions:
What hardware is needed to connect from serial COMPort@PC to the SPI?
(I saw the schematics of PonyProg, some resitors etc. could placed in cable connector?)
Is it possible to use the SPI nearly in the same way like the USART?
(leave the USART away and do programming and data transmitting over SPI?)
What hardware is needed to connect from serial COMPort@PC to USART?
(Driver....)
Are there any other simple ways to programm a mega before or when it is placed to
a board.

Just some hints where I can find some answers, would be very usefull.
Thank you very much
Denny

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

I just had an idea, but it does not solve my problem.
I thaught of using an bootloader and usart in my project.
I would just need the bootloader at the very first start,
to fill the mega with the programmcode.
BUT how does the bootloader come into the mega?
It's like the old chicken and egg thing. What was there first.... :(

Can anybody tell me?

Thanks
Denny

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

Hi Denny,

Typically you burn a bootloader onto the chip early on, say in early production or on the test board when testing. You can use the test board, ISP programmer, JTAG, etc. I use the STK500 or a JTAG.

Most people program a USART-based bootloader, which is fairly easy to implement. Then you can reprogram the app code any time you want on the final board, using simple RS-232 from a PC, without special hardware.

If the bootloader is robust, you may never need to change it, so reprogramming the main code of your chip just requires connecting to the serial port on your final board (or however you communicate). If the bootloader needs reburning after installation, you can do so if you have an SPI, JTAG, etc. header built in, though you'll need the corresponding device. Alternatively for in-house/personal work, you can unplug the chip and put it into a test board. Reburning the bootloader via plain serial is a bit risky (IMHO), and rarely done (sensibly), since you have to rely on the chip itself programming over itself, and have no recourse should something go wrong (the term "brick" comes to mind).

Overall, the bootloader is a self-contained on-board program that makes use of the SPM instruction (on the AVR) to program itself; the other methods use external hardware to provide access to every byte on the chip. Thus, bootloader code is usually limited to programming the app area (non-boot area), and can't change fuses nor clear lock bits (though lock bits can be set).

SPI is nice, but it does require a dedicated connector and device for programming. There are other kinds of hardware-based programmers out there too (both serial and parallel). A bootloader is always a nice addition in any case, and costs nothing but some time to code or port (there are many examples out there). BTW, you generally have to compile a small program for the PC end too, so it can talk to the AVR bootloader from the PC.

Hope my verbosity has helped a bit...

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

It's my first own project in developing a complete test equipment,
which should include everything (circuit schematics, programming,choosing the right parts and materials...)
If I do my work good, it will be produced in a small series.
That's why I have to think of in circuit programming and aswell interfacing the device for
a connection to a PC.

Thanks
Denny

PS: I do not want a full solution, just hints and maybe known problems or experiences would be interesting.

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

Thanks jeffjacques,

so I will try to figure out, if a bootloader and/or the tested programm could be programmed on production into the mega.
If this works it would be a very nice solution, handling both updating
and communication with the device over just on port, without any further hardware except an serial cable.

Thx
Denny