Virtual Index

View Original

Where Do I Start?

How do you start programming a microcontroller? What do you need to interface with a microcontroller’s peripherals?

Each chip is different, and each vendor provides an abundant amount of support to get you started on their platform. With that said, you might need different IDEs (Integrated Development Environment), different header files, different programming chips, and sometimes, different languages (the most common are C and Python). But the last depends on the libraries, tools, and header files that support that chip’s development. So let’s dig into each one individually.

IDE you say?

An IDE, from its name, is a development environment that allows you to write your code, while also including tools to build, link, and debug your program. In the embedded systems world, these IDEs also contain tools to flash your code onto the chip (program the chip), as well as libraries that facilitate register access and module initialization. They also target different architectures. An IDE that can talk to Texas Instruments’ chips is different than one that can talk to MicroChip microcontrollers. Examples of that would be MPLab, Keil, Arduino IDE, and much more. The difference would be in their debugger and compiler capabilities. IDEs also provide the running environment for that language, and sometimes offer device simulators. You can read more about Integrated Development Environments on Wikipedia and Search Software Quality.

What is a header file?

A header file is included into a project’s source code in order to provide the macro, function, and variable declarations of a library, without exposing the actual definitions and code inside of the functions. This allows developers to write libraries and share them, providing a header file that contains all the method prototypes and possible data types used, as well as a binary file that contains compiled code (the functions’ implementations). This ensures that the code does not get used or manipulated maliciously, while also maintaining its integrity. Header files usually have the extension .h or .hpp. Python can also import those, as its base language is C. Java, however, cannot. It has special libraries and a certain process for building them.

C, I like Python

Each programming language has its strengths and weaknesses. C is very low-level, typically takes longer to write, and requires the developer to really know what they’re doing when it comes to memory management. Python, on the other hand, is easier to use, and relieves the developer from worrying too much about optimizations, as there are libraries and tools that take care of that. Java is sometimes used for embedded systems programming, but it is not that common. You can learn more about the differences on Educba or on ActiveState’s blog.

Where’s the bridge?

So we have selected the appropriate IDE for our chip, and written our code in the language of choice, using libraries of choice. How do we get that into our chip? In the case of stand-alone microcontrollers, a USB development tool is required, such as the EZ430-RF2500, or the MPLAB Pickit. These in-circuit debuggers will also allow you to flash the program onto your chip. Whereas development boards typically contain a debugging tool on the same board, such as Texas Instrument’s TM4C123G.

EZ430-RF2500

TM4C123G

So where do I start?

Depending on the project you’re building, your entire environment might differ. Every vendor has different requirements, and every product family might differ from another. Main points of comparison between chips would be: number of I/O pins, RAM size, register size (8-bit, 16-bit, 32-bit, etc..), clock frequencies, and possible additional modules such as serial ports, analog to digital conversion (ADC), and pulse-width modulation (PWM). It also depends on the possible additional electronics the project might include. A servo motor will require a PWM module to control it, whereas analog sensors will need an ADC module in order to interpret the detected values.