CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

sleep() with re-mappable EXT1 as wake up

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
marek816



Joined: 06 Aug 2015
Posts: 6

View user's profile Send private message

sleep() with re-mappable EXT1 as wake up
PostPosted: Wed Aug 19, 2015 1:17 pm     Reply with quote

Hi, my code will sleep if I disable INTR_GLOBAL but will not wake from following code.
uP is DSPIC33FJ16GS502
I've tried every combination I can think of. Data sheet says:
"The device will wake-up from Sleep mode on any of
these events:
Any interrupt source that is individually enabled
• Any form of device Reset
• A WDT time-out"

My interrupt code sets state machine:
Code:

#INT_EXT1
void  IntReedSwitch(void)
{
   printf("EXT1 fired\r\n");
   main_state = POWER_UP_DOWN;   //jump to power up/down
}

My power up or down case from my state machine:

case POWER_UP_DOWN:
            if (sleep_mode==0)
               {
               delay_ms(1000);
               sleep_mode=1;
               disable_interrupts(INTR_GLOBAL);
               disable_interrupts(INT_TIMER1);       
               enable_interrupts(INT_EXT1);
               clear_interrupt(INT_EXT1);
               printf("Going to sleep now!\r\n");
               sleep();             // make processor sleep
               delay_cycles(1); //Avoid problem with the next instruction being fetched
           //    printf("Waking from sleep now!\r\n");
               }
            else
               {
               clear_interrupt(INT_EXT1);
               sleep_mode=0;
               printf("Wakey wakey!\r\n");
              // enable_interrupts(INTR_GLOBAL);
               enable_interrupts(INT_TIMER1);
               }
            main_state = TIMEOUT;   
            break;

The idea is that the EXT1 input makes the uP wake up and also go to sleep (basically an on off push button function).

EXT1 is mapped using RPINR0 = 0x0900; which sets EXT1 to remappable pin 9.

Based on the statement from the datasheet, am I correct to presume I can use EXT1 to wake uP?

Thanks!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Aug 19, 2015 4:43 pm     Reply with quote

If you disable global interrupts, your code will never enter the #INT_EXT1
routine. Therefore, the main_state will never be set to POWER_UP_DOWN.

I think you need to post a complete (but still small) test program.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group