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.

CC2541-Q1: CC2541 comparator is not working

Part Number: CC2541-Q1
Other Parts Discussed in Thread: CC2541

Hi,

We are working on CC2541 based project. For waking up CC2541 from PM3, we are trying to use internal comparator (P0.4 and P0.5). The comparator got enabled but the output is not getting toggle with different inputs. i.e always gives same output. Note: In PM3 mode, customized ISR got triggered.

The following registers are set with corresponding values:

APCFG |= 0x30;

IEN1 |= 0x20;

P0IEN = 0x00;

P0DIR &= ~(0x30);

CMPCTL |= 0x02;

Did I miss any configurations?

My question is how to toggle comparator for waking up CC2541 from PM3 as an external trigger?

Thanks,

Vipin.

 

  • Hello,
    The output of the comparator is routed to the edge detect circuitry for P0.5. Simply configure a regular pin interrupt on P0.5. Are you checking the value of your IO configuration in debug mode to verify that the settings your posted are not reconfigured elsewhere in your application?
  • Hi,

    If I configure an interrupt for P0_5 using P0IEN = 0x20; then the interrupt service routine always gets triggered. Maybe this is because the voltage at P0_5 (which is +ve terminal for comparator) is somewhere close to 2.1V.

    The P0_4 is at 2.3V. I want the ISR to get triggered when the P0_5 input crosses 2.3V.

    Regarding your question, "Are you checking the value of your IO configuration in debug mode to verify that the settings your posted are not reconfigured elsewhere in your application?"
    Yes. Just before I check for the CMPCTL.OUTPUT, I put a break point and all the registers are at expected values.

    Thanks.
  • Hello Vipin,

    I tested it successfully on a CC2541EM+SRF05EB. You need to enable interrupt on P0.5. Here is my code:

    #pragma vector = P0INT_VECTOR
    __interrupt void p0_ISR(void)
    {
        /* Note that the order in which the following flags are cleared is important.
           For level triggered interrupts (port interrupts) one has to clear the module
           interrupt flag prior to clearing the CPU interrupt flags. */
    
        // Clear status flag for pin with R/W0 method, see datasheet.
        P0IFG = ~P0IFG;
        // Clear CPU interrupt status flag for P0.
        P0IF = 0;
    
        // Toggle SRF05EB LED1.
        P1_0 ^= 1;
    }
    
    
    void main(void) {
        /***************************************************************************
        * Clock setup
        * See basic software example "clk_xosc_cc254x"
        */
    
        // Set system clock source to HS XOSC, with no pre-scaling.
        CLKCONCMD = (CLKCONCMD & ~(CLKCON_OSC | CLKCON_CLKSPD)) | CLKCON_CLKSPD_32M;
        while (CLKCONSTA & CLKCON_OSC);   //Wait until clock source has changed
    
        /* Note the 32 kHz RCOSC starts calibrating, if not disabled. */
    
    
        // Initialize P1_0 for SRF05EB LED1.
        P1SEL &= ~BIT0;           // Function as General Purpose I/O.
        P1_0 = 1;                 // LED1 on.
        P1DIR |= BIT0;            // Output.
    
    
        /*  Enable comparator input pins
        *   P0.5 +
        *   P0.4 -
        */
        APCFG |= 0x30;
    
        // Clear Port 0 Interrupt flags.
        P0IF = 0;
        P0IFG = 0x00;
    
        // Interrupt enable on P0.5
        P0IEN = 0x20;
    
        // Enable CPU Interrupt for Port 0 (IEN1.P0IE = 1).
        P0IE = 1;
    
        // Enable Global Interrupt by setting the (IEN0.EA = 1).
        EA = 1;
    
        // Enable the comparator.
        CMPCTL |= 0x02;
    
    
        /***********************************************************************
        * Setup powermode
        */
        // Set [SLEEPCMD.MODE] to PM3.
        SLEEPCMD = (SLEEPCMD & ~SLEEPCMD_MODE) | SLEEPCMD_MODE_PM3;
    
        /* Main Loop, enter/exit Power Mode 3. */
        while(1)
        {
            // Enter powermode
            // Sets PCON.IDLE with a 2-byte boundary assembly instruction.
            // NOTE: Cache must be enabled (see CM in FCTL).
            // This method gives the least current consumption.
            EnterSleepModeProcessInterruptsOnWakeup();
        }
    }