Ads

Get STM32 tutorial using HAL at $10 for a limited time!

Thursday, March 17, 2016

ARM Cortex-M3 (STM32F103) Tutorial - I2C Master

In this tutorial, I will explain about I2C protocol and how to use it on STM32F103 microcontroller. I2C (Inter-Integrated Circuit) or sometimes called TWI (Two Wire Interface) is a synchronous serial protocol that only need 2 wire for communication. These wire are SCL for clock line and SDA for data line. Using I2C bus, you can connect devices like temperature sensor, EEPROM, RTC, etc (up to 112 device) just using two wire (plus GND wire). For accessing these device, I2C use 7-bit address. Theoretically 7-bit address space allows 128 addresses, however some addresses are reserved for special purpose. Thus, only 112 address can be used. There is also special method to use I2C with 10-bit address.


I2C is multi-master and multi-slave bus. I2C bus can consists of one or more master device, but only one master device can have an access to I2C bus each time. To communicate with a slave device, master is responsible for sending clock to the slave device. Clock signal is always generated by master. I2C drivers are open-drain, means that they can pull the signal low, but can't drive it high. On each signal line (SCL and SDA) must have a pull-up resistor to restore the signal high when no device is asserting it low.


Monday, February 29, 2016

ARM Cortex-M3 (STM32F103) Tutorial - 4x4 Matrix Keypad

Embedded system applications usually require large number of buttons connected (ex. calculator, cell phone). Keypad is one of the input device that commonly used in embedded system that require large number of buttons. 4x4 matrix keypad have 16 buttons. We can connect this buttons directly to GPIO pin, but it will eat up precious GPIO pin (If we have 16 buttons, then we need 16 GPIO pins). To avoid this trouble, keypad use technique that will save GPIO pin. In this technique, buttons are connected in a matrix (row/column) style.


The internal connection of the buttons in 4x4 matrix keypad is like this:


Sunday, January 31, 2016

ARM Cortex-M3 (STM32F103) Tutorial - Unipolar Stepper Motor

In this tutorial, I will share how control a unipolar stepper motor using STM32F103 microcontroller. If you don't know the basic of the stepper motor, I suggest you to read this article first. To control a stepper motor from microcontroller, we can't directly drive it with GPIO pins because GPIO pins have maximum current that can sink or source from it. To overcome this problem, we can use driver circuit. The driver circuit for unipolar stepper motor can be built by using 4 transistors to drive large current every 4 wires of a stepper motor. It also can be built with ULN2003 IC. This is the circuit for driving a unipolar stepper motor from microcontroller by using ULN2003 IC:


In this tutorial, I will use 28BYJ-48 stepper motor. This motor is very cheap and it also comes with driver module based on ULN2003 IC. This motor runs with 5V supply and has gear inside. The gear reduction ratio is approximately 64:1. If you search from internet, other people say that the gear reduction ratio is actually 63.68395:1.

 

Friday, January 29, 2016

Basic of Stepper Motors

A stepper motor is an electromechanical device which converts electrical pulses into discrete mechanical movements. The shaft of this motor is rotates in discrete step increment when electrical pulses are applied in a proper sequence. Every discrete step of a stepper motor is measured in degree (it can be 1.8° or even smaller depends on the stepper motor type and stepping technique).


This kind of movement is different from DC motors. DC motors is rotates continuously when there is a voltage applied to it and stops when the voltage removed. When the voltage applied to DC motors reversed, the rotation is also reversed. For the stepper motor, we can change the direction of the shaft rotation by reverse the sequence of the applied pulses. The speed of stepper motor shaft rotation is directly related to the frequency input of the pulses. The length of rotation of the stepper motor is directly related to the number of pulses applied.

Sunday, January 10, 2016

ARM Cortex-M3 (STM32F103) Tutorial - System Timer - Delay Function

In this tutorial, I will share how to use system timer (SysTick) for making delay functions. SysTick is a basic countdown timer. SysTick can be used by an operating system to ease porting from another platform. SysTick can be polled by software or can be configured to generate an interrupt. To use SysTick we can reload a value to the reload value register. SysTick reload value register supports value between 0 - 0x00FFFFFF (24-bit).

SysTick can be configured through the 4 registers:


Saturday, January 2, 2016

ARM Cortex-M3 (STM32F103) Tutorial - GPIO - Read Push Button/Switch

In this tutorial, I will explain how to use STM32F103 GPIO peripheral for read input from push button. GPIO (General Purpose Input Output) on STM32F103 can be configure to 4 different modes (input mode, output mode, analog input mode, alternate function mode). For read input from push button, we need to configure GPIO in digital input mode.


STM32F013 has 3 input mode (digital input): input with internal pull-up, input with internal pull-down, and input floating. The logic voltage of STM32 microcontroller is 3.3V, so the logic voltage for GPIO input pins is also 3.3V, but there are several pins that have 5V tolerant. So, we can input 5V logic level to this 5V tolerant input pins. This table below shows I/O voltage level on STM32F103 input pins.