All you need to know about AVR fuses

avr crystal oscillator

AVR lock bits and fuses are one of the topics that may cause some confusion. If you missed something or set one bit wrong, it may lead to failure – bricking the whole AVR chip. So it is important to understand once and do things right. Even though datasheets give enough information about AVR fuses, many times, we feel somewhat unsure before executing the write command. Let us go through the main features of AVR fuses and lock bits so next time we would feel safe and get the expected results.

Continue reading

Introducing to STM32 ADC programming. Part2

After we had a quick overview of the STM32 ADC peripheral, we can dig deeper into specifics. To understand simple things, let’s go with the simplest case – single conversion mode. In this mode, ADC does one conversion and then stops. After the ADC conversion result is stored into the 16-bit ADC_DR data register (remember that the conversion result is 12-bit), then the End of Conversion (EOC) flag is set. An interrupt is generated if the EOCIE flag is set. The same situation is if the injected channel is converted. The difference is that the result is stored in the corresponding ADC_DRJx register, the JEOC flag is set, an interrupt is generated if the JEOCIE flag is set. In our example, we will measure the internal temperature sensor value and send it using USART. A temperature sensor is internally connected to the ADC1_IN16 channel. The algorithm will start a single conversion and wait for the conversion complete flag EOC. We will then read the ADC value from the ADC_DR register, which will later be used to calculate Celsius’s temperature value…

Continue reading

Introducing to STM32 ADC programming. Part1

STM32 ADC is a pretty complex peripheral. It is designed to be flexible enough to accomplish complex tasks. We will dedicate a few posts where we will try to cover the main features and give working examples of code. The block schematic may look scary the first time, but it can be split into several pieces that are responsible for different functions if you look closer. Will will go through them step by step to make it look brighter.

Continue reading

USB oscilloscope using STM32

This is a basic oscilloscope on STM32F103C8T6 microcontroller. The circuit board is kept very simple. No fancy analog stuff – just diode protection circuit and resistor divider. It is a two-channel 8-bit scope with 300kSps each. It accepts voltage levels from 0 to 6.6V. Data stream via USB is live and goes to PC GUI called mini scope v4.Here you have some basic controls, including sampling rate, triggering source and level, buffer size, and other handy stuff. Building a custom USB oscilloscope might seem like a fun project, it can be a lot of work and may not be worth the effort for most people. Here are a few reasons why: All that being said, if you’re really passionate about electronics and want to learn more about how USB oscilloscopes work, building your custom USB oscilloscope can be a gratifying project. Just be prepared for a lot of hard work and possibly some frustration along the way!

Continue reading

Programming STM32 USART using GCC tools. Part 2

In the last 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, mainly when RTOS is used or when we perform necessary real-time data processing. And having USART routines with while the 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 a 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 and 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