Introduction

In this tutorial, we will learn how to set up your computer to work with BTnodes. This will involve installing all the necessary drivers and tools, as well as setting up your programming environment. Then, we will download the source code for the operating system and upload sample applications onto the BTnode. Finally, we will starting writing our own programs.

Installation

For the sake of this tutorial, we will be working in Windows XP. It is possible to work with BTnodes in Linux, but this is more difficult and less intuitive. For more information, see Installation. For the Windows platform, most of the installation steps are described in detail at WinInstall, including a quick summary for advanced users.

Cygwin

We strongly recommend to install Cygwin on your Windows machine. The main reason in this context is the command line building tool make that comes with Cygwin and that we require to compile our C projects. There are other possibilities, but here we will stick with Cygwin. You can download it from http://www.cygwin.com, and make sure to select the make package during installation.

USB Driver

In order to communicate with the BTnode once it is installed and is running a program, we use a Silabs CP2101 extension board that allows us to attach the device to the computer via USB. This requires us to install the appropriate drivers that create a virtual COM (serial) port to speak to the BTnode. Download this from here and install.

WinAVR

The BTnode is based on the ATmega128 from the Atmel AVR series. In order to compile programs for this platform and to upload code to the device, we need to install WinAVR (http://winavr.sourceforge.net/), which can be obtained from sourceforge. This installer automatically inserts the WinAVR directory into the path which means we can access the avr-gcc compiler and the uisp uploader from any shell location and from inside Eclipse.

Eclipse

We will use the Eclipse IDE (Integrated Development Environment) to develop our programs. This is not strictly necessary, any other IDE will work fine. However, for this tutorial, we will be using Eclipse in our examples.

Eclipse was originally designed for Java programming and is also written in Java. Hence it requires a JRE (Java Runtime Environment) to be installed. If this is not the case, take the time now to rectify the situation. The latest JRE is available from http://www.java.com. Eclipse is available at http://www.eclipse.org, the latest snapshot can be downloaded from here. Download this archive and extract it to your location of choice. This can be C:\Program Files or even C:\, which we will use here.

In order to create and maintain C or C++ projects, you need to install an Eclipse plugin called CDT (C/C++ Development Tools). This can be done by directing the Eclipse Update Manager to http://download.eclipse.org/tools/cdt/releases/eclipse3.1 or manually by downloading the package and unzipping it in the same location as previously.

Obtaining Source Code

Now we have installed everything we need to be able to write, compile and upload programs to our BTnode, and need just one more thing. It is time to get the source code for the operating system we need to compile our code against and some sample programs to help us understand how to program the BTnode.

The ethernut project (http://www.ethernut.de) is an open source hardware and software project for building tiny embedded ethernet devices. The operating system (OS) source code is hosted on sourceforge. The BTnode hardware is slightly different, and hence it requires an altered OS. However, ethernut forms the core of our OS. The btnut project on sourceforge defines a layer on top of ethernut that forms our OS.

Btnut Source

In order to get the latest development version of our operating system source code, we will fetch it directly from sourceforge's CVS server. If you do not have Cygwin installed, please follow the instructions at WinInstall.

Open a Cygwin shell and direct it to your eclipse workspace directory (Here: C:\workspace). Type the following command and hit enter, and you should see something like this:

user@host /cygdrive/c/workspace
$ cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/btnode co btnut
cvs checkout: Updating btnut
U btnut/AUTHORS
U btnut/COPYING
...
U btnut/extras/teco_ssmall/tsl2550.c
U btnut/extras/teco_ssmall/tsl2550.h

Once this process completes, you should have a btnut directory containing the newest sources for our OS.

Nut Source

Now, to be able to compile these sources, we need the ethernut sources. To fetch these, first enter the btnut directory and then issue the make command as follows. When you are prompted for a password, just hit enter.

user@host /cygdrive/c/workspace
$ cd btnut/
user@host /cygdrive/c/workspace/btnut
$ make nut-cvs-sources
rm -rf nut
cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/ethernut login
Logging in to :pserver:anonymous@cvs.sourceforge.net:2401/cvsroot/ethernut
CVS password:
cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/ethernut co -D \
2005-10-05 nut
cvs checkout: Updating nut
U nut/.cvsignore
U nut/AUTHORS
...
U nut/tools/win32/README
mv nut ../

This command automatically downloads the correct version of the ethernut sources into a new directory nut in the workspace directory. To check that everything went as planned, we can now compile the sources by issuing make install as follows:

user@host /cygdrive/c/workspace/btnut
$ make install
make -C btnode install
make[1]: Entering directory `/cygdrive/c/workspace/btnut/btnode'
make -C bt install
make[2]: Entering directory `/cygdrive/c/workspace/btnut/btnode/bt'
avr-gcc -c -mmcu=atmega128 -Os -Wall -Werror -Wstrict-prototypes
...
make[2]: Leaving directory `/cygdrive/c/workspace/btnut/btnode/support'
make[1]: Leaving directory `/cygdrive/c/workspace/btnut/btnode'

If this does not issue an error message like make: *** [install] Error 2, then everything should be fine.

Creating Eclipse Projects

Now we have all the source code we need, but before we can program, we need to create the corresponding projects in Eclipse. Therefore open Eclipse (with the CDT plugin installed). Set the workspace to whatever you have defined. Open File => New => Project, then select C => Standard Make C Project, and click Next. Enter btnut and click Finish. Eclipse will then ask you to switch to the C Perspective. Answer yes. Now, open File => New => Standard Make C Project, enter nut and press Finish. You should have one project folder for btnut and one for nut.

Next, expand the btnut project on the left side and open the app/bt-cmd folder. Here, open the bt-cmd.c file. Look at the source code - this is a BTnode application. In order to compile this program directly from within Eclipse, please refer to WinInstall. We will continue to compile from command line. For this purpose, navigate your Cygwin shell to the app/bt-cmd directory and enter make.

user@host /cygdrive/c/workspace/btnut
$ cd app/bt-cmd

user@host /cygdrive/c/workspace/btnut/app/bt-cmd
$ make
avr-gcc -c -mmcu=atmega128 -Os -Wall ...
avr-gcc bt-cmd.btnode3.o  ...  -o bt-cmd.btnode3.elf
avr-size bt-cmd.btnode3.elf
   text    data     bss     dec     hex filename
  58668     920     155   59743    e95f bt-cmd.btnode3.elf
avr-objcopy -O ihex bt-cmd.btnode3.elf bt-cmd.btnode3.hex
rm bt-cmd.btnode3.elf

This creates a file called bt-cmd.btnode3.hex, which contains the bt-cmd program code executable in BTnode instructions.

Uploading programs to the BTnode

Finally, we need to upload this code to the BTnode. For this purpose you need to have the BTnode connected to your computer via USB and you need to know which virtual COM port it is using. There is a special make target that will send the program to the BTnode, but first we need to tell make which port to use. Therefore, go back to Eclipse and open the file btnut/Makedefs. Look for the statement BURNPORT = /dev/ttyS0 and change this to BURNPORT = COMx where x represents your port number. Now, we can go back to the Cygwin shell and execute make burn btnode3, which will trigger the uisp uploader to send the created binary file to the BTnode. This is a bit tricky, as you need to press the reset button on the BTnode (see WinInstall for details on how to find it), and release it when the uploader is ready to send the data. If all goes well, it should look like this:

user@host /cygdrive/c/workspace/btnut/app/bt-cmd
$ make burn btnode3
make burn.btnode3
make[1]: Entering directory `/cygdrive/c/workspace/btnut/app/bt-cmd'
uisp -dprog=stk500 -dpart=atmega128 -dserial=COM3  --erase --upload\
 if=bt-cmd.btnode3.hex
Firmware Version: 1.15
Atmel AVR ATmega128 is found.
Firmware Version: 1.15
Uploading: flash
make[1]: Leaving directory `/cygdrive/c/workspace/btnut/app/bt-cmd'
make: Nothing to be done for `btnode3'.

If you get the following instead, then just keep the reset button pressed and execute the command again.

user@host /cygdrive/c/workspace/btnut/app/bt-cmd
$ make burn btnode3
make burn.btnode3
make[1]: Entering directory `/cygdrive/c/workspace/btnut/app/bt-cmd'
uisp -dprog=stk500 -dpart=atmega128 -dserial=COM3  --erase --upload\
 if=bt-cmd.btnode3.hex
[VP 1] Device is not responding correctly.
make[1]: *** [burn.btnode3] Error 2
make[1]: Leaving directory `/cygdrive/c/workspace/btnut/app/bt-cmd'
make: *** [burn] Error 2

Congratulations, you have just uploaded your first program to the BTnode!

Communicating With Your Program

Now the program is running on the BTnode, which is indicated by the blue blinking LED. In order to see what the program is doing, we need to access its terminal, again using the virtual COM port. For this purpose, we will use HyperTerminal, which you can find in the start menu under Start => Programs => Accessories => Communications => HyperTerminal. First, it will prompt you for a connection name, and you can choose whatever you like. Next, you need to select the appropriate COM port. In the following dialog, you need to set the following connection settings:

  • bits per second: 57600
  • Data bits: 8
  • Parity: None
  • Stop bits: 1
  • Flow Control: None

You can now save this connection for later. If you press the reset button on your BTnode once, you should see the bt-cmd interface like this:

# --------------------------------------------
# Welcome to BTnut (c) 2005 ETH Zurich
# bt-cmd program version: 20060112-0913
# --------------------------------------------
booting bluetooth module... ok.
hit tab twice for a list of commands
[bt-cmd@btnode]$

Starting up bluetooth takes a few seconds, this is normal. From the command prompt, you can hit tab twice to find out all the possible commands. For now, we will be content with checking that the MAC address of the device is indeed the same as the one on the label on the side of the BTnode. Therefore, enter addr and compare the two.

[bt-cmd@btnode]$addr
Local bt_addr: 00:04:3f:00:01:2f (error code=0)

If this is successful, you are finished. You have now installed all the necessary tools to be able to write programs, compile them, upload them to the device, and interact with them. Next time, we will expand on this and write our own little program.

!!! Dieses Dokument stammt aus dem ETH Web-Archiv und wird nicht mehr gepflegt !!!
!!! This document is stored in the ETH Web archive and is no longer maintained !!!