Programming Embedded Systems

Michael Barr, Anthony Massa

Mentioned 3

Authored by two of the leading authorities in the field, this guide offers readers the knowledge and skills needed to achieve proficiency with embedded software.

More on

Mentioned in questions and answers.

My company is transitioning from assembly coded microcontrollers to C. We are considering Microchip, Atmel, Renasas, et. al. for future projects using C code. Are there good training resources to bring our engineers up to speed with C? Seminars, instructors, classes, etc. The experience level of the engineers varies from no training to some knowledge.

Welcome to the 80's. :) Start with the either classic K&R C book or my favorite C: a Reference Manual by Harbinson & Steel if you can find one. I work with PICs and there are several useful books about PIC programming. I was already familiar with C from using PCs I didn't find them useful in that regard.

C allows you to be close to assembly and most compilers to include it inline, so it's as close to assembler as any high level language. You should happy and at home pretty quickly, I think.

If you are interested in jumping forward a few decades ;>) you might want to consider a Microchip C complier. I'm going to be looking into this soon and there is a good book on Practical Statecharts in C/C++.

The good news is that if your engineers have a background in assembly, some of the 'C' langugage concepts, such as pointers and arrays, will not be difficult to grasp (and hopefully master.)

Regarding your specific question about embedded C training, Netrino has a bunch of courses on embedded training, including writing embedded code in C and C++.

Also, the Embedded Systems Conferences (just had one in Boston a couple weeks ago, next one is in Silicon Valley next spring I think) are always full of courses on embedded development & different languages. But you probably don't have the luxury of waiting 6 months.

If your staff are more of the "book learner" types, these books might be of interest:

That should give you enough to chew on for a little while.

For 16-bit Microchip pics, there is

IIRC it was decent, but they focus pretty heavily on doing one thing per chip. Our apps multiplex a lot of I/O, and for that the examples/casestudies in the book (that assumed exclusive use) were hard to bring to practice.

When I started with this architecture, having a readily made example board (from Microchip, $50-$100 range) really helped, specially if you target roughly the same variant as the example board.

This because it offered an easy check if a problem was hardware or software related by running it on the example board.

I am reading a primer text on embedded C programming (it is: Barr & Massa, 2007). For companion hardware board to run examples, they recommend Arcom VIPER-Lite. But I do already have Beaglebone Black (BBB) board and I don't want to buy a new board.

The two boards have same architecture, namely, ARM but BBB uses TI AM3358BZCZ100 processor, clocked at 1GHz, whereas VIPER-Lite uses Intel's PXA255 processor, clocked at 200MHz. The BBB board has more memory and basically more of everything.

My question is, can I follow and execute embedded C code examples given in this book on my BBB board? Does embedded C code depend on processors or architecture or something else? I understand that very specific examples addressing particular peripherals/drivers may not be portable from one platform to next but is entire embedded code like this? I am hope I am making sense.

May be my title wording can be misleading, but this is what I'm trying to accomplish.

I have a plan to develop a multipurpose integrated machine (something like fully automatic washing machine... But does more than that)... It is going to have many moving and non moving parts which needs to be controlled by a chip / processor on the panel...

I know C# and could write the modules that takes care of the user input and controls the machine by issuing commands to it. But what should do on the machine side...

Say, suppose I want the machine to rotate Drum B for 30 Seconds... My C# code will be

Machine.Rotate(drumB, Direction.Clockwise, 30);

But How am I going to access the motor of the machine so that It can spin for 30 seconds...

Should I know "Embedded Systems" to do it or is there something else I need to learn.

Could you please help me out... If possible with the books / online material to start learning the same.


First, IMHO you must learn embedded systems for this kind of project, despite the tecnologies you may use. Thinking and programming in embedded systems is a bit different than thinking and programming for desktop computers.

The most important difference is the hardware resources (example, most of the times you will have limited disk and memory capacity, and the same for the processor). Other important difference is the software fault tolerance (it can be a little anoying if the driver gets stuck inside the car on the washing machine because the software chrashed...). There are other important points that you must look for (example, software-hardware co-design), but I think this 2 are really important ones and I think you must pay attention to them from the beggining of your project.

As an introduction to embedded systems, I would recommend you "Programming Embedded Systems: With C and GNU Development Tools" form Michael Barr (more software oriented) and "Designing Embedded Hardware" by John Catsoulis (hardware oriented). Of course, you can always check Wikipedia article as a starting point.

If you really want to use .NET, you have two options:

  • as has already been said, look for .NET Micro Framework. Take care that the .NET MF only works with a limited number of hardware (check this page);
  • other option is to buy an industrial panel (example of one here) or industrial computer, install Windows Embedded and program under standard .NET Framework. Beside this last advantage, the hardware is industrial, which means it is, for example, shock and water resistant, and has a number of inputs (USB, CAN, Ethernet, Serial, ...) that you can use with all the advantages of Windows programming.

Another option is to try other hardwares, but in that case you must use the libraries/APIs/frameworks the manufacturer provides for that hardware.

In order to you access your the hardware, you must use the available hardware inputs/outputs. For example, if you want to comunicate with a, let's say, stepper motor, you must check how you can comunicate with it. If the only way is by sending a PWM signal, you must find a way to do so. Two hipothesis:

  • if you are using a development kit with .NET MF, you must check if it can generate a PWM signal, otherwise you will probably need to write a device driver to do so;
  • if you are using a host computer as human interface connected to an external hardware (it can be connected through USB, Serial, ...), the hardware must be capable to receive messages from the host and generate the PWM signal (almost certainly you will a microcontroller on your hardware for this behaviours).

For both hipothesis, you can create a high-level framework with methods like the you one you presented that abstracts all the communication with the hardware. Also, @Daniel suggestion of callbacks is a really good one because it makes your framework more flexible (as an example, you can have different behaviours defined on the callback for each of the motors after it stops or before it starts).

As a final point, you must evaluate what do you really need for your project. If your project must be cheap, probably you will use a small hardware, but in that case you may, or may not, be able to use the .NET Micro Framework; if you can spend a little bit more money, maybe you can use a little more expensive hardware running Windows and in that case you can use even the standard .NET Framework.

Sorry for the big answer, but I hope it helps you on your choice(s)!