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.

cc2530 sample code doubt

Other Parts Discussed in Thread: CC2530

I don't understand how the line

"SLEEPCMD &= ~SLEEP_OSC_PD_BM;       // power up both oscillators" 

in the following function works... can some one help me?

This is a sample code from the cc2530 sample examples (Components\radios\cc2530\clock.c)

 

void clockSetMainSrc(uint8 source)
{
    register uint8 osc32k_bm = CLKCONCMD & CLKCON_OSC32K_BM;

    // Source can have the following values:
    // CLOCK_SRC_XOSC   0x00  High speed Crystal Oscillator (XOSC)
    // CLOCK_SRC_HFRC   0x01  Low power RC Oscillator (HFRC)
   
    SLEEPCMD &= ~SLEEP_OSC_PD_BM;       // power up both oscillators
    while (!CC2530_IS_HFRC_STABLE() || ((SLEEPSTA & SLEEP_OSC_PD_BM)!=0));// wait until the oscillator is stable
    NOP();

    if (source == CLOCK_SRC_HFRC){
        CLKCONCMD = (osc32k_bm | CLKCON_OSC_BM | TICKSPD_DIV_2 | CLKCON_CLKSPD_BM);
    }
    else if (source == CLOCK_SRC_XOSC){
        CLKCONCMD = (osc32k_bm | TICKSPD_DIV_1);
    }
    CC2530_WAIT_CLK_UPDATE();
    SLEEPCMD |= SLEEP_OSC_PD_BM;        // power down the unused oscillator
}

i m refering swru191b.pdf  (cc253x user manual)

this is the sleepcmd register description :

SLEEPCMD (0xBE) – Sleep-Mode Control Command

Bit    description/value

7       OSC32K_CALDIS 0 R/W Disable 32-kHz RC oscillator calibration


0: 32-kHz RC oscillator calibration is enabled.
1: 32-kHz RC oscillator calibration is disabled.
This setting can be written at any time, but does not take effect before the chip has
been running on the 16-MHz high-frequency RC oscillator.


6:3 – 000 0 R0 Reserved

2 – 1 R/W Reserved. Always write as 1

1:0 MODE[1:0] 00 R/W Power-mode setting


00: Active / Idle mode
01: Power mode 1 (PM1)
10: Power mode 2 (PM2)
11: Power mode 3 (PM3)

and

#define SLEEP_OSC_PD_BM     0x04

and,

SLEEPCMD.OSC_PD this as seen in Figure 4-1. Clock System Overview.

The OSC_PD is not defined in the register definition of SLEEPCMD.

  • Hello,

    SLEEPCMD &= ~SLEEP_OSC_PD_BM;       // power up both oscillators

    this line of code makes no sense to me too for these reasons:

    1 - this code writes a 0 to a Reverved bit (bit 2) that the datasheet says to always write as 1;

    2 - like the comment says, it enables both oscillators, but to enable both oscillators we only need to force the active/idle mode (bit 0:1);

    3 - this line of code force also the OSC32K_CALDIS bit to 0, which means it enables the calibration of 32-kHz RC oscillator.

    And this line does not makes sense also:

    SLEEPCMD |= SLEEP_OSC_PD_BM;        // power down the unused oscillator

    it only afects the Reserved bit..

    Can someone clarify this code because im very confused, im using CC2530.

    Thank you

    Filipe Palhinha