Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Programming ATMega32 via RS232

Status
Not open for further replies.

codedawg

Newbie level 5
Joined
Apr 27, 2012
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,357
I want to be able to rewrite the program stored in flash on my ATMega32 with a new program via a serial connection. Is there a way to do this without having to rely on a programmer? For example, could I write a program on the ATmega that when it gets a certain message on the serial port, the next series of data is the new program that I want to flash the device with? This way I can just send out a message to rewrite and send the hex file data and it should automatically rewrite. Is this possible? Or should I invest in another microcontroller that handles whether incoming data on the serial port is a new program to rewrite on the atmega?
 

You can search portable programmers, and see principe. You should provide space where to keep new hex data.
 

What you ask is possible. You need to write a bootloader - or to adapt an existing bootloader to suit your needs.
A bootloader is a code that is executed in a dedicated, privileged zone of the flash, called the bootloader area. Code that executes in this area has the unique ability to change the contents of every location of flash - including bootloader area.
The only problem is that bootloader area is rather small, 4096 bytes in case of Mega32, and you have to squeeze your bootloader to fit into this limited space.

For a good starting point, I suggest you to look for the Arduino bootloader. It does exactly what you want, but is targeted to Mega1280 and Mega2560 with a bootloader area of 8192 bytes. I think that removing unneeded code you should be able to succeed.
 

Doesn't a bootloader require that the chip be restarted aka powered off and on? I'm trying to remotely re-program this chip so I want compile the hex files locally, then send the hex files to a remote (linux) machine that has a service running. This service realizes new files have come in and thereby pushes the hex files to the chip via serial port and re-programs it. If the chip is running, it'd need to realize new data has come through the serial port and restart itself (sounds like another microcontroller is required to do it?). If I edit the bootloader, I don't think it will realize a new program has come in until the device becomes restarted, if I'm not mistaken (or maybe I am mistaken :p). Is there a way to do this without having to power off/on?
 

Hmm... maybe now I have a better understanding of what you want to do.

If you want the PC to reprogram the MCU, the it must act just like an Atmel programmer. You need a serial-to-SPI converter, and then a piece of software that control that port following the Atmel programming protocol.

A better and easier way is use of a bootloader, where PC and MCU "co-operate" to reflash the firmware. The PC will inform the MCU that a new firmware is ready, and the MCU will jump to the bootloader area (no need to restart, just remember to reset SP to end of RAM), waiting for data packets that are written in the application flash area. At the end, you can jump to location 0 and that's all.
If you use this strategy the code that reflashes MUST be in the bootloader area or it will not work.
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top