Library 28- L3GD20 3-axis digital gyroscope

Posted on August 21, 2014 at 12:29 PM

MEMS sensor L3GD20 is included on STM32F429-Discovery board, so I made a library to use it. This is 3-axis digital gyroscope, so it can measure rotation in X, Y and Z axis. L3GD20 sensor works with SPI communication, or I2C. On Discovery board is connected for SPI mode, SPI5 is used for communication.

L3GD20 can be set to work in 3 different full scales: 250, 500 and 2000 dps.

Sensor has also possibility to measure temperature, but this is not included in this library.

L3GD20 Library


  • Measure 3 axis rotation
  • Enables high pass filter to stabilize output
  • Selectable 3 full scale modes

Continue reading

Library 27- Read GPS data on STM32F4 devices

Posted on August 20, 2014 at 11:52 AM

Recently I got a cheap GPS module from ebay, NEO-6M. They said that this is flight controller, but position fix is good only on really flat area. When I made a library, I connect my SDcard to STM32F4 to save data, result are here.

To communicate with STM32F4 device, USART is in use. Most GPS modules have by default 9600 baudrate and 1Hz refresh rate of sending data. I got my GPS configured in 115200 baudrate and 5Hz refresh rate, so when you try example, make sure that you change your baudrate to correct value.

GPS Library


  • Parse GPS data
  • Supported NMEA 0183 standard
  • Works with GPGGA, GPRMC, GPGSA, GPGSV NMEA statements
  • Version 1.1 – 22.08.2014
    • Calculate distance between 2 coordinates
    • Calculate bearing between 2 coordinates

Continue reading

Library 26- Rotary encoder on STM32F4xx

Posted on August 14, 2014 at 2:10 AM

A rotary encoder, also called a shaft encoder is an electro-mechanical device than converts the angular position or motion of a shaft to an analog or digital. There are 2 types of rotary encoders:

  • Incremental – output indicates just rotation clockwise or counterclockwise
  • Absolute – output indicates current position for encoder

For that purpose I made a one simple library. This library works for incremental rotary encoders. It uses an interrupt to handle rotations. On the rotary encoders inside are basically 2 pushbuttons. And because they are mehanical, you can also expect some debouncing. STM32F4 is a fast device and will handle this debouncing what you don’t want. For that you have to make a good filtering. I made a schematic. how to properly connect rotary encoder to STM32F4 to disable debouncing effect.

Properly connected rotary encoder to STM32F4 device

Properly connected rotary encoder to STM32F4 device



  • Operate with Rotary encoder

Continue reading

STM32F4 External interrupts tutorial

Posted on August 13, 2014 at 5:48 PM

Each STM32F4 device has 23 external interrupt or event sources. They are split into 2 sections. First interrupt section is for external pins (P0 to P15) on each port, and other section is for other events, like RTC interrupt, Ethernet interrupt, USB interrupt and so on.

GPIO as Interrupt

Interrupt lines

I will show now how to configure GPIO pin to be an interrupt and how to handle it in your code with CMSIS function.

In section one (GPIOs) we have 16 interrupt lines. They are line0 to line15 and they also represent pin number. This means, PA0 is connected to Line0 and PA13 is connected to Line13.

You have to know that PB0 is also connected to Line0 and PC0 also and so on. This is for all pins on board, All Px0 (where x is GPIO name) pins are connected to Line0 and let’s say all Px3 are connected to Line3 on the Interrupt channel.

All pins with same number are connected to line with same number. They are multiplexed to one line.

IMPORTANT: You can not use two pins on one line simultaneously:

  • PA0 and PB0 and PC0 and so on, are connected to Line0, so you can use only one pin at one time to handle interrupt from there.
  • PA0 and PA5 are connected to different lines, they can be used at the same time.

Each line can trigger an interrupt on rising, falling or rising_falling enge on signal. Continue reading

Library 25- AM2301 (DHT21) sensor for STM32F4xx

Posted on August 3, 2014 at 5:48 PM

AM2301 or DHT21 is a digital sensor for measure temperature and humidity. It has temperature resolusion up to .1 degree and accuracy to .5 degree celcius. Humidity has .1% resolution and 3% accuracy. This is quite good.



  • Read temperature from sensor
  • Read humidity from sensor


Continue reading