1. Introduction 1.1 Project Overview The purpose of this work is to provide a sample project that will introduce how to use an Atmel AVR STK500 Microcontroller Starter Kit [1] and an external device, in this case a mytwi Temperature Sensor [2], to establish a basic data acquisition (DAQ) system. The instructions given to achieve this are written in a style that is a mix between general and specific so one can gain a more complete understanding on why some of the instructions are necessary as well as to provide a venue for one to implement a completely different project using the same utilities used for this DAQ project. The most important aspect of DAQ system produced is how to achieve communication amongst the AVR microcontroller unit (MCU), the host personal computer (PC) and the temperature sensor. This project requires the use of many technical terms specific for Atmel microcontrollers and for commonly used electronic devices and standards. Hence, a glossary has been provided in Appendix section A.1 to help further the user s understanding of the DAQ system formed in this project. 1.2 Project Materials This section includes a listing of both the required and additional materials used to produce the sample projects provided in this work. 1.2.1 Required Materials Note: The preceding numbers within parentheses denote quantity. AVR STK500 Microcontroller Starter Kit (described in more detail in section 2, Hardware Connectivity), which includes: o (1) STK500 printed circuit board (shown in Figure 1.4) o (1) 6-wire cable for In-System Programming (shown in Figure 1.1) o (2) 10-wire cables for input/output ports and parallel mode programming (shown in Figure 1.1) o (4) 2-wire cables for input/output ports, USART, and DataFlash connections (shown in Figure 1.1) Vincent A. Rosa Florida Gulf Coast University Page 1 of 11
o (1) 9-pin RS-232 cable (shown in Figure 1.2) o (1) DC power cable (shown in Figure 1.3) o (1) Atmel CD-ROM with datasheets and software o (1) ATmega8515L-8PU sample microcontroller Host PC meeting the following minimum requirements: o Pentium -class processor o 64MB RAM for Windows 9x platforms and 128MB RAM for Windows NT/2000/XP platforms (it is recommended to have double these amounts) o 200MB free hard disk space (for AVR Studio, WinAVR, and CodeVisionAVR) o Windows 95/98/2000/ME/XP/Vista or Windows NT 4.0, or higher (Note: XP is used for all provided examples) o One of the following combinations: (2) 115200 baud (115.2 kbps) RS-232 ports (COM ports); (1) RS-232 port and (1) USB port; or (2) USB ports (1) 10-15 V AC or DC power supply with a 500 ma minimum (Figure 1.3 shows some examples of valid power supplies that were used with this project) (1) Additional 9-pin RS-232 cable (Note: (2) RS-232 serial-to-usb cables were used in this project; one is shown in Figure 1.2. The use of regular RS-232 serial cables versus RS-232 serial-to-usb cables is dependent on the features of the host PC used for the project) (1) mytwi Temperature Sensor (ordered online from myavr at http://shop.myavr.com/index.php?sp=article.sp.php&artid=71) AVR Studio 4.16 or later (integrated development environment provided by Atmel; available online at http://www.atmel.com/dyn/products/tools_card.asp?tool_id=2725) WinAVR 20090313 or later (contains all of the tools for AVR development on a Windows platform, which includes the GNU GCC compiler for C/C++, the avr-gcc compiler, the avrdude programmer, and the avr-gdb debugger; available online at http://winavr.sourceforge.net/) CodeVisionAVR Evaluation 2.04.1 or later (integrated development environment provided by HP InfoTech; available online at http://www.hpinfotech.ro/html/cvavr.htm) Vincent A. Rosa Florida Gulf Coast University Page 2 of 11
Figure 1.1 From left to right: a 6-wire cable, a 10-wire cable, and a 2-wire cable. Figure 1.2 From left to right, top to bottom: RS-232 serial cable; RS-232 serial cable male-end connector (to STK500); RS-232 serial cable female-end connector (to host PC); RS-232 serial-to-usb cable; RS-232 serial male-end connector of the serial-to-usb cable (to STK500); USB-end connector (to host PC). Figure 1.3 From left to right, top to bottom: DC power cable; 12 V AC, 1000 ma power supply; 10 V DC, 1200 ma power supply. Vincent A. Rosa Florida Gulf Coast University Page 3 of 11
1.2.2 Additional Materials The following list of printed material is highly recommended for those who intend to establish a more complete base of knowledge on the features and functionality of the STK500 and the ATmega8515L MCU: AVR STK500 User Guide [1] ATmega8515(L) Datasheet [4] AVR068: STK500 Communication Protocol [14] The following list of printed material is highly recommended for those who intend to further their knowledge in AVR C programming: avr-libc Reference Manual (available online at http://www.nongnu.org/avr-libc/) AVRDUDE (for Linux users; available online at http://www.nongnu.org/avrdude/) Embedded C Programming and the Atmel AVR, 2 nd Edition [10] AVR Tools Online Help (available at http://support.atmel.no/bin/customer?=&inc=help) 1.3 STK500 Components AVR devices are a set of proprietary RISC microcontrollers distributed by Atmel Corporation. AVR seems to be an acronym, but Atmel has not provided an official definition for what each letter stands. It is speculated within the AVR community that it may either stand for Advanced Virtual RISC or Alf and Vegard s RISC where Alf-Egil Bogen and Vegard Wollan are the founding designers of the AVR RISC microcontroller. The STK500 is an evaluation printed circuit board (PCB) that is meant to help those who are new to AVR Flash development become familiar with developing software for their desired AVR Flash microcontroller. The STK500 PCB is composed of three main sections: Control, Target Socket, and User Interface. Figure 1.4 shows a topside view of the STK500 and is complemented by Figure 1.5, which diagrams the most important components of the STK500. The Control section of the board provides an interface between the host PC and the rest of the board via RS-232 serial communication. The Target Socket section includes plastic dual in-line package (PDIP) sockets, programming headers, and configuration jumpers. The User Interface section consists of push-button switches, LEDs, and input/output (I/O) headers. Vincent A. Rosa Florida Gulf Coast University Page 4 of 11
User Interface Section Target Socket Section Control Section Figure 1.4 Topside view of the STK500 microcontroller. Vincent A. Rosa Florida Gulf Coast University Page 5 of 11
Figure 1.5 Components of the STK500 [1]. The Control section contains the master MCU, which is the driving force of the entire board, and a secondary MCU that performs and ensures proper firmware updates [3]. The master MCU of the STK500 used in this project is an ATmega8535L, and it is what programs the devices installed in the target section and controls the overall functionality of the board, which includes control over the onboard clock generator and the reference and supply (V CC ) voltages [3]. It is important to know that the functionality of the User Interface section of the STK500 is dependent on the installed PDIP device, which must be an AVR Flash microcontroller where at most one can be in control at any given time [3]. The ATmega8515L MCU shown in Figure 1.6 is the PDIP device that came factory installed in target socket SCKT3000D3 on the board used in this project. The complete list of features of the ATmega8515L goes beyond the scope of this project, but they can be obtained from its respective datasheet provided by Atmel [4]. Vincent A. Rosa Florida Gulf Coast University Page 6 of 11
ATmega8515L MCU Figure 1.6 The ATmega8515L-8PU installed on a STK500 PCB at target socket SCKT3000D3 (the ATmega8515L-8PU is an 8-bit RISC MCU in PDIP form). 1.3.1 Target Sockets and ISP Headers The STK500 User Guide explains, In-System Programming [ISP] uses the AVR internal SPI (Serial Peripheral Interface) to download code into the flash and EEPROM memory of the AVR. ISP requires only V CC, GND [ground], RESET, and three signal lines for programming [1]. All of the target sockets correspond to a specific 6-pin target ISP header and are colorand number-coordinated with their respective target header as seen in Figure 1.4. For example, the source header labeled ISP6PIN needs to be connected to the target header labeled SPROG3 to program the flash and EEPROM memories used by the MPU. Enabling SPROG3 also allows for programming all other sockets that are bordered with the color red and have a label ending in the number 3 (the close-up in Figure 1.7 shows these relationships). The SPROGx ISP headers, where x represents the number for a specific header, enable serial programming via the port labeled RS232 CTRL. The RS-232 serial communication protocol is used as implied by the label of this port. Vincent A. Rosa Florida Gulf Coast University Page 7 of 11
A free red socket (SCKT3300D3) A target 6-Pin, red ISP header (SPROG3) The source 6- Pin ISP header (ISP6PIN) ATmega8515L PDIP in a red socket (SCKT3000D3) Figure 1.7 Color- and number-coordinated MPU Socket with corresponding ISP Headers. Section 2, Hardware Connectivity, further explains the hardware aspects of communication, and section 4, Application Programming, further explains the software implementations that correspond to this physical communication. 1.3.2 Switches, LEDs, and Input/Output Ports The STK500 comes with a set of eight programmable buttons that function as switches, and they are labeled from SW0 through SW7. The header labeled SWITCHES shown in Figure 1.8 is what needs to be used to enable control over these buttons, or switches. Similarly, the set of seven LEDs labeled from LED0 through LED7 are controlled via the LEDS header shown in Figure 1.9. Figures 1.10 and 1.11 provide the respective circuit diagrams for a push-button switch and for an LED as well as respective pinout views for the SWITCHES and LEDS headers. Vincent A. Rosa Florida Gulf Coast University Page 8 of 11
Figure 1.8 From left to right, top to bottom: buttons SW7, SW6, and SW5; LEDs LED7, LED6, and LED5; and headers SWITCHES, PORTA, and PORTD. Figure 1.9 From left to right, top to bottom: buttons SW2, SW1, and SW0; LEDs LED2, LED1, and LED0; and headers LEDS, PORTB, and PORTC. Figure 1.10 From left to right: Hardware Implementation of the Switches and Switch Header [1]. Figure 1.11 From left to right: Hardware implementation of an LED; pinout of the LEDS header [1]. The hardware setup used in this project for the buttons and LEDs is further explained in section 2.3.1, and the corresponding software to this physical setup is explained in section 4.1.1 of this document. The input/output (I/O) ports within the User Interface section of the STK500 are controlled by the installed PDIP device. Each I/O port header has seven I/O pins, one ground (GND) pin, and one voltage (VTG) pin as shown in Figure 1.12. The middle letter of each pin corresponds to the letter of the respective port to which each pin belongs (e.g. PD0 is pin 0 of the Vincent A. Rosa Florida Gulf Coast University Page 9 of 11
PORTD header). The only exception to this nomenclature is with the PORTE/AUX header. The I/O port header PORTE/AUX shown in Figure 1.12 can function as either a regular I/O port or as an auxiliary port that functions according to the applied jumper settings described in Figure 1.13. The Alternate Port Functions section of the ATmega8515(L) Datasheet [4] has a complete list and explanation of the alternate functions served by ports A through E with respect to the ATmega8515L MCU. Figure 1.12 From left to right: Pinout of an I/O port header; pinout of the PORTE/AUX header [1]. Figure 1.13 Auxiliary header special functions with respect to certain jumper settings and the PORTE/AUX header [1]. Vincent A. Rosa Florida Gulf Coast University Page 10 of 11
1.4 mytwi Temperature Sensor Components The mytwi Temperature Sensor used for this project is a PCB containing an LM75 temperature sensor [2], and it uses the Two Wire Interface (TWI) more commonly known as the Inter- Integrated Circuit (I 2 C) bus [5] for communication to an external device. The two most essential lines used in I 2 C communication are the Serial Data (SDA) and Serial Clock (SCL) lines, which are controlled with both pull-up resistors and pull-up jumpers as seen in Figure 1.14 [2]. Address Jumpers LM75 Temperature Sensor SDA Line SCL Line Pull-Up Resistors Pull-Up Jumpers Figure 1.14 Main components of the mytwi Temperature Sensor. Vincent A. Rosa Florida Gulf Coast University Page 11 of 11