STM32 Delay Function.

STM32 Delay Function.
STM32

The first thing I noticed after switching from AVR to STM32 was the absence of the familiar delay functions delay_us() and delay_ms(). Well, if they're missing, they're missing, I thought at the time, and whenever I needed a delay, I did it like this...

SPI STM32.

SPI STM32.
STM32

We won't go over how the protocol works, since it was covered here; let's go straight to the capabilities of the STM32 SPI module: full-duplex synchronous transfer using 3 lines; simplex synchronous transfer using two lines, with the option of a bidirectional data line; 8- or 16-bit frame format; operation in Master or Slave mode; in Master mode 8...

STM32 Interrupts.

STM32 Interrupts.
STM32

On STM32, interrupts are managed by the NVIC (Nested Vectored Interrupt Controller). Let's look at its capabilities: handling up to 81 interrupts, depending on the MCU model; a programmable priority level from 0 to 15 for each interrupt, with level 0 being the highest priority; dynamic priority changes; dividing interrupts into groups, and within groups into...

STM32 Code Execution Time.

STM32 Code Execution Time.
STM32

It all started when I needed to at least roughly estimate the execution time of a piece of code. It turned out that microcontrollers with a Cortex-M3 core have a special module for this called the Data Watchpoint and Trace Unit, DWT for short. To configure DWT to measure code execution time, we need to set 2 bits. The TRCENA bit in the DEMCR register, setting...

STM32 PWM.

STM32 PWM.
STM32

PWM on STM32 is generated using timers; the documentation says a lot about them, but PWM turned out to be quite easy to configure. We'll generate PWM using channel 4 of timer 1. First, we need to find which pin is responsible for channel 4 of timer 1; to do this, open the Technical DataSheet for your MCU (mine is the STM32F103VET6) and find which pin has...

STM32: Storing ADC Data with DMA.

STM32: Storing ADC Data with DMA.
STM32

DMA (Direct Memory Access) lets you transfer data without involving the core. That is, if you use DMA, then when an ADC conversion completes, we don't need to fetch the conversion result and store it in memory; DMA will do it for us. To do this, when configuring DMA it's enough to specify the address to take data from and where to store it, plus a few more simple settings...

Digital Programmable Oscillator: Connecting the LTC6903 to STM32.

Digital Programmable Oscillator: Connecting the LTC6903 to STM32.
STM32

In one of my designs I needed to vary a clock frequency over a wide range, and as the title suggests, I chose the LTC6903. The LTC6903 and LTC6904 are digital programmable oscillators with a frequency range from 1KHz to 68MHz; the only difference is that the LTC6903 is controlled via SPI and the LTC6904 via I2C. They are quite easy to connect and only require bypass capacitors on the supply...

How to Connect an Encoder to STM32.

How to Connect an Encoder to STM32.
STM32

One of my previous articles about encoders described how they work and ways to process the data coming from them. The methods described can be implemented on simple microcontrollers like the Atmega; more advanced ones, like STM32, have a dedicated encoder interface that processes the data from the encoder by itself and, based on this data, increments or decrements the value...

How to Flash the miniSTM32F103V.

How to Flash the miniSTM32F103V.
STM32

The simplest and most accessible way to flash an STM32 is with the bootloader; in this article we'll look at how to do it using the miniSTM32F103V board as an example. First, let's figure out what a bootloader is. A bootloader is simply a program that is stored in a certain section of memory and can rewrite the microcontroller's flash. It is programmed during chip manufacturing...

STM32 ADC.

STM32 ADC.
STM32

Let's look at the features of the ADC in STM32. 12-bit resolution; reference voltage from 2.4 to 3.6 volts; sampling rate up to 1MSPS; 18 channels (16 external and 2 internal: reference voltage and temperature sensor); interrupt at the end of regular and injected conversions; interrupt from the window comparator (Analog watchdog); DMA transfer for regular...