Embedded C programming using AVR Studio on Arduino Boards

For those of you who have an Arduino development board and wanted to code in embedded c and upload your code on the board, this is the right post.

For starters you need to download following components:
1. Arduino IDE Download Link
2. AVR Studio Download Link or AVRDUDE download

We shall be using AVRDUDE utility for burning our programs onto the micro-controller.

Once you’ve installed above programs. We can begin the setup of AVR studio using AVRDUDE for burning our programs.

First you must locate following two files:

  1.  avrdude.exe : If you have installed Arduino IDE then a sample path for this file is as follows. C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avrdude.exe
  2.  avrdude.conf : Similarly for Arduino IDE installation the path is as follows. C:\Program Files (x86)\Arduino\hardware\tools\avr\etc\avrdude.conf

If you are using AVRDUDE direct download, then these files shall be in the avrdude installation folder. example: C:\avrdude\avrdude.exe and C:\avrdude\avrdude.conf

We shall require both of these paths in the subsequent steps, so kindly ensure you’ve copied these two paths and kept it somewhere.

Next step is detecting which COM port your arduino board uses.

devicemanager

In my case the port used by the Arduino Board is COM3. Keep this information with you.

Now the AVRDUDE arguments is as follows:

  1. Arguments for Arduino Mega 2560
    -v -patmega2560 -cwiring -P COM3 -b115200 -D -Uflash:w:"$(ProjectDir)Debug\$(TargetName).hex":i -C"C:\avrdude\avrdude.conf"
  2. Arguments for Arduino UNO
    -v -patmega328p -carduino -P COM3 -b115200 -D -Uflash:w:"$(ProjectDir)Debug\$(TargetName).hex":i -C"C:\avrdude\avrdude.conf"

I shall explain few important command line options used in above commands. The detailed explanation for all the options is given in following documentation.
options
Now that we understand about the commands that shall be used, we can proceed with the creation of AVR Studio programmer.

avrstudioprogrammer

Steps:

  1. Open AVR Studio.
  2. Under tools select external tools.
  3. Press add.
  4. Name your programmer in the Title field.
  5. Paste the appropriate arguments in the Arguments field.
  6. Paste the avrdude.exe file path without the quotation marks in the Command field.
  7. Check the ‘Use Output window’ box.
  8. Press OK.

Now you have your programmer available in the tools menu above the external tools sub-menu.

You can upload a LED blinking program to your board to check whether everything is working.

Steps for testing

  1. Create a new GCC executable project
  2. Make your main.c file
  3. Build the project so that the hex file is generated
  4. Go to Arduino Programmer in the tools menu and click on it
  5. You should get an output window

If everything works you will have the hello world blinking LED.

Hope you liked the post. If you found it useful, please like and share! Remember sharing is caring 🙂

Advertisements

SIM 300/900 (GSM Module)

INTRODUCTION

SIM 300 is a GSM modem with a simple serial interface. SIM 300 modem can accept any GSM network operator SIM card and act just like a mobile phone with its own unique phone number. With this module one can send/receive sms, connect to internet via GPRS and receive calls. The modem can either be connected to PC serial port directly or to any microcontroller. When purchasing purchase the entire board. As it comes with RS232 to TTL converter and ethernet port. Also do check the module by calling a few times when in the shop.

You can purchase this module online. Some of the sites are listed below:

  1. http://www.nskelectronics.com/sim300_modem_with_rs232.html
  2. http://robokart.com/wireless-modules/gsm-gprs/sim-900a-gsm-gprs-modem.html

SIM300_INTERFACE_MODULE_RS232_TTL-500x500

Fig.1 SIM300 Module

There are two LEDs on the board. One is power LED and the other is the network LED. When you insert your SIM card into the slot and power ON the device the power LED will be turned ON. After few seconds the network LED will start blinking after an interval of 3 seconds. If this happens it means signal is proper but if it is blinking faster it means that there is no network. If your mobile phone has network then this module should have network at the same location(provided the antenna is connected.) Make a call and it should ring. Do it a couple of times before purchasing from a store.

AT commands

These are the Haye’s command set also called AT commands. AT stands for attention. These commands are used to control the modem. Using these commands the modem can be operated. There are different commands for sending/reading sms etc. For further information about the history you can read the Wikipedia article.

The AT command set can be downloaded here.

at_commands

Above table lists few of the commands. The most basic command is AT and the response is OK. If you get OK then it means that everything is working fine.

exteneded_at

Now to test out the commands or for direct interfacing with the PC or laptop you can use USB to RS232 adapter.

USBRS232Cable_1

Fig. 2 USB to RS232 Adapter

You will need to install prolific drivers. These will be included in a small CD that accompanies the adapter or you can download here.

Once you do that there will be a COM port available now. Some of the basic commands are explained in the following video.