Saturday, October 26, 2013

Arduino hardware with AVR Studio and coding in C or ASSEMBLY - no programmer required

Hi

Recently I was working on an IR recorder for my home automation projects. After working with Arduino and C, finally had to move to assembly since every single Atmega328 intruction was to be accounted for. The work is still on but I am very happy with results and what I have learnt about the hidden capabilities of Atmega328 waveform generation. That will be next time but I would like to  explain how I have used the Arduino hardware (Atmega328 with duemilanove bootloader) to be programmed from AVR studio using the bootloader and bypassing a programmer.

I had two main requirements as mentioned below:-

1) Write Code in assembly and generate Hex code. Download Hex code to Atmega328 and run.
2) Start a serial monitor at the end of program download since the code was designed to communicate with a terminal for configuration and passing the results (VT100 terminal emulation supported in the code).

Sponsor: www.avmicrotech.com/shop eshop for your electronic needs


To be able to use the Arduino hardware with AVRStudio, first  you will have to download avrdude from sourceforge and then  have to write a batch file in your AVRStudio project folder where the Hex file is generated. The batch file contents are as below.
--------------------------------------------------------------------------------------
ECHO OFF
ECHO Starting Avrdude please wait......
avrdude -P com30 -b 57600 -p m328p  -c arduino -F -e -U flash:w:AutoProg.hex
pause
--------------------------------------------------------------------------------------

Note:- You will have to change those in red as per details below.

com30 - This is the com port that your arduino UNO or deuemilanove shows up as
57600 - Downloading baud rate for duemilanove. For UNO it should be 115200 (please check).
m328P - For atmega328p. For Mega this will change. Please read the avrdude manual.
AutoProg.hex - This is the hex file that will be generated in your project folder hence you will have to change it as per your project name.

Imp:- If you get "not in sync" error msg during avrdude (Arduino) download, please update your avrdude to the latest version.

To down load the hex you will have to click (execute) this batch file in the folder alternatively you can also create a short cut in AVRstudio using Tools -> customize -> Tools. The screen shots are as below:-


This is how it appears in the AVRStudio menu.




The avrdude also releases the serial port after the download, hence the serialmonitor can be started immediately.

For a free serial monitor like Hyperterminal , you can download PUTTY and enable serial mode.

This is how I have been working for many years. If you know a shorter and better way then do let me know. Thanks!!
 

No comments:

Post a Comment