Skip to main content

Introduction to Embedded Programming!






In the last sections, we discussed the communication protocols in general and then shifted to discussing the Spi in detail. The last discussions were based on the hardware part of the MCU and Spi peripheral but from this section, we will shift our focus to the software implementation.

We have already discussed that any digital circuitry requires binary instructions i.e, we need to provide the machine language(binary) code. Now we can either write our program in assembly language which is more user-friendly than the machine code or we can write in other high-level languages such as C.The assembly code is a low-level code i.e it is much more dependent on the architecture of the processor. Hence the use of a higher-level language such as C is much more efficient as it is portable across all the architectures. There are some cases in which the use of assembly is preferred such as while writing the Reset handlers or accessing the CPU registers, but other than these cases, C is used.

When C is used in programming the embedded systems, it is often referred to as embedded C. It is basically an extension of the C programming language but there are a few differences between conventional C and embedded C such as the I/O functionalities and the resource(memory, processing power) constraints which are there in embedded systems but other than those the languages are quite similar. Moreover, in embedded C we directly program the underlying peripheral configuration registers. Each peripheral is provided with individual registers in the memory and these are used to set the configuration of the peripheral.

So, in embedded programming, we basically program these registers to perform the required operation. All the information about these registers is located in the MCU datasheet provided by the manufacturer and so it is very important for any embedded systems engineer to know how to read the datasheet. These datasheets are the heart and soul of creating firmware/drivers for any MCU and hence the first step for learning embedded systems programming is knowing how to understand a datasheet. The image attached below is a part of the Atmega 32 datasheet and provides the information about various registers for controlling GPIO.





The address of the above register can be found in the datasheet as well. Using it, we can write the data at the specified address with the help of pointers and hence can manipulate the working of GPIO. In practice, there are a number of registers for configuring each peripheral and hence we need a way to create a mapping of software over hardware. This is achieved through the use of structures which can create the exact same pattern of registers in software by the use of variables whose sizes are same as that of the corresponding registers. Then we use register pointers which are then assigned to the starting address of the peripheral and hence we can now control each and every setting of a peripheral.

There are various other techniques which are used to manipulate the hardware and these can be learned by diving deeper into the C Programming language.  






Comments

Popular posts from this blog

Let's Build a Music Player!

Digital Music Player's are one of the many sensational devices that were developed in the 20th century. They have been around for a while now and have become a part of our life. In the last few years, they have been integrated within Smart Phones and hence, have reached the masses. Now, Let us try to dive into knowing how these devices work and I guarantee that we all would be fascinated by the kind of engineering which goes into making these magic boxes. There are various topics which must be covered in order to build our own music player and so there will be several blogs to build a SOUND foundation. Now let us make a list of the required components and then we will walk through each of them in the upcoming blogs. There are 3 basic parts which are required to build a device which can output Audio:- Storage Medium. Micro-controller. Audio Output device. We will store the required music file onto a storage medium as the onboard memory on a microcontroller is low...

SD-CARD

This Post marks the beginning of our quest to develop a simple Music player. SD stands for Secure digital and these small devices have been around for a while now. They contain flash memory and a memory controller which is given instruction by the main MCU. So our main objective here is to understand how sd cards work and how to interface them with a microcontroller. As to understand the working of SD card we need to dive into the world of transistors and bits! The Sd card contains solid-state memory also known as the flash memory which is a type of EEPROM i.e  Electronically Erasable Programmable Read Only Memory .  Flash memory stores information in an array of memory cells made from  floating-gate transistors . These transistors are used in different topologies as to store each bit. We will not program each bit individually as it will be time-consuming as well as an inefficient way to store the data. As to move to a higher level of abstraction, we need a way to ...

Automated Outdoor Lighting

This Project enables a person to make any Outdoor Lighting Automated i.e to switch On/Off according to the sunlight outside. If it is dark outside then the light will turn On and if it is daytime then it will automatically switch Off. This can be very useful for all Outdoor Lighting of various commercial buildings as well as for residential buildings. This can also be implemented in Vehicles which will automatically turn their lights On.  Our aim can be achieved by designing a proper transistor circuit and using a relay with it to control the high voltage network. T he Requirements Are: 1:- Bipolar Transistor(Bc 547) 2:-5/6v Spdt Relay 3:-Resistors(Around 4.5k And 3k Ohm) 4:-Light Dependent Resistor 5:-5v Power Supply 6:-Pcb For Soldering Things Together 7:-Multimeter          CIRCUIT AND EXPLANATION The project involves the use of a transistor as a switch to make the outdoor light on/off. As we know that transistor can be used in three diffe...