|
|
View previous topic :: View next topic |
Author |
Message |
delphy_boy
Joined: 15 Sep 2008 Posts: 8
|
Wake from sleep on RDA interrupt |
Posted: Wed Sep 24, 2008 2:56 am |
|
|
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
|
|
Posted: Wed Sep 24, 2008 4:26 am |
|
|
You must make sure the pic goes to sleep in idle mode. |
|
|
delphy_boy
Joined: 15 Sep 2008 Posts: 8
|
|
Posted: Thu Sep 25, 2008 2:23 am |
|
|
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
|
|
Posted: Thu Sep 25, 2008 3:04 am |
|
|
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
|
|
Posted: Thu Sep 25, 2008 8:07 am |
|
|
Thanks Ttelmah, i will give this a try. |
|
|
|
|
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
|