Microcontroller Systems (KON 309E) : Lecture Notes (WEEK 1)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Microcontroller Systems

(KON 309E)

LECTURE NOTES
(WEEK 1)
Introduction

1.1. Preliminaries (What is a microcontroller?)

A microcontroller (μC) is a single-chip, small and low-cost computer, which is designed to


perform the given tasks in industrial, commercial, and personal applications by running the
commands stored in the program memory [1].

The main difference from a microprocessor is that external components (such as peripheral
units, memory, clock, etc.) are required to operate a microprocessor as a computer.
However, all the required modules are included and ready to use in the microcontrollers. It is
the reason for microcontrollers to be sometimes called as a computer-on-a-chip or a single-
chip-computer. For basic microcontroller definition and tools for programming, you may
refer to “Lecture Notes-2.pdf” document.

There are hundreds of different microcontrollers that differ from each other by features
such as processing speed, memory size, the intention of use, number and variety of
peripheral units, etc. Microcontrollers are used in automatically controlled products and
devices, such as automobile engine control systems, implantable medical devices, remote
controls, office machines, appliances, power tools, toys, and other embedded systems [2].
For an overview on the selection of microcontrollers and basic issues on the programming
tools and languages, you may refer to the document Lecture Notes-1V1.pdf included in the
course materials directory.

1.2. Components of the Microcontrollers:

The main microcontroller components can be listed as follows.


 Central processing unit (CPU)
 Clocks (Generally this lacks but some MCU’s have built-in oscillators, like PIC12 serie)
 Program memory (ROM)
 Data memory (RAM)
 Peripheral units (I/O, ADC, SPI, USART, etc.)
Figure 1.1: A microcontroller consists of a core, clock, memory & peripheral units [1].

 Central processing unit: A central processing unit (CPU) is a part of the


microcontroller which is responsible for processing and executing the instructions
coded by a user. Therefore, it is also possible to state the CPU as the brain of a
microcontroller.

 Clock: For the operation of all sequential (logic) circuits, such as memory and
registers, in a microcontroller, a clock signal is a must. The execution speed of the
instructions in the CPU also depends on the frequency of this clock signal.
Furthermore, the clock is required for data transfer via communication protocols.
The source of the clock signal can be internal or external depending on the
microcontroller and mostly provided by the oscillators.

 Program memory: The on-chip program memory or ROM (Read Only Memory) is a
reserved area where the program code (instructions) is stored. It is also called as a
(programmable) flash memory. Some data used by the microcontroller during
program execution may also be stored in ROM.

 Data memory: The data memory or RAM (Random Access Memory) is a reserved
area which is used to store the temporary variables, constants, registers, etc. used
during the operation of the microcontroller.

 Peripheral Unit: A peripheral unit is a part of a microcontroller that interfaces with


the physical world. GPIOs, I2C, SPI, UART, etc., are the example peripheral units
found in most of the today’s microcontrollers.
2. STM32 Microcontroller Family

2.1. Development Board:

In this course, it is planned to use an STM32 board which has an ARM Cortex-M3 based core
operating at 72MHz, high-speed embedded memories, and an extensive range of peripheral
units. In the following figure, a mini development board that consists of the STM32F103C8T6
microcontroller is illustrated.

Figure 2.1: STM32F103C8T6 microcontroller board.

Detailed information for this development board and pin-out scheme can be found in the
laboratory experiment sheets.

2.2. System Architecture:

STM32 microcontrollers are classified as low, medium, high, and XL-density devices
depending on the model and flash memory size. STM32F103C8T6 microcontroller has 64
Kbytes of flash memory; therefore, it can be found under the medium-density devices. It is
important to know this information since it can be important during the usage of some
peripheral units.

System architecture for the medium-density devices are given as follows.

ICode Bus: It provides connection between the instruction bus of the core and flash memory
instruction interface.

DCode Bus: It connects the load and debug access bus (DCode Bus) of the core to the flash
memory data interface.

System Bus: This bus connects the system bus of the core (peripherals bus) to the bus matrix
that manages arbitration between the core and the DMA.

DMA Bus: DMA bus provides connection between the AHB (master interface) and bus matrix
that manages the access of CPU DCode and DMA to RAM, Flash and peripherals.
Figure 2.2: System architecture for the medium-density STM32 devices [3].

Note: DMA (direct memory access) is a structure used for data communication between the
memory and other devices. Its advantage is that the CPU is partially disabled during the data
communication, thus speeding up the data flow and making the central processing unit less
busy. As a result, the CPU will cease to be the main element in the data flow and provide
opportunities for other processes. The data flow will also be accelerated due to a shorter
route.

Bus Matrix: It manages the access arbitration between the core system bus and the DMA
master bus.

AHB (Advanced High performance Bus): It is a bus protocol introduced by ARM, and used for
connecting components that need higher bandwidth on a shared bus. It is also capable of
waits, errors, and burst data transfers.

APB (Advanced Peripheral Bus): It is another bus protocol designed for low bandwidth
control accesses, such as register interfaces on system peripherals. APB has a much reduced
and low complexity signal list, and burst data transfers are not supported.
3. Preliminaries for Programming

3.1. Logical Operators:


The mostly used logical operators in microcontroller programming can be given as AND, OR,
XOR, and NOT. The truth table for the AND operation is given as below:

Table 3.1: Truth table for the AND operation.


A B A && B
false false false
false true false
true false false
true true true

The truth table for the OR operation is given as below:

Table 3.2: Truth table for the OR operation.


A B A || B
false false false
false true true
true false true
true true true

Finally, the truth table for the XOR operation is given as below:

Table 3.3: Truth table for the XOR operation.


A B A XOR B
false false false
false true true
true false true
true true false

3.2. Number Bases:


A number base is the number or combination of digits that a counting system uses to
represent numbers. The most commonly used number system is the decimal system which is
also known as base 10.

Binary is, on the other hand, the most commonly used non-base 10 system, and consists of
the numbers 0 and 1. Please check some examples illustrated below.
Table 3.4: Conversion between the decimal and binary numbers.
Base-10 Base-2
1 0 0 0 0 1 0b00001
4 0 0 1 0 0 0b00100
14 0 1 1 1 0 0b01110
29 1 1 1 0 1 0b11101

There exist another number base, also known as the hexadecimal system, which is
commonly used in coding and computer systems. In this number base, the digits 0−9 and the
letters, which represent two digits A(10), B(11), C(12), D(13), E(14), F(15), are used.

The conversion between the binary and hexadecimal system is used much in embedded
programming. For this purpose, first of all, any digit of hexadecimal number system can be
represented using only 4 bit as follows, since there exist only 16 digits in hexadecimal
number system.

Table 3.5: Conversion between the hexadecimal and binary numbers.


Hex 0 1 2 3 4 5 6 7
Bin 0000 0001 0010 0011 0100 0101 0110 0111
Hex 8 9 A B C D E F
Bin 1000 1001 1010 1011 1100 1101 1110 1111

Therefore, the simplest way is to create a group of 4 bit of binary numbers, and then replace
the groups with its equivalent hexadecimal digits.

Examples:

⏟ ⏟

⏟ ⏟

⏟ ⏟

3.3. Bitwise Operations:

Bitwise operations allow us to perform logical operations for each bit in the number. These
operations are given in the following table:
Table 3.6: Bitwise operations and examples.
Operator Symbol Example
Bitwise AND & 0b01110100 & 0b00111101 0b00110100
Bitwise OR | 0b01110100 | 0b00111101 0b01111101
Bitwise XOR ^ 0b01110100 ^ 0b00111101 0b01001001
Bitwise Left Shift << 0b00000000 |= (1 << 4) 0b00010000
Bitwise Right Shift >> 0b01000000 >> 3 0b00001000
Bitwise NOT ~ ~ 0b01100001 0b10011110

Bitwise operations are going to be used many times during the programming of the STM32
microcontroller, especially while writing to the registers.

References:

[1] R. Toulson and T. Wilmshurst, Fast and effective embedded systems design: applying the
ARM mbed, Newnes, pp.3-16, 2016.
[2] URL-1, https://en.wikipedia.org/wiki/Microcontroller, “Microcontroller”, Wikipedia,
reached in 24.09.2020.
[3] URL-2, https://www.st.com/resource/en/reference_manual/cd00171190-stm32f101xx-
stm32f102xx-stm32f103xx-stm32f105xx-and-stm32f107xx-advanced-arm-based-32-bit-
mcus-stmicroelectronics.pdf, STM32F103xx Reference Manual, RM0008, reached in:
24.09.2020.

You might also like