Introduction to MSP430 Interrupts

In this tutorial, we will see a practical way of coding interrupts. Our task for today will be to learn interrupts for GPIO and Timers. In the initial part, we will first look at coding interrupts for the GPIO pins, and in the other half, we will modify this code to add interrupts for timers. By the end of the tutorial, you will have a code that will blink a led using a timer interrupt. However, the blinking frequency will vary if you push a button. In the last tutorial on timers, we saw that we were continuously monitoring the timer flag to check when the timer has overflown. This process is called polling. The only problem with this method is it keeps the processor busy. What if we had another way by which the timer would itself tell the CPU that the timer had overflown? This is where interrupts come into the picture. For example, imagine a scenario where you would always go up to the door to see someone s there or not. This process can be called…

Continue reading

Use fixed integer types to enhance portability

If you have programmed anything with C, you should be familiar with common data types like char, unsigned char, int, unsigned int, long int, long long int, etc. It is tough to tell by the looks of the type how many bytes this variable takes on memory and how it looks in a different system. For instance, in 8-bit AVR-GCC compiler, int is a 16-bit type, while in ARM-GCC, int is 32-bit. So int size is dependent on platform, compiler, and runtime libraries. And switching between systems may trick you if you are not careful enough. You can always check the size of the variable by using sizeof() function. What to do if you need your code to be portable between different systems. Some great libraries could work on any system, including 8-bit, 16-bit, 32-bit, or 64-bit. To avoid this annoying problem, the ISO C99 standard introduced portable data types that are defined in stdint.h header file. If you open this header file of your default compiler tool-set you will find how things are organized. First of all, it checks…

Continue reading

Timers of MSP430

In the last tutorial, we had a look at configuring clocks or internal clocks of the MSP430. Since you are now at a stage where you can set clocks on your own, we can use them to access various functions of the MSP430. All of the major features, such as the ADC, timers, e.t.c, rely upon the clock or the clock speed at which the microcontroller functions. Timers of any microcontroller are special registers that increment or decrement their value automatically. They are an integral part of the microcontroller and are used in almost every project, from basic to complicated ones. A useful feature of the timers of the MSP430 you can use them to achieve a real-time clock, i.e., a delay of precisely 1 sec, provided you use the 32.768kHz crystal supplied to you with the Launchpad. Let’s move onto the technical specification of the timer. If you have referred to the user guide of the msp430 you must have founded out there are two types of timer mainly ‘TIMERA’ and ‘TIMERB.’ An important point to note here is…

Continue reading

Resetting Arduino via serial line

Usually, Arduino boards are reset by using additional DTR line of the serial interface. This becomes a problem when USB-UART adapter doesn’t support DDR line. And you probably read many cases where one or another particular cable won’t work for programming but can be used for simple serial data transfers. Ralph thought that there should be another solution that would allow using any serial cable for programming. He thought that TXD and RXD lines are always available since they are used for data receive and transmission. So why not to use one of those to reset the microcontroller. With three additional discrete, he created a simple circuit that would stand between RXD data line and RST pin. This is simply an RC circuit that would discharge cap during some time. So when data line works in regular operation – RSTin isn’t affected due to slow cap discharge. But when the RST signal is held down for a longer time – the cap is discharged, and then the RST signal is sent. Since he’s done modifications, he also had to make…

Continue reading

Half duplex UART from single AVR pin

Smaller microcontrollers like Attiny84 microcontrollers don’t have UART interfaces, and you may not need them in many cases. But if you want a USART option, you will need to use software USART library or write your own routines. You can find many great software USART libraries for that purpose. As a rule, you will have to use two pins to establish communication. But if you are tight on I/Os, you can cheat a little and make it work from a single pin. Ralph has been experimenting with the simple but intelligent circuit, which allows performing half duplex UART communications with other systems. The whole trick lies in a small schematic made of diode, transistor and resistor. Diode is only for making one way TX signal path from MCU to other device. The resistor is only for limiting base current. All is left a transistor which works as a key. We need to remember that when the serial line is inactive, it stays in the high state. So when microcontroller transmits data, TX on the right keeps transistor open. Thus if…

Continue reading

Configuring the DCO of MSP430

Clocks are an essential part of any microcontroller. These are the first thing one should know while beginning to use any feature of the controller, whether it’s a timer, interrupts, or ADC. All of them rely on the clock setting of the microcontroller and works accordingly. The MSP430 is not so different. However, it features very easy-to-configure clock settings, which might look a bit tough initially, but once you get used to it, you will find it amazing to use. Unlike AVR, where you use super complicated fuse bits to change your clock source and the frequency, this is not the case with the MSP430. The clocks are easily configurable, and most important, if you are using internal clock, you can change its frequency at any time during the program, which is not possible in the AVR series. Before beginning, let me describe our task. We will use a blink-led program, which is already included with CCS and without changing the delay loop, and with the help of the internal oscillator, we will observe a change in blinking time of…

Continue reading