Home > Uncategorized > MSP430 Tutorial – Using Breakpoint in Emulator

MSP430 Tutorial – Using Breakpoint in Emulator

February 28th, 2011 Leave a comment Go to comments

MSP430 Tutorial – Using Breakpoint in Emulator

The methodology of debugging an Embedded system is slightly different from debugging normal C program executions. In normal programming language, you can display the content of a running program, by, for example, printing something on the screen. This is not possible in embedded systems.

In embedded environment we need a way, where we can execute the program step by step and see the results. The Emulator provides a way to execute program in steps. With emulator you can run the program till a certain statement and stop it there. You can also do step by step execution. This we can see till what point does the program work and where it fails.Take some time to learn it, even if things are not very obvious. You will be glad that you did learn this chapter.

To start experimenting and learning the break point, copy paste the following code in the IAR embedded system. Replace the msp430x14x.h and the IO pin corresponding to your hardware. In this particular example there is an LED connected to Port P5.0. If you have an LED connected to, for example, P2.3, then replace statement P5DIR |= (BIT0) with P2DIR |= (0x08) and similarly the P5OUT lines.


int main( void )

// Stop watchdog timer to prevent time out reset

P5DIR |= BIT0 ;
P5OUT|= BIT0 ; // P5.0 High
P5OUT&=~BIT0; // P5.0 Low
P5OUT|= BIT0 ; // P5.0 High
P5OUT&=~BIT0; // P5.0 Low

return 0;

If we run the program freely, it will make the Port Pin P5.0 high, then low and then again high and finally low. As we had observed earlier, our hardware is such that the LED will glow when P5.0 is low. Therefore, we observe the LED glowing when we run the program freely.

What we actually want to do it to look at the led glowing on and off using break point. To do this take the cursor to the statement
P5OUT&=~BIT0; // P5.0 Low

Now press F9 there. You will notice a Red circle or an arrow on the left hand side of the statement. What we have done is – added a break point at that statement.

P5OUT|= BIT0 ; // P5.0 High

If you press Control-D now, the program will load on your board and the screen will look as follows. The green highlight shows where the program is ready to execute from.

Hit F5 now. The program will execute till just before the staement marked with breakpoint. In this case it will stop at the statement

Now remove the break point on the line
P5OUT&=~BIT0; // P5.0 Low

by taking the cursor on that line and pressing the F9 key. The red circle or arrow on left will go. Now take the cursor to the line just below it and press F9. This will create the break point on the second high statement
P5OUT|= BIT0 ; // P5.0 High
statement. Press the F5 ke to execute the statement. This time the P5.0 goes low and LED glows.

Keep experimenting with the Break points for single step, free run. At a time you can add no more that 2 break points. If you have already placed two break points, you will have to remove one before you can add another.

Categories: Uncategorized Tags:
  1. No comments yet.