This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
I have a very basic code. Just blink the LED at the interrupt on any GPIO.
Issue is I am not able to debug the code. All works fine when it reached at the last curly braces of closing ISR it does not go back and on pressing 'step into' t gives this error.
MSP430: Can't Single Step Target Program: Could not single step device.
here is code
#include <msp430.h>
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR |= BIT0; // Set P1.0 to output direction
P1REN |= BIT4; // Enable P1.4 internal resistance
P1OUT |= BIT4; // Set P1.4 as pull-Up resistance
P1IES |= BIT4; // P1.4 Hi/Lo edge
P1IFG &= ~BIT4; // P1.4 IFG cleared
P1IE |= BIT4; // P1.4 interrupt enabled
__bis_SR_register(LPM4_bits + GIE); // Enter LPM4 w/interrupt
}
// Port 1 interrupt service routine
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
P1OUT ^= BIT0; // P1.0 = toggle
P1IFG &= ~BIT4; // P1.4 IFG cleared
}
Luqman said:__bis_SR_register_on_exit(LPM2_bits );
There is a little difference: ‘__biS_SR_register()’ Set the bits and ‘__biC_SR_register_on_exit()’ Clears the bits and ‘on_exit’ means not now but when call is completely finished.
When the LPM is canceled the clock will continue clocking and the program resumes from where it was stopped. Look carefully what will happen in your ‘main’ now.
Yes you are right.
But I know the difference but I am using "__biS_SR_register_on_exit(LPM2_bits );" not "__biC_SR_register_on_exit(LPM2_bits );"
want when it goes back in main it goes in different mode. Specfiically in my code, It will come from LPM4 and it should go after completing call in LPM2. Am I right ?
But in debug session control does not go back in the man finishes in the last curly brace,,
Whereas it goes in case of MSP430F2274 Case f I run same code on it.
I never said only 'main' should alter the power mode. Through this instruction "__biS_SR_register_on_exit(LPM2_bits );" I am changing the vlue of SR in stack. after executing ISR when t goes back it will load the altered value from the stack in the SR.
Let the someone else advise. btw Thanks you tried to help me :)
Luqman said:Through this instruction "__biS_SR_register_on_exit(LPM2_bits );" I am changing the vlue of SR in stack. after executing ISR when t goes back it will load the altered value from the stack in the SR.
Wrong! You need to (re-)read the User’s Manual.
Leo Bosch said:‘on_exit’ means not now but when call is completely finished
and Stack has been ‘popped’!
yes you are right. When ISR will completely finish and stack will popup and it will go back to the position from where it was before interrupt generating It will start working again with changed Power mode.
During ISR surely it will be in AM
Luqman said:want when it goes back in main it goes in different mode. Specfiically in my code, It will come from LPM4 and it should go after completing call in LPM2. Am I right ?
First of all there's a conflict between the two highlighted requirements. If the ISR ends and the stored SR register on the stack is set to LPM2, then execution will never get back to main - the CPU will be switched off. You can only resume execution of main by clearing the LPM bits to resume in active mode.
The second problem with the latest code listing is that __bis_SR_register_on_exit(LPM2_bits); will do nothing if the MCU was in LPM4 before the ISR triggered. The set bits in LPM4_bits include all the set bits in LPM2_bits (plus some extra ones). If you want to exit the ISR in LPM2 then you'd need to do
__bic_SR_register_on_exit(LPM4_bits); // Clear the LPM4 bits
__bis_SR_register_on_exit(LPM2_bits); // Set the LPM2 bits
or equivalently:
__bic_SR_register_on_exit(LPM4_bits & ~LPM2_bits); // Clear the bits that are set in LPM4_bits but not set in LPM2_bits
A common way to do this is to just clear the LPM4 bits in the ISR. Then the CPU will be active and execution continues in main, where the code can switch to LPM2 and set up any peripherals as required.
**Attention** This is a public forum