CSE391: Embedded Systems and Interfacing Introduction to Microcontrollers Nazmus Saquib Lecturer Department of Computer Science and Engineering Bangladesh University of Engineering and Technology April 22, 2018 Nazmus Saquib (Lecturer of CSE, BUET) Microcontroller April 22, 2018 1 / 25
Introduction Introduction to Microcontrollers Microprocessor by itself is not functional Needs external units like RAM, ROM, I/O ports, timer, etc. Microcontrollers provide limited amount of these resources Nazmus Saquib (Lecturer of CSE, BUET) Microcontroller April 22, 2018 2 / 25
Introduction Difference between Microprocessor and Microcontroller Microprocessor CPU is standalone Designer can decide on the amount of resources Expensive General purpose Microcontroller CPU, RAM, ROM, I/O Ports, and timer are all on the same chip Resources are fixed Cost effective Special purpose Nazmus Saquib (Lecturer of CSE, BUET) Microcontroller April 22, 2018 3 / 25
Introduction Difference between Microprocessor and Microcontroller Microprocessor CPU is standalone Designer can decide on the amount of resources Expensive General purpose Microcontroller CPU, RAM, ROM, I/O Ports, and timer are all on the same chip Resources are fixed Cost effective Special purpose Nazmus Saquib (Lecturer of CSE, BUET) Microcontroller April 22, 2018 3 / 25
Introduction Difference between Microprocessor and Microcontroller Microprocessor CPU is standalone Designer can decide on the amount of resources Expensive General purpose Microcontroller CPU, RAM, ROM, I/O Ports, and timer are all on the same chip Resources are fixed Cost effective Special purpose Nazmus Saquib (Lecturer of CSE, BUET) Microcontroller April 22, 2018 3 / 25
Introduction Difference between Microprocessor and Microcontroller Microprocessor CPU is standalone Designer can decide on the amount of resources Expensive General purpose Microcontroller CPU, RAM, ROM, I/O Ports, and timer are all on the same chip Resources are fixed Cost effective Special purpose Nazmus Saquib (Lecturer of CSE, BUET) Microcontroller April 22, 2018 3 / 25
Introduction Difference between Microprocessor and Microcontroller Microprocessor CPU is standalone Designer can decide on the amount of resources Expensive General purpose Microcontroller CPU, RAM, ROM, I/O Ports, and timer are all on the same chip Resources are fixed Cost effective Special purpose Nazmus Saquib (Lecturer of CSE, BUET) Microcontroller April 22, 2018 3 / 25
Introduction to Atmel AVR ATmega32 Which microcontroller will we be using? Atmel AVR ATmega32 OR Atmel AVR ATmega16 Nazmus Saquib (Lecturer of CSE, BUET) Microcontroller April 22, 2018 4 / 25
Introduction to Atmel AVR ATmega32 Which microcontroller will we be using? Atmel AVR ATmega32 OR Atmel AVR ATmega16 Nazmus Saquib (Lecturer of CSE, BUET) Microcontroller April 22, 2018 4 / 25
Introduction to Atmel AVR ATmega32 Naming Convention of ATmega32 Atmel AVR ATmega32 AT Atmel mega series name (others are tiny and Xmega) 32 flash memory size 32KB Nazmus Saquib (Lecturer of CSE, BUET) Microcontroller April 22, 2018 5 / 25
Introduction to Atmel AVR ATmega32 ATmega32 Pinout Nazmus Saquib (Lecturer of CSE, BUET) Microcontroller April 22, 2018 6 / 25
Introduction to Atmel AVR ATmega32 Features of ATmega32 8-bit microcontroller 32 8-bit general purpose CPU registers Three types of memories: 1 Flash (32KB) 2 EEPROM (1KB) 3 SRAM (2KB) Von Neumann vs Harvard Architecture Nazmus Saquib (Lecturer of CSE, BUET) Microcontroller April 22, 2018 7 / 25
Introduction to Atmel AVR ATmega32 Features of ATmega32 8-bit microcontroller 32 8-bit general purpose CPU registers Three types of memories: 1 Flash (32KB) 2 EEPROM (1KB) 3 SRAM (2KB) Von Neumann vs Harvard Architecture Nazmus Saquib (Lecturer of CSE, BUET) Microcontroller April 22, 2018 7 / 25
Introduction to Atmel AVR ATmega32 ATmega32 Flash Memory Divide into two sections: Application section Boot section Nazmus Saquib (Lecturer of CSE, BUET) Microcontroller April 22, 2018 8 / 25
Programming the ATmega32 Required Hardware Obvious components: ATmega32, circuit components, etc. Special component: Programmer aka Writer aka Burner We will be using USBasp (or its derivative) as our programmer Nazmus Saquib (Lecturer of CSE, BUET) Microcontroller April 22, 2018 9 / 25
Programming the ATmega32 USBasp Programmer (and its Derivative) Nazmus Saquib (Lecturer of CSE, BUET) Microcontroller April 22, 2018 10 / 25
Programming the ATmega32 Required Software For Windows Users... Atmel Studio IDE http://www.microchip.com/avr-support/atmel-studio-7 AVRpal Burner https://sourceforge.net/projects/avrpalnet/ USBasp Driver https://bit.ly/26hhvxq Nazmus Saquib (Lecturer of CSE, BUET) Microcontroller April 22, 2018 11 / 25
Programming the ATmega32 Installing the Software Installing IDE and burner is easy Installing driver requires some way around for Windows 8 and above Newer Windows OS does not allow 3rd party drivers by default We need to disable driver signature enforcement Nazmus Saquib (Lecturer of CSE, BUET) Microcontroller April 22, 2018 12 / 25
Programming the ATmega32 Disabling Driver Signature Checking Click restart while holding down the shift key Troubleshoot >Advanced >Startup Settings Find Disable driver signature enforcement from the list Type in the corresponding number Once the machine restarts you can install 3rd party drivers Nazmus Saquib (Lecturer of CSE, BUET) Microcontroller April 22, 2018 13 / 25
Programming the ATmega32 Installing USBasp Driver Plug in USBasp Go to device manager You should find USBasp with an exclamation sign Right click, go to properties, and update driver Select search computer for driver and select the unzipped folder A warning might pop up, confirm Nazmus Saquib (Lecturer of CSE, BUET) Microcontroller April 22, 2018 14 / 25
Programming the ATmega32 Steps in Programming Microcontroller 1 (Atmel Studio) Write code 2 (Atmel Studio) Generate hex file 3 (USBasp, microcontroller) Connect µc USBasp PC 4 (AVRpal, USBasp Driver) Burn hex file to microcontroller Nazmus Saquib (Lecturer of CSE, BUET) Microcontroller April 22, 2018 15 / 25
Programming the ATmega32 Steps in Programming Microcontroller 1 (Atmel Studio) Write code 2 (Atmel Studio) Generate hex file 3 (USBasp, microcontroller) Connect µc USBasp PC 4 (AVRpal, USBasp Driver) Burn hex file to microcontroller Nazmus Saquib (Lecturer of CSE, BUET) Microcontroller April 22, 2018 15 / 25
Programming the ATmega32 Steps in Programming Microcontroller 1 (Atmel Studio) Write code 2 (Atmel Studio) Generate hex file 3 (USBasp, microcontroller) Connect µc USBasp PC 4 (AVRpal, USBasp Driver) Burn hex file to microcontroller Nazmus Saquib (Lecturer of CSE, BUET) Microcontroller April 22, 2018 15 / 25
Programming the ATmega32 Steps in Programming Microcontroller 1 (Atmel Studio) Write code 2 (Atmel Studio) Generate hex file 3 (USBasp, microcontroller) Connect µc USBasp PC 4 (AVRpal, USBasp Driver) Burn hex file to microcontroller Nazmus Saquib (Lecturer of CSE, BUET) Microcontroller April 22, 2018 15 / 25
Programming the ATmega32 Using Atmel Studio: Create Project Nazmus Saquib (Lecturer of CSE, BUET) Microcontroller April 22, 2018 16 / 25
Programming the ATmega32 Using Atmel Studio: Select Device Nazmus Saquib (Lecturer of CSE, BUET) Microcontroller April 22, 2018 17 / 25
Programming the ATmega32 Using Atmel Studio: Build Project Nazmus Saquib (Lecturer of CSE, BUET) Microcontroller April 22, 2018 18 / 25
Programming the ATmega32 Using Atmel Studio: Build Success Successful build creates a hex file Hex file is created in debug folder of project directory We need to burn this file to our microcontroller Nazmus Saquib (Lecturer of CSE, BUET) Microcontroller April 22, 2018 19 / 25
Programming the ATmega32 Understanding USBasp Pinout Pin description is provided at the back One to one correspondence with the header Do not twist, look directly into the header CORRECT Nazmus Saquib (Lecturer of CSE, BUET) INCORRECT Microcontroller April 22, 2018 20 / 25
Programming the ATmega32 Understanding USBasp Pinout (Cntd.) Vcc (10) MOSI (6) GND (11) RESET (9) SCK (8) MISO (7) Nazmus Saquib (Lecturer of CSE, BUET) Microcontroller April 22, 2018 21 / 25
Programming the ATmega32 USBasp Derivative Header pins are explicitly written Connections are similar Also possible to use the socket Nazmus Saquib (Lecturer of CSE, BUET) Microcontroller April 22, 2018 22 / 25
Programming the ATmega32 AVRpal Nazmus Saquib (Lecturer of CSE, BUET) Microcontroller April 22, 2018 23 / 25
Summary Summary Things we have learnt: Difference between µp and µc Basic features of ATmega32 How to program ATmega32 We left out: how to write our code? We will learn to write our code in next class Nazmus Saquib (Lecturer of CSE, BUET) Microcontroller April 22, 2018 24 / 25
Summary Summary Things we have learnt: Difference between µp and µc Basic features of ATmega32 How to program ATmega32 We left out: how to write our code? We will learn to write our code in next class Nazmus Saquib (Lecturer of CSE, BUET) Microcontroller April 22, 2018 24 / 25
Questions Questions? Nazmus Saquib (Lecturer of CSE, BUET) Microcontroller April 22, 2018 25 / 25