Tag Archives: embedded

Compile-Time Polymorphism

Let’s say we have a peripheral, like an accelerometer, connected via an SPI bus. Then let’s say we have to different embedded projects that make use of this same chip, implemented on two different microcontrollers. Wouldn’t it be nice to be able to write the accelerometer communication code once, keep a low runtime overhead that […]

Posted in FussyLogic | Also tagged , , , | Leave a comment

STM32F0 Discovery Development III

The ARM startup code we discussed last time was enough to get a program to compile, link and run, but it wasn’t enough to support a real C program. There is one primary feature that we’re missing, pre-initialised variables need their initial values copying from flash to RAM. The discovery-basic-template is full of useful information, […]

Posted in FussyLogic | Also tagged , , , | Leave a comment

Getting Started With The STM32F0 Discovery

Introduction I’ve added another nice cheap dev board to my collection, the STM32F0 Discovery, which I got from RS in the UK for £. It’s an SGS Thompson (ST) kit, based around their STMF051R8T6 device, which is in turn based on an Arm Cortex M0. I like this sort of dev board so much because […]

Posted in FussyLogic | Also tagged , , , | Leave a comment

Blowing a Fuse

I like to use avrdude for programming my AVR’s. It’s got support for pretty much every possible programming method supported by the AVR CPUs and has a good command line interface. A command line interface is very important when you use Makefiles to act as your IDE. Here, for example, is a little bit of […]

Posted in FussyLogic | Also tagged , | Leave a comment

Volatile Delays

You want to write a simple delay loop on your embedded microcontroller. Let’s say you’re waiting for the crystal oscillator to stabilise before you use it. static void delay( int loops ) { while(loops–) ; } You’re then very surprised to find that this takes a total time of 0ms when you call it. You […]

Posted in FussyLogic | Also tagged , , | Leave a comment

CPU, Interrupted — Timers II

When last we spoke on this subject I had left you with a time-accurate but impractical timer interrupt handler. #define F_CPU 16000000 uint8_t Timer_ms = 0; static void initTIMER1( void ) { // CTC mode (WGM1[3:0] = 0x04) TCCR1A = 0; TCCR1B = _BV(WGM12); // CLK/8 prescaler (see datasheet for table) TCCR1B |= _BV(CS11); // […]

Posted in FussyLogic | Also tagged , , , , , | Leave a comment

CPU, Interrupted — Timers

Yesterday I mentioned that interrupts on an embedded microcontroller can cause you trouble. That’s not strictly true – it’s not the interrupt that causes trouble it’s the way you handle them. An awful lot of programmers don’t handle them correctly and they end up in a sticky mess. Before I can talk about interrupts though, […]

Posted in FussyLogic | Also tagged , , , , | Leave a comment

AVR UART Transmit and stdio

The setup for a UART on AVR is such common code that I wonder if possibly it’s just assumed to be understood and explained. This is a quick article to fill in the gaps. First let’s talk initialisation. This is often the most important part of using any hardware peripheral on an embedded processor. In […]

Posted in FussyLogic | Also tagged , , | Leave a comment