শ্রেণীঅনুসারে আর্কাইভ: টিউটোরিয়াল

Compiling a V-USB (AVR-USB) example program with Visual C++

Well, I used MinGW / MSYS to compile some AVR-USB programs when I was working for IICT. Setting up MinGW is in windows is extremely tedious, especially if you live in a country where 30kBps download speed is considerably high. The offline installation of MinGW is equally confusing. I was considering an alternate development environment for windows, and Visual C++ can be considered as a great option.

Some of my students today visited me with some problems compiling a V-USB commandline example. Although I managed to solve it, I had to do it with considerable amount of hacks to the v-usb libraries. They were using visual C++ version 6. Now I am going to show some steps to compile an example of V-USB from Microsoft Visual C++ 2010 Express Edition.

Both online and offline installer for Visual C++ express edition is available from the website. The express edition is free to download and use for evaluation and education: http://www.microsoft.com/express/downloads/

In case you don’t know yet, v-usb can be downloaded from obdev’s website at: http://www.obdev.at/products/vusb/download.html

To set up the VC++ environment, you’ll also need libusb-win32 drivers. Download them from: http://sourceforge.net/projects/libusb-win32/

 

For this blogpost, I am using these files:

vusb-20100715.tar.gz

libusb-win32-bin-1.2.1.0.zip

downloaded from the respective sites, and the latest version at the time of writing this blogpost. I’ve also downloaded and installed Microsoft Visual C++ 2010 Express edition.

I am using 32 bit version of Windows 7, with intel processor. If you use 64 bit version of windows or AMD processor, you have to select apropriate libraries.

Open the libusb-win32-bin-1.2.1.0.zip with 7-zip and extract contents of folder libusb-win32-bin-1.2.1.0.zip\libusb-win32-bin-1.2.1.0\lib\msvc\ to C:\Program Files\Microsoft Visual Studio 10.0\VC\lib , (note, the library folder to be copied for 64 bit version is msvc_x64). Also extract the content of libusb-win32-bin-1.2.1.0\include\ to C:\Program Files\Microsoft Visual Studio 10.0\VC\include

Read this file: libusb-win32-bin-1.2.1.0\bin\libusb-win32-bin-README.txt to know how to install the bin folder content.

Open Microsoft Visual Studio Express edition, and create a new Win32 Console Application Project using the wizard. Use all default settings of wizard.

image

Now, using windows explorer, open the folder where the project is created using the wizard. My project title is ledcomm. By default, it will be in \Documents\Visual Studio 2010\Projects\ledcomm\ledcomm

Open the vusb-20100715.tar.gz and browse to this folder:

image

Copy the contents of commandline folder into the folder where you created the project (X:\Documents\Visual Studio 2010\Projects\ledcomm\ledcomm). The folder should now look like:

image

Copy the folder “firmware” vusb-20100715.tar\vusb-20100715\examples\custom-class\ to X:\Documents\Visual Studio 2010\Projects\ledcomm\ (note: it is one level up the folder where we copied command line). You can use this folder to create a AVR studio project later.

image

In the project explorer, remove all source and header files from the project:

image

Now add the following source files and header files to the project

image

ledcomm\set-led.c

ledcomm\opendevice.h

ledcomm\opendevice.c

firmware\requests.h

firmware\usbconfig.h

 

The project explorer window now looks like this:

image

Go to project properties and check if the Pre Compiled header is disabled:

 

image

 

At this point, if you hit F5 (Run), you’ll get this debug result:

1>—— Build started: Project: ledcomm, Configuration: Debug Win32 ——
1>  set-led.c
1>X:\documents\visual studio 2010\projects\ledcomm\ledcomm\set-led.c(84): warning C4013: ‘strcasecmp’ undefined; assuming extern returning int
1>  opendevice.c
1>  Generating Code…
1>opendevice.obj : error LNK2019: unresolved external symbol _usb_control_msg referenced in function _usbGetStringAscii
1>set-led.obj : error LNK2001: unresolved external symbol _usb_control_msg
1>opendevice.obj : error LNK2019: unresolved external symbol _usb_get_string_simple referenced in function _usbGetStringAscii
1>opendevice.obj : error LNK2019: unresolved external symbol _usb_close referenced in function _usbOpenDevice
1>set-led.obj : error LNK2001: unresolved external symbol _usb_close
1>opendevice.obj : error LNK2019: unresolved external symbol _usb_strerror referenced in function _usbOpenDevice
1>set-led.obj : error LNK2001: unresolved external symbol _usb_strerror
1>opendevice.obj : error LNK2019: unresolved external symbol _usb_open referenced in function _usbOpenDevice
1>opendevice.obj : error LNK2019: unresolved external symbol _usb_get_busses referenced in function _usbOpenDevice
1>opendevice.obj : error LNK2019: unresolved external symbol _usb_find_devices referenced in function _usbOpenDevice
1>opendevice.obj : error LNK2019: unresolved external symbol _usb_find_busses referenced in function _usbOpenDevice
1>set-led.obj : error LNK2019: unresolved external symbol _strcasecmp referenced in function _main
1>set-led.obj : error LNK2019: unresolved external symbol _usb_init referenced in function _main
1>X:\documents\visual studio 2010\Projects\ledcomm\Debug\ledcomm.exe : fatal error LNK1120: 10 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

 

I just pasted this error message so that people who have a hard time finding a solution quickly hits this page.

Firstly, VC++ doesn’t have strcasecmp, so replace the strcasecmp command with strcmp command. There goes the case insensitivity!

Now project>project properties, Configuration Options>Linker>Input>Additional Dependencies

image

 

Click on the additional dependency box and click on <Edit…>

image

In the additional dependencies dialogue, type in libusb.lib. Then press ok, and again ok from the properties dialogue.

image

Now Press F7 to build the project.

 

1>—— Build started: Project: ledcomm, Configuration: Debug Win32 ——
1>  set-led.c
1>  ledcomm.vcxproj -> x:\documents\visual studio 2010\Projects\ledcomm\Debug\ledcomm.exe
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

Now you can run the created exe file:

image

 

In this way, you can use Visual C++ 2010 Express Edition to compile the

মন্তব্য নেই

A Tutorial of Proteus Isis and Proteus Ares

This tutorial shows you how to create circuits in Proteus Isis, simulate them and then create PCB with Proteus.

Proteus is software for microprocessor simulation, schematic capture, and printed circuit board (PCB) design. It is developed by Labcenter Electronics.
The Proteus Design Suite inludes:
* ISIS -- A schematic capture tool with the possibility to simulate programmable ICs like Microchip PIC, Atmel AVR (ATmega8, ATmega32, or ATtiny2313) etc.
*ARES -- for PCB layouts.

The URL for Proteus is http://www.labcenter.co.uk/

Unfortunately, there are few / no good tutorials for Proteus out there, and therefore I took the trouble of making one myself. The tutorial has 3 parts. First part demonstrates Drawing circuits in Proteus Isis. Second part shows how to simulate circuits in Proteus ISIS, and how to export to ARES for making PCB layout. The third video shows Routing and how to print masks for PCB making.

25টি মন্তব্য

(Really) Beginners Microcontroller Guide (Part-II) Configuring Ponyprog properly and writing program to uC

(A Continuation from (Really) Beginners Microcontroller Guide (Part-I) Compiling the first program)

(alpha version. Very unstable, still editing)

Writing program to Microcontroller

We will be using ponyprog from lancos. Although it is possible to program directly from winavr, I like the interface of the program very much.

Construct the simplified SI Prog. You’ll need:
1. A serial port DB9 Female Connector,
2. 5V1 Zener Diodes x3
3. Resistors: 15K, 10k, 4k7 x 3
4. Bread board wires

Connect the circuit on veroboard. To see how it looks go to my blog http://sajiduc.blogspot.com/2008/04/beginners-microcontroller-programming.html

To connect the programmer always consult the datasheet of the microcontroller. Connect the Mosi, MISO, SCK, Reset lines of the programmer to the corresponding pins of microcontroller, and connect GND to 0V. Connect the serial connector to the serial port of your mother board. Please do not use a usb-serial converter, and connect only to true serial port.

Goto http://www.lancos.com/prog.html and download ponyprog from there. Install ponyprog, and open ponyprog from startmenu.

After the annoying neigh sound, click ok. Pony prog will say

Click ok again

Now do the bus timing calibration:


Afterwards, it is important. Click Setup>Interface Setup. Select Serial radio button. From drop down select SI Prog API / SI Prog IO. Select the COM port in which the programmer is connected. It is COM1 if you have only one serial port, but for multiple ports, you have to select the appropriate one. Please note that 90% cases, the SIProg does not work because of not proper configuration in this dialog. So if the SI Prog does not work, try to change the COM port, or switch between SI Prog API and IO

Select the appropriate device name

Now to test if the programmer is working, Click Command>Read All. From my experience 70% cases, people don’t get a smooth read operation at the first try. See below for common problems


If every thing is ok, (Which actually did in my first experimental SIProg) Then reading will start.

Now click File>Open, and open the testprog.hex file generated by the compiler.

Now select write all


And then the write will be successful!

Then play with your microcontroller circuit:

Ofcource the write may not be successful.
This might be due to
1. Circuit connection error (Check if you have connected power to micr
ocontroller, check if the breadboard connections are loose, if the programmer are connected to the proper pins, if the programmer is soldered properly.)

2. Check if the BC547 transistor is working by testing if 0.7 V drop occus between Emitter and Base.

3. Check if your serial port is working and you are not using a USB-serial converter

4. Play around with the interface setup (in ponyprog) to find another suitable setting for you. (Try SIprog API, SIProg IO, Check if you have selected correct serial port)

5. This is very common for me:- the microcontroller is dead!!!!

Well, no 5 can result from 2 cases, a) a heart attack of the microcontroller (Fry out, like connecting Vcc of microcontroller to ground and ground to Vcc, microcontroller, at 90% cases just fry) b) Accidental programming of the fusebits of the microcontroller can result the SPI interface to be locked out. This can be overcome by a universal programmer. If you happen to have access to one, ask some one clear the lock bits.

6. You forgot to select the right device (I also sometimes forget to do that)

6টি মন্তব্য

(Really) Beginners Microcontroller Guide (Part-I) Compiling the first program

(alpha version. Very unstable, still editing)

This is actually a beginners microcontroller guide. Just in alpha version. Please suggest necessary improvements.

This tutorial will show you how to:
1. Write and compile your first program in WinAVR environment
2. Construct necessary hardware for the program execution
3. Load the program into Microcontroller using the Simplified SI Prog
The tutorial assumes that you have some knowledge of C/C++ programming. If you are looking for a good book to start AVR series C Programming for Microcontrollers Featuring ATMEL’s AVR Butterfly and the free WinAVR Compiler is a great option.
Compiling the program
My program is quite simple. It will input from a port of a microcontroller checking if the pins are high or low. If the pin is high, the output will flash, other wise, the output will remain low.

Now to compile the code, we need the free winavr compiler. Download it from http://winavr.sourceforge.net/download.html
Install WinAVR.
Now go to Start>Programs>WinAVR>Programmer’s Notepad (XP) or Orb>All Programs>WinAVR>Programmer’s Notepad (Vista)

The main window pops up:

Select the coding scheme to C/C++ to better visualize the programming

Now type / copy paste the program:

#include <avr/io.h>

int main (void) {char c;int delay=10000;int i=0;DDRC = 0xFF;DDRD = 0x00;while (1) {c = PIND;PORTC = c;while (++i < delay);PORTC = 0x00;while (--i > 0);}}

Save the program firstprog.c

Now in order to compile the program using winavr, we need a MAKEFILE. The WinAVR comes with a make file creator called “Mfile[WinAVR]“. Go to it by using start menu.

In the MFile Edit window, you have only two menu: File and Makefile. Click on Makefile, and change MCU Type to ATmega8,

Change main program name to firstprog.c

Now Click File>Save As, and provide filename MAKEFILE with no extensions, in the same directory where you created the firstprog.c

Now go back to programmers notepad, and select, Tools>[WinAVR] Make All

If there is no typo or other problems, the output window (Viewed by pressing F8) will show like this.

Congratulations, you have successfully compiled your first program. (Well, hopefully :-| )

Your compiled files are in the folder:

Cont.. (Really) Beginners Microcontroller Guide (Part-II) Configuring Ponyprog properly and writing program to uC

মন্তব্য নেই