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

Wake from sleep on RDA interrupt

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



Joined: 15 Sep 2008
Posts: 8

View user's profile Send private message

Wake from sleep on RDA interrupt
PostPosted: Wed Sep 24, 2008 2:56 am     Reply with quote

Hi,

I am using complier V4.008 and a PIC18F6722.

I am trying to get the PIC to wake from sleep on reception of a character in the UART buffer.

I have global and the rda interrupts enabled but the PIC does not wake from sleep when I send characters to the comm port. I also had the same problem using an 18F8722.

Does anyone have any suggestions??
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Wed Sep 24, 2008 4:26 am     Reply with quote

You must make sure the pic goes to sleep in idle mode.
delphy_boy



Joined: 15 Sep 2008
Posts: 8

View user's profile Send private message

PostPosted: Thu Sep 25, 2008 2:23 am     Reply with quote

How do you mean go to sleep in idle mode? Is that different from the built-in function "sleep()" that is available in the compiler?
Ttelmah
Guest







PostPosted: Thu Sep 25, 2008 3:04 am     Reply with quote

The key is that to wake up from RDA, requires the serial component to not go fully to sleep. There are a (huge) number of different 'sleep' modes (on some chips), resulting in different parts of the chip left awake. 'Sleep', triggers the currently selected mode, which defaults to 'fully asleep', including the peripheral clocks disabled. You need to select the right mode, _before_ calling the 'sleep' function.

There are several things you need to do:
First, INT_RDA, must be enabled. Also _cleared_. Remember that for RDA, you need to clear the read buffer, before you can clear the interrupt. Any other interrupts, that you use, but don't want to wake you up, should be disabled.
INT_GLOBAL, should normally be disabled. When you wake from sleep on the RDA interrupt, the received character will be garbage, so there is no point in actually calling a handler for this.
The _oscillator_, needs to have the IDLEN bit set. This is done with the 'setup_oscillator' selection. OSC_IDLE_MODE sets this bit. Normally you would also want OSC_INTRC. to run off the internal oscillator (the alternative is the timer1 oscillator).
Only then do you call the 'sleep' function.
After the sleep instruction, have a NOP instruction (delay_cycles(1)). The instruction after the sleep is 'prefetched', and it is safer to do this.
Then have a setup_oscillator instruction, to switch to the full power oscillator.
Then clear the receive buffer, and the interrupt.
Finally start your code again.

To wake the chip, send a character, then _pause_ for a little while. Then send the 'real' data. Alternatively, send a sequence of dummy characters, followed by the 'real' data, and have your code look for a marker for the start of the real data, once it wakes.

Best Wishes
delphy_boy



Joined: 15 Sep 2008
Posts: 8

View user's profile Send private message

PostPosted: Thu Sep 25, 2008 8:07 am     Reply with quote

Thanks Ttelmah, i will give this a try.
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