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.

Power mode 2 to power mode 0 Interrupt problem..

Hello Sir,

I want to send some data through UART when i press S1 button on evalution board.

On power on the device, it should run in PM2, When i press s1 button device must wake up from PM2 to PM0 and then should send some data.

After sending data it must go back to PM2 again.

i have written below code.. it is working fine when i debug & run it through IAR embedded workbench IDE..

but after dumping it on chip, switch off that board and switching on, then on pressing s1 button the device is sending data but again it is not sending on pressing S1 button..

//=====================================

#include "hal_types.h"
#include "hal_defs.h"
#include "hal_cc8051.h"
#include "ioCCxx10_bitdef.h"

#if       (chip == 2510)
#include  <ioCC2510.h>
#endif

//static uint32 __xdata Cnt = 0   ;
uint8 i = 0  ;
uint16 j=0;
//==============================================================================

#pragma vector = 0x6B
__interrupt void PM0_ISR(void)
{
    P0IFG  &= ~BIT1;
    P0IF = 0;
    // Clear the [SLEEP.MODE] bits.
    SLEEP &= ~SLEEP_MODE;
    // Set SRF04EB LED1 to indicate Power Mode 2
    P1_0 = 0;
   
}
//==============================================================================
void uart0send()
{
    U0BAUD=59;                  // For 9600 baud rate
    U0GCR=(U0GCR & ~0x1F)|8;
    U0CSR|=0x80;                //Asynch
    U0UCR=(U0UCR&~83)|0x02;
    U0GCR&=~0x20;
   
    PERCFG &= ~0x01;
    P0SEL|=0x3c;
    P1SEL&=~0x3c;
    CLKCON&=0x80;
    while(CLKCON & 0x40);
    SLEEP|=0x04;
    UTX0IF=0;
   
    for (i=65; i<=81; i++)
    {
      if(i>64&&i<91)
      {
        U0DBUF = i;
      }
      while(!UTX0IF);
        UTX0IF=0;
    }
}
//==============================================================================
void main(void)
{
    P1SEL &= ~0x06;
    P1_0 = 1;
    P1_3 = 1;
    P1DIR |= 0x09;
   
    P0IFG &= ~0x0D;
    PICTL = (0x8C & ~0x01) | 0x08;
   
    SLEEP &= ~0x04;
    while(!(SLEEP  & 0x20));                    // Wait until HF RCOSC is stable
   
    CLKCON = (CLKCON & ~(0x07 | 0x40)) | (0x00);
    while (CLKCON & 0x40);
  
    SLEEP |=  0x06;
    P0IE = 1;
    EA = 1;
    if(SLEEP& 0x03)
    {
        PCON |= 0x01;
        uart0send();
        P1_0 = 0;
        
    }
}
//============================================================================== 

 

Also i need to wake up device from PM3 to PM0 & then send data through uart, when ever i select s1 button..!

later after sending data it must go back to pm3 mode.. again on pressing s1 button device must wake & data must send.. if flow should happen.. 

i have written below code.. getting same problem as above pm2-pm0 shifting..

#include "hal_types.h"
#include "hal_defs.h"
#include "hal_cc8051.h"
#include "ioCCxx10_bitdef.h"
#if       (chip == 2431)
#include  "ioCC2431.h"
#endif
 static char __xdata XData[26]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
 uint16 j=0;
 uint8 i=0;
//==============================================================================
#pragma vector = 0x6B
__interrupt void PM0_ISR(void)
{
    P0IFG = 0x00;
    P0IF = 0;
    //SLEEP &= ~SLEEP_MODE;// Clear the [SLEEP.MODE] bits
    P1_0 = 1;      
}
//==============================================================================
void uart0send()
{
    U0BAUD=59;                  // For 9600 baud rate
    U0GCR=(U0GCR & ~0x1F)|8;
    U0CSR|=0x80;                //Asynch
    U0UCR=(U0UCR&~83)|0x02;
    U0GCR&=~0x20;

    PERCFG &= ~0x01;
    P0SEL|=0x3c;
    P1SEL&=~0x3c;
    CLKCON&=0x80;
    while(CLKCON & 0x40);
    SLEEP|=0x04;
    UTX0IF=0;
   
     for (i=0; i<=25; i++)
    {
      if(XData[i]>='A' && XData[i]<='Z')
      {
        U0DBUF = XData[i];
        while(!UTX0IF);
        UTX0IF=0;
      }
    }
}
//==============================================================================
void main(void)
{
    P1SEL &= ~0x06;                                                                                                                                                                             
    P1_0 = 1;
    P1_3 = 1;
    P1DIR |= 0x09;
    P0IF = 0;
    P0IFG &= 0x00;
    PICTL =  0x08;
   
    SLEEP &= ~0x04;
    while(!(SLEEP  & 0x20));            // Wait until HF RCOSC is stable
   
    CLKCON = (CLKCON & ~(0x07 | 0x40)) | (0x01);
    while (CLKCON & 0x40);
    SLEEP |=  0x07;                     // PM 3
   
    P0IE = 1;
    EA = 1;
      
        PCON |= 0x01;
        uart0send();
        P1_0 = 0;
}
//==============================================================================

  • Hi,

    I susupect there is no loop in main - you just wait for wakup once, send and the it's finished. Where is the loop you expected?

    Why don't you do the sending in the ISR itself? (Wakeup by interrupt - send - and go back to sleep?

     

     

  • Hello sir

    Even though writing a small loop like [while(1);] also then its not sending data...

    If i keep the send function in interrupt itself.. its continuously sending data..

    Hmm.. there might be small mistake but unable to find it... or unable to write the logic in another way..

  • I think what TF was trying to say is you need some way to repeat the send operation and the easiest way would be with a loop in main something like this

    void main(void)
    {
        P1SEL &= ~0x06;                                                                                                                                                                             
        P1_0 = 1;
        P1_3 = 1;
        P1DIR |= 0x09;
        P0IF = 0;
        P0IFG &= 0x00;
        PICTL =  0x08;
       
        SLEEP &= ~0x04;
        while(!(SLEEP  & 0x20));            // Wait until HF RCOSC is stable
       
        CLKCON = (CLKCON & ~(0x07 | 0x40)) | (0x01);
        while (CLKCON & 0x40);
        SLEEP |=  0x07;                     // PM 3
       
        P0IE = 1;
        EA = 1;
        while(1)
            {
      
            PCON |= 0x01;
            uart0send();
            P1_0 = 0;
            }
    }

    Without this loop, you simply return from the main function and no longer iterate on the button press in your uart0send routine.

    Jim Noxon