Professional Documents
Culture Documents
Implement of A Bluethooth Protocol Stack On A Low-Cost Microcontroller
Implement of A Bluethooth Protocol Stack On A Low-Cost Microcontroller
127
Abslrocl-This paper describes the creation and implementation of a Bluetooth protocol stack for an eight-bit microcontroller, using only open-source or freely available software to keep costs at a minimum. The created stack was used to successfully establish a Bluetooth-based connection between an Atmel microcontroller and a nearby computer.
Index Terms-Bluetooth,
microcontroller, protocol
INTRODUCTION Bluetooth was introduced in 1998 as a short range, wireless communication technology. It has been used widely as a cable replacement technology, as is demonstrated in various wireless headsets available for cell phones, and wireless printers which make use of Bluetooth technology. The ability to communicate to almost any electronic device wirelessly has widened the scope of applications for small microcontrollers. They can now easily be used for remote sensors, short-range communication and security applications, to name but a few [I]. Various one-chip Bluetooth solutions are available on the market today containing an integrated microcontroller, hut these are usually very limited in their performance, and it is preferable to implement the upper section of the Bluetooth protocol stack [Z] on a separate microcontroller. This makes more processing power available for applications by allowing more powerful processors to be used and provides a greater level of control over the wireless connection. The cost involved with developing Bluetooth capable products can be quite high. This includes the cost of the Bluetooth hardware, and other sofhvare necessary to add Bluetooth capability to a small system. To address this problem, we created a small Bluetooth capable embedded system using almost exclusively opensource, or freely available software. One of the main factors taken into consideration during development was to limit the amount of memory used by the stack. A stack that takes up to much memory would hinder development of other applications that make use of it.
I.
The initial design of the system, especially with regards to the hardware, is based on the work done by Beutel and Kasten [3]. The Ahnel ATmegalZSL microcontroller [4] was used as a host controller, and provides an 8-bit AVR RlSC microcontroller with 128 KB of in-system programmable program memory and 4 KB S U M . It also has two serial ports, which allows the Bluetooth module to he connected to one port, whilst the other port can he used to send various data to a connected computer, depending on the application. During development, state information regarding the Bluetooth protocol stack was sent via the serial port to monitor the intemal workings of the protocol stack The ATmegalZBL is a low-voltage ( 3 . 3 ~ ) capable microcontroller running at 8 MHz. It was chosen to be compatible with the Bluetooth module, which also runs on a low voltage. A 5v variant of the microcontroller is also available, which is capable ofrunning at 16 MHz. The microcontroller is connected to a Mitsumi Bluetooth module through a serial interface. The Bluetooth module is based on C S R s Bluecore technology [ 5 ] . Although the module is capable of hnctioning as a single-chip Bluetooth solution, for the purposes of this project it was set up with only the sections of the Bluetooth protocol stack helow the HCI layer.
G. P.Hancke (e-mail:ghaneke~~eng.up.ac.za).
B. Sofmare Used A number of open source and freely available software packages were used in order to reduce the total cost of development. I) A VR-GCC AVR-GCC is a modified version of the popular opensource GCC compiler, capable of compiling C code for use on Atmel microcontrollers based on the AVR core. The compiler provides for transparent use of common C functions such as malloc a n d p r i n 6 with certain restrictions imposed to reduce memory usage. 2) A VRDUDE After a program is successfully compiled, it needs to be transferred to the microcontroller. AVRDUDE does this by making use of the microcontrollers in-circuit programmability. No additional programming hardware is required, except a simple parallel cable, reducing development cost considerably.
128
I ,
UCAP
HCt Control
Radio
EX",
Command
Command
Fig. 2. A functional layout of the HCI layer. This figure describes the flow of data through the HCI layer from the micmconWllers serial interface with the Bluetooth module.
function. In the same manner, whenever an L2CAP level connection is established an indication is sent to the higher layers, and a response expected. Since the higher layers were not implemented in this project, the responses are
129
Fig. 3. A functional layout of the LZCAP layer. The main functional section$ ofthe LZCAP layer i s shown here.
simulated. In order to keep track of the internal workings of the stack during development, a large amount of debugging messages were output to another computer through the microcontrollers serial port. By default programs are compiled in such a way as to automatically load these strings into the microcontrollers memory at startup, and this quickly took up almost all of the available memory. To prevent this from happening, these debugging messages were coded to only load into a pre-defined section of memory when needed. Using Kasatkins documentation [6] three basic test programs were written to test the functionality of the system throughout development. All these programs ran on a Linux based computer using the Affix stack. The Affix stack was used on the computer since it allowed easy development of programs using Bluetooth technology, and was one of the most up to date open-source protocols available at the time of development. Communicating with different implementations of the stack also provides a good measure of compatibility for the final system. A server program was created to listen for incoming Bluetooth connections, as well as a client program that would attempt to connect to a Bluetooth device with a known IP. The third program was a detection program, which would use a Bluetooth module attached to the computer to locate any Bluetooth devices within range, and read their IP addresses.
111. FINAL TESTMG AND RESULTS
A. TeslSelup
IV. CONCLUSION
Using open source software to develop Bluetooth based products is not only viable, but a very effective method of reducing development costs. With the addition of flow control between the microcontroller and Bluetooth module, and some additional memory, the performance of the system can he significantly improved. Also, the removal of the debugging messages, which are constantly being processed, would increase the available processing power significantly. The 5v variant microcontroller could easily be used since the slave hoard for the Bluetooth module provides for the necessary voltage conversion, and this would allow an increase in clock speed from 8 MHz to 16 MHz, also boosting available processing power significantly.
The Linux based computer was used as a sender, with a custom test program written for final testing. The test program would ahempt to connect to a Bluetooth device with a known IP, which in this case was our microcontroller. When a connection was established, a string of data read from the keyboard would he sent to the microcontroller via the Bluetooth connection. The microcontroller was set up to listen for an incoming connection. When a connection was created, it would take the received data, modify it slightly to show that it did indeed pass through the microcontroller, and re" it to the
130
ACKNOWLEDGMENT
We would like to thank D. Johnson and the CSIR for their assistance in setting up and integrating the Bluetooth module as well as the use o f their slave board design for the Bluetooth module. REFERENCES
[I] P. Bhagwal, 2001, "Blueloolh: technology for shon-range wireless
apps", hlernel Compuling Vol. 5 . Issuc3,96-103 121 Bluetooth Special Interest Group, Specifications of the Blueloath
system "1.1,20W
[3]
(41
J. Beutel, 0.Kaslen, A minimal Blueioorh bosed compuling and communico,bn PlOCnn. 2001, Available: httn:ll~~ww.tik.ee.rthzchi-beotelioub.hlml ATmegal28L Damheet, Almel microelectronics, 2003, Available:
htlp:llu?uu.slmel.com [ 5 ] Bluecore Product data sheet, CSR, 2002 [6] D. Kasalkin, AJJii in LI nuishell 2002, Available from h ~ l ~ : l l a f ~ ~ . x ~ u r c c f ~ ~ ~ . ~ ~ ~ ~ N ~ ~ - ~ ~ ~ l i ~ d ~ ~ . h l m l