1

How can I enable and disable (clear and set GIE SR bit) in C using the mspgcc?

tylerjw
  • 802
  • 4
  • 14
  • 28
  • Possible duplicate: http://stackoverflow.com/q/47981/694733 – user694733 Oct 10 '13 at 12:01
  • @user694733: Not a duplicate. The GIE SR bit in the MSP430 is generally not accessed using simple bitwise operator because there is no symbol defined in C that represents the status register. – tinman Oct 10 '13 at 12:18
  • This is not a duplicate as the status register (SR) is a processor register, not a normal memory mapped register. I found the solution, see below. – tylerjw Oct 10 '13 at 12:28

3 Answers3

3
/*interrupt.c
ganeshredcobra@gmail.com
GPL
*/
#include <msp430g2553.h>
#define LED1 BIT0
#define LED2 BIT6
#define BUTTON BIT3
volatile unsigned int i;//to prevent optimization
void main(void)
{
WDTCTL=WDTPW+WDTHOLD;
P1DIR |= (LED1+LED2);//
P1OUT &= ~(LED1+LED2);
P1IE |= BUTTON;
P1IFG &= ~BUTTON;

//__enable_interrupt();//enable all interrupts
_BIS_SR(LPM4_bits+GIE);
for(;;)
{}
}

//port1 interrupt service routine
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
P1OUT ^= (LED1+LED2);
P1IFG &= ~BUTTON;
P1IES ^= BUTTON;
}

This is an example of interrupt http://importgeek.wordpress.com/tag/msp430-launchpad/

ganeshredcobra
  • 1,881
  • 3
  • 28
  • 44
1

You can either use the __eint() / __dint() intrinsics:

#include <intrinsics.h>
...
    __eint();
    /* Interrupts enabled */
    __dint();
    /* Interrupts disabled */

Or you can use the __bis_status_register() / __bic_status_register() intrinsics:

#include <msp430.h>
#include <intrinsics.h>
...
    __bis_status_register(GIE);
    /* Interrupts enabled */
    __bic_status_register(GIE);
    /* Interrupts disabled */

Or one of the many other compatibility definitions in intrinsics.h. Note that there are also some special versions such as __bis_status_register_on_exit() / __bic_status_register_on_exit() which will change the state of the flag on exit from an ISR.

tinman
  • 6,348
  • 1
  • 30
  • 43
  • I'm using the `mspgcc` and I get `fatal error: intrinsics.h: No such file or directory`, also the `__eint()` and `__dint()` produce errors. – tylerjw Oct 10 '13 at 12:26
  • @tylerjw: What version of mspgcc are you using? You should probably add that information to the question as it would change the validity of the answers. – tinman Oct 10 '13 at 12:35
1

Through experimentation I found it can be enabled with _BIS_SR(GIE); and disabled with _BIC_SR(GIE); without including anything but the standard msp430g2553.h file.

tylerjw
  • 802
  • 4
  • 14
  • 28