wake up from sleep mode using UART

Author
fbasma
Starting Member
  • Total Posts : 33
  • Reward points : 0
  • Joined: 2008/09/17 13:05:25
  • Location: 0
  • Status: offline
2008/10/09 12:41:09 (permalink)
0

wake up from sleep mode using UART

Hello,
 
according to my understanding while reading the  datasheet that i can't wake up the pic from sleep mode by using  UART interrupts. is there some sort of workaround for this problem or ofcourse maybe it can work but i'm missing something.
 
thanks in advance i would appreciate it a code would be posisble.
 
Thanks agian.
#1

7 Replies Related Threads

    sequoia
    Super Member
    • Total Posts : 222
    • Reward points : 0
    • Joined: 2008/08/04 17:17:09
    • Location: 0
    • Status: offline
    RE: wake up from sleep mode using UART 2008/10/09 13:46:13 (permalink)
    0
    Try idle or doze mode instead of sleep mode. You may also want to look at Peripheral Module Disable (PMD).
    #2
    houta69
    Super Member
    • Total Posts : 275
    • Reward points : 0
    • Joined: 2007/08/04 09:33:43
    • Location: Georgia, USA
    • Status: offline
    RE: wake up from sleep mode using UART 2008/10/09 17:16:20 (permalink)
    0
    Hi fbasma -
     
    Does the UxMODE register in the uart module for your PIC24 not have these bit settings?
     
    bit 7 WAKE: Wake-up on Start Bit Detect During Sleep Mode Enable bit
    1 = UARTx will continue to sample the UxRX pin; interrupt generated on falling edge, bit cleared in
    hardware on following rising edge

    0
    = No wake-up enabled
     
     
    Some addional verbage from section 10.3.1.6 of the reference manual:
     
    Any source of interrupt that is individually enabled, using its corresponding IE control bit in the
    IECx registers, can wake-up the processor from Sleep mode. When the device wakes from Sleep
    mode, one of two actions may occur:
    • If the assigned priority for the interrupt is less than or equal to the current CPU priority, the
    device will wake-up and continue code execution from the instruction following the PWRSAV
    instruction that initiated Sleep mode.
    • If the assigned priority level for the interrupt source is greater than the current CPU priority,
    the device will wake-up and the CPU exception process will begin. Code execution will
    continue from the first instruction of the ISR.

     

    -Adam
    #3
    fbasma
    Starting Member
    • Total Posts : 33
    • Reward points : 0
    • Joined: 2008/09/17 13:05:25
    • Location: 0
    • Status: offline
    RE: wake up from sleep mode using UART 2008/10/10 11:43:31 (permalink)
    0
    well thanks for the responses guys ,
     
    adam yea i've already tried that but for a certain reason it didn't work, anyway i'll go through my code again and see what i missed. i'll keep you posted.
     
    Thanks
    #4
    fbasma
    Starting Member
    • Total Posts : 33
    • Reward points : 0
    • Joined: 2008/09/17 13:05:25
    • Location: 0
    • Status: offline
    RE: wake up from sleep mode using UART 2008/10/13 19:18:39 (permalink)
    0
    hey again,
     
    i've been working on this, but i kind of faced a problem , hopefully u might help me with this. What is going on is that is that when i send characters the reciever uart interrupts it, but only for ONE TIME. i try to send more characters to see whether it gets interrupted but it doesn't.it ends up staying in sleep mode. i've tried to remove the sleep mode, the weird thing is that it interrupts it two times rather than one (ie. i send one character interrupt is activated, i send another character also the interrupt is activated, i try to send a third character, the interrupt is NOT activated). i've chopped the uart part from my code.  please when u havve some time can you check it out and see what i'm doing wrong. Thanks in advance.

    #include <p24fj128ga010.h>
    #define SYSCLK          8000000

    #define FCY             SYSCLK/2
    #define BAUDRATE2  2400
    #define CTS _RF3 // Clear To Send, input, HW handshake
    #define RTS _RF4
    #define BAUDRATEREG2 (FCY/16/BAUDRATE2)-1
    #define U_ENABLE 0x8080
    #define U_TX 0x0400
     
    _CONFIG2( IESO_OFF & FNOSC_PRI & FCKSM_CSDCMD & OSCIOFNC_ON & POSCMOD_XT)
    _CONFIG1( JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & ICS_PGx2 & FWDTEN_OFF & WINDIS_OFF);
    void UART2Init();
     void  putU2(int Ch);
    char getU2();
    void __attribute__((interrupt, no_auto_psv)) _U2RXInterrupt(void);
    //start of the main fuction
    main()
    {
        // initialization
        TRISA = 0xff80;
         UART2Init();
      char sss;
    // putsU2("fadi basma ya jagaldrgdgdfgdfgdfgdfgdfgdf2");
        while( 1)   // main loop
        {
       // sss=getU2();
       // putU2(sss);
         Sleep();
       
        } // main loop

    } // main
    //end of the main fuction

     //////////////////////////////////////////////////////////////////////////////////////
     //initiallization of the UART it is set to 2400 baud rate
    void UART2Init()
    {
        // Set directions of UART IOs
     _TRISF4 = 0; //output pin
     _TRISF3 = 1; //input pin
        RTS=1; //enable RF13
     U2BRG = BAUDRATEREG2; //intiate the baud rate
     U2MODE = U_ENABLE; // initialize the UART module uart enable
     U2STA = U_TX; // enable the Transmitter (transmit enable)
       // reset RX flag
      IFS1bits.U2RXIF = 0;
      //clear the reciever buffer
     
     IPC7bits.U2RXIP = 7;  // set IP as 7
     IEC1bits.U2RXIE = 1;    //enable interrupt

    }
    //////////////////////////////////////////////////////// fuction to send a character via the UART
    void  putU2(int Ch){
        // wait for empty buffer 
     //while (CTS);
    //while(IFS1bits.U2TXIF == 0);
    //while(_RIDLE ==1);
       while(U2STAbits.UTXBF == 1);
          U2TXREG = Ch;
         
    }
    ////////////////////////////////////////////////////////fuction to send characters via the UART
    void putsU2( char *s)
    {
    while( *s) // loop until *s == ‘\0’, end of string
    putU2( *s++); // send the character and point to the next one
    } // putsU2

    ////////////////////////////////////////////////////////fuction to get a character via the UART
    char getU2(){
    char Temp;
    //RTS = 0;
    while(IFS1bits.U2RXIF == 0);
    //if(U2STAbits.URXDA == 1){
        Temp = U2RXREG;
        IFS1bits.U2RXIF = 0;
       //U2STAbits.OERR =0;
        return Temp;
    //}
    //RTS = 1;
    }
     
    void __attribute__((interrupt, no_auto_psv)) _U2RXInterrupt(void)
    {
     IFS1bits.U2RXIF = 0;
      _RA0 = 1;
    putsU2("hellooo");
       // read for next interrupt
    }
     
    #5
    houta69
    Super Member
    • Total Posts : 275
    • Reward points : 0
    • Joined: 2007/08/04 09:33:43
    • Location: Georgia, USA
    • Status: offline
    RE: wake up from sleep mode using UART 2008/10/14 00:15:12 (permalink)
    0
    Greetings -
     
    Add U2MODEbits.WAKE = 1; to your RX interrupt routine. I believe this bit is cleared after the PIC is awakened. 
     
    If it were me, I'd also strip it down to the bare minimum to start with (looks like you've already started doing some of that). Just set a breakpoint in the RX ISR or toggle your LED on RA0 as a status indicator until you've gotten a handle on waking from the interrupt repeatedly. Once you have that, start adding the other code back in incrementally. 
     
    Hope this helps.

    -Adam
    #6
    fbasma
    Starting Member
    • Total Posts : 33
    • Reward points : 0
    • Joined: 2008/09/17 13:05:25
    • Location: 0
    • Status: offline
    RE: wake up from sleep mode using UART 2008/10/14 08:07:21 (permalink)
    0
    Thanks alot, this just did the trick , eventhough that doesn't make sense, coz i thought that when it comes back from sleep mode, all the initial intiallization will be back. Anyway thanks alot, i really appreciate it.
     
    Fadi
    #7
    houta69
    Super Member
    • Total Posts : 275
    • Reward points : 0
    • Joined: 2007/08/04 09:33:43
    • Location: Georgia, USA
    • Status: offline
    RE: wake up from sleep mode using UART 2008/10/14 10:25:41 (permalink)
    0
    Yeah, the manual eludes to that bit being cleared, but always as it pertains to something else... auto baud, break chars, etc... The only definitive indication of how this works that I found was figures 21-13 and 21-14. In going back over this, I realized that this bit should be set immediately before entering sleep() and after checking that the bus is idle.
     
    Also just as an FYI, if you're interested in conserving power via sleep, you'll also want to look at shutting down power to the individual peripherals via the Peripheral Module Disable (PMD) bits.
     
    Anyway, glad you got it going.

    -Adam
    #8
    Jump to:
    © 2018 APG vNext Commercial Version 4.5