Ads

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

Saturday, March 28, 2015

STM32F4 Discovery Tutorial 4 - Configure Clock Using External Crystal (HSE)

From the first tutorial until this tutorial, the system clock that we use is internal RC oscillator (HSI) which the value is 16 MHz. This can be checked by using this simple code:
#include "stm32f4xx.h"

int main(void)
{
    // Update the system core clock variable 
    // according to current clock register value
    SystemCoreClockUpdate();

    while (1);
}
SystemCoreClockUpdate() function is used for update SystemCoreClock variable that store the value of current system clock. To see this variable value, we can go into debug mode. In the Variables tab, do the right click and select Add Global Variables then select the SystemCoreClock variable. After that we can step over the SystemCoreClockUpdate() by using F10. After that line is executed, the SystemCoreClock is updated to 16 MHz in Variables tab.


Sunday, March 22, 2015

Micromouse Robot

I made micromouse robot for my final project. I made this because I was so excited when I first saw this robot. This is the micromouse that make me excited. This micromouse is named Tetra and made by Kato-san. The size is even smaller compared to Tamiya mini 4 WD.


I was playing mini 4 WD when I was elementary school. Tamiya can run fast and turn in the track as it has rollers. When I first saw micromouse, there is a question came to my head. Why and how micromouse can run fast without touching the wall and can also navigate the maze to reach center of the maze? I even ever think that micromouse is controlled by a remote control, but that’s not true. The fact is micromouse has an algorithm to solve the maze. I was so excited to figure out how to make my micromouse, so I make micromouse robot for my final project. This is my micromouse.


Monday, March 16, 2015

STM32F4 Discovery Tutorial 3 - Get Input from Button

In this tutorial, I will explain how to configure pin as an input from button. I will use user button which connected to PA0.

First, make new project called button or whatever you want. If you don’t know how to make a new project, you can learn from tutorial 2. After that don’t forget to include the library for this project.
#include "stm32f4xx.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_gpio.h"
Every time you want to use GPIO, you must configure RCC (Reset and Clock Control) for each GPIO.
// Enable peripheral clock to GPIOA module
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
// Enable peripheral clock to GPIOD module
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
GPIO_InitTypeDef is a struct which used for input initialization value for GPIO.
// This is struct for configure GPIO
GPIO_InitTypeDef GPIO_InitStruct;