Programming STM32 USART using GCC tools. Part 2

In the previous part of the tutorial, we have covered simple USART routines that send data directly to USART peripheral. This is OK to use such an approach when a project isn’t time critical, and processing resources are far from limits. But most often we stuck with these limiting factors especially when RTOS is used or when we perform crucial real-time data processing. And having USART routines with while loop based wait isn’t a good idea – it steals processing power only to send a data. As you may guess – next step is to employ interrupts. As you can see, there are many sources to trigger interrupts, and each of them is used for different purpose. To use one or another interrupt first it has to be enabled in USART control register (USART_CR1, USART_CR2 or USART_CR3). Then NVIC USART_IRQn channel has to be enabled to map interrupt to its service routine. Because NVIC has only one vector for all USART interrupt triggers, service routine has to figure out which of interrupts has triggered an event. This is done by… Continue reading

Programming STM32 USART using GCC tools. Part 1

When we need some feedback from the microcontroller, usually we use USART. It allows to output messages, debug information to the terminal screen. Also, data can be sent to MCU same way. For this purpose, STM32 microcontrollers have more than one USART interface allowing to have multiple streams of data output and input. USART interface is designed to be very versatile, allowing to have lots of modes including LIN, IrDA, Smart card emulation, DMA based transmissions. But for now, let’s focus on standard USART communications we could send and receive messages from the terminal window. Continue reading

STM32 interrupts and programming with GCC

Probably one of the key features of any microcontroller is the interrupt system. ARM Cortex-M3 microcontrollers may have up to 256 interrupted sources. The first 15 interrupt sources are called system exceptions. These exceptions arise within Cortex core like reset, NMI, hard fault and error, debug, and SystTick timer interrupt. In the exception table, they start from address 0x00000004 and are numbered from 1 to 15. There is no 0 number exception (FYI – the very top of exception table address is used to store the starting point of stack pointer): Each exception vector holds the four-byte address of the service routine that is called when an exception occurs. Exception table usually is located in startup code like this: Continue reading

STM32F100RB based sunrise alarm clock will wake you up rain or shine

Alarm clocks usually – ring a pair of bells, play jarring noise, imitate the cock a doodle do of a rooster what else? We have seen alarm clocks with radios, and Phones with alarm clocks but most of them [if not all] uses sound to wake you up – not really the most gentle way of waking someone up. What do we recommend? The sunrise clock – instead of breaking your morning with a bunch of rings that also scares away a good start for your day this clock illuminates the surroundings giving a feel of morning sunrise in the comfort of your own room [yeap rain or shine]. Its build is quite straight forward – time was kept using a real time clock implemented using a STM32F100RB Arm Cortex M3 processor and a ceramic oscillator. Time is displayed using a pair of 8×8 LED matrices. The lamp [the source of light] is controlled using a dimmer circuit composed of an opto-diac and a triac – the opto – diac isolates the microcontroller from the high voltage AC source needed… Continue reading