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: Reading and setting the sleep timer without waiting for rising edges

Part Number: CC2530
Other Parts Discussed in Thread: CC2533, , Z-STACK, REMOTI

Tool/software:

The user guide for the CC2530 and CC2533 has the following text.

The Sleep Timer is running when operating in all power modes except PM3. The value of the Sleep Timer

is not preserved in PM3. When returning from PM1 or PM2 (where the system clock is shut down), the

Sleep Timer value in ST2:ST1:ST0 is not up-to-date until a positive edge on the 32-kHz clock has been

detected after the system clock restarted. To ensure an updated value is read, wait for a positive transition

on the 32-kHz clock by polling the SLEEPSTA.CLK32K bit, before reading the Sleep Timer value.

This implies that I should write code to ensure that  SLEEPSTA.CLK32K !=0 before reading ST0 (or wait for the next rising edge which would wait for SLEEPSTA.CLK32K to be 1 and then 0, and then 1 again to get the next rising edge).

The code in Z-Stack 3.02 for the CC2530EB does not have this wait.  Is the wait required?

void halSleepSetTimer(uint32 timeout)
{
uint32 ticks;

/* read the sleep timer; ST0 must be read first */
((uint8 *) &ticks)[UINT32_NDX0] = ST0;
((uint8 *) &ticks)[UINT32_NDX1] = ST1;
((uint8 *) &ticks)[UINT32_NDX2] = ST2;
((uint8 *) &ticks)[UINT32_NDX3] = 0;

/* Compute sleep timer compare value. The ratio of 32 kHz ticks to 320 usec ticks
* is 32768/3125 = 10.48576. This is nearly 671/64 = 10.484375.
*/
ticks += (timeout * 671) / 64;

/* subtract the processing time spent in function halSleep() */
ticks -= HAL_SLEEP_ADJ_TICKS;

/* set sleep timer compare; ST0 must be written last */
ST2 = ((uint8 *) &ticks)[UINT32_NDX2];
ST1 = ((uint8 *) &ticks)[UINT32_NDX1];
ST0 = ((uint8 *) &ticks)[UINT32_NDX0];
}

Similarly, the user guide states to wait until STLOAD.LDRDY is 1 before wring to ST2.  The code above does not do that.  However, the macro used for the CC2533EB in RemoTI 1.4.0, waits after setting the sleep timer registers.

#define HAL_SLEEP_ST_SET(STCNT) st ( \
/* Set the sleep timer compare; ST0 must be written last. */\
ST2 = ((uint8 *) &(STCNT))[2]; \
ST1 = ((uint8 *) &(STCNT))[1]; \
ST0 = ((uint8 *) &(STCNT))[0]; \
while (!(STLOAD & LDRDY)); /* Wait for the sleep timer to load. */\
)

Which version (the user guide, Z-Stack, or RemoTI) is correct or does it matter?

  • Hi,

    This implies that I should write code to ensure that  SLEEPSTA.CLK32K !=0 before reading ST0 (or wait for the next rising edge which would wait for SLEEPSTA.CLK32K to be 1 and then 0, and then 1 again to get the next rising edge).

    The code in Z-Stack 3.02 for the CC2530EB does not have this wait.  Is the wait required?

    void halSleepSetTimer(uint32 timeout)

    By the time halSleepSetTimer is called, the ST values are likely expected to be valid, so adding an additional check would be redundant.

    Similarly, the user guide states to wait until STLOAD.LDRDY is 1 before wring to ST2.  The code above does not do that.  However, the macro used for the CC2533EB in RemoTI 1.4.0, waits after setting the sleep timer registers.
    Which version (the user guide, Z-Stack, or RemoTI) is correct or does it matter?

    I would follow the User Guide. There may be other assumptions happening at the level of Z-Stack which may already handle the wait specified in the User Guide.

    In your previous post (e2e.ti.com/.../cc2530-is-timer-2-needed-if-using-only-the-802-15-4-phy-in-the-cc2530) it seems you do not need to use Z-Stack MAC, and if that is the case then any code in Z-Stack should be used only for reference. If any discrepancy arises between Z-Stack and User Guide, the User Guide should take precedence.

    Thanks,
    Toby