trouble understanding RETI instruction

Thread Starter

jack_e

Joined Apr 9, 2010
1
Hi
I am having trouble understanding RETI instruction. Being a novice at MSP430 architecture, have begun exploring by writing simple snippets. I am trying to blink a LED using a timer. I want to control the dutycycle of the flashing.
My query is that after exiting the ISR on RETI, which instruction does the control flow go to. Have tried debugging via different methods but its still unclear. Here is my code. PLzz help.
;*****************************************************************************
.cdecls C,LIST,"msp430x11x1.h" ; Include device header file
;*****************************************************************************
;----------------------------------------------------------------------------
.text ; Progam Start
;-----------------------------------------------------------------------------
RESET mov.w #300h,SP ; Initialize stackpointer
StopWDT mov.w #WDTPW+WDTHOLD,&WDTCTL ; Stop WDT
SetupP1 bis.b #04h,&P2DIR ; P1.0 output
SetupC0 mov.w #CCIE,&CCTL0 ; CCR0 interrupt enabled
mov.w #0ffffh,&CCR0 ;
SetupTA mov.w #TASSEL_2+MC_2,&TACTL ; SMCLK, contmode
;
bis.w #CPUOFF+GIE,SR ; CPU off, interrupts enabled
nop
;-----------------------------------------------------------------------------
TA0_ISR; Toggle P1.0
;-----------------------------------------------------------------------------
xor.b #04h,&P2OUT ; Toggle P1.0
add.w #10,&CCR0 ; Add Offset to CCR0
reti
;-----------------------------------------------------------------------------
; Interrupt Vectors
;-----------------------------------------------------------------------------
.sect ".reset" ; MSP430 RESET Vector
.short RESET ;
.sect ".int09"
.short TA0_ISR
.end
 

Papabravo

Joined Feb 24, 2006
21,159
Interrupts happen between instructions. The contents of the program counter is saved on the stack when the processor goes to the interrupt routine. This saved address points to the instruction that would have been executed if there had been no interrupt.

Pretty cool eh?
 

DonQ

Joined May 6, 2009
321
Can't quite follow your opcodes since I do other processors, but it looks like you stop your processor with interrupts enabled. The next instruction is a nop, followed by your interrupt routine. So if I'm misunderstanding your code, ignore this.

Usually, when an interrupt happens, the processor is taken out of any stop/pause/sleep/low-power mode that it is in, the interrupt routine runs, then it returns to the instruction after the stop/pause/sleep/whatever instruction and starts running code again. Either that following code executes normally, or you put a jump/branch back to the previous instruction (sleep/pause/etc.) to put it back to sleep.

After the processor is stopped, your code seems to instruct a nop, then just drop off into wherever???

Depending on how your processor handles it, when your interrupt routine returns, it could be re-executint the interrupt routine, or, if the interrupt routine is automatically placed somewhere else, it would execute the uninitialized code after the nop, (or something else.)

Usually, the main function of embedded code is an endless loop, whether it includes a stop/pause/sleep/... instruction or not. This way, it never 'falls off the end' like your code seems to do.

[if your code was formatted, e.g. with columns to make it easier to read, try wrapping "code" tags around it to preserve the formatting next time, its the "#" tool on the advanced toolbar]
 
Top