diff --git a/examples/platforms/cc2538/radio.c b/examples/platforms/cc2538/radio.c index 0a8cb22ed..ee2c8ebbd 100644 --- a/examples/platforms/cc2538/radio.c +++ b/examples/platforms/cc2538/radio.c @@ -69,6 +69,7 @@ static ThreadError sReceiveError; static uint8_t sTransmitPsdu[IEEE802154_MAX_LENGTH]; static uint8_t sReceivePsdu[IEEE802154_MAX_LENGTH]; +static uint8_t sChannel = 0; static PhyState sState = kStateDisabled; static bool sIsReceiverEnabled = false; @@ -109,7 +110,24 @@ void disableReceiver(void) void setChannel(uint8_t channel) { - HWREG(RFCORE_XREG_FREQCTRL) = 11 + (channel - 11) * 5; + if (sChannel != channel) + { + bool enabled = false; + + if (sIsReceiverEnabled) + { + disableReceiver(); + enabled = true; + } + + HWREG(RFCORE_XREG_FREQCTRL) = 11 + (channel - 11) * 5; + sChannel = channel; + + if (enabled) + { + enableReceiver(); + } + } } void otPlatRadioGetIeeeEui64(otInstance *aInstance, uint8_t *aIeeeEui64)