PreviousNext
setRFmode
Help > OS functions > RF > setRFmode

Function

 

Set modes for RF operation

Purpose

 

Specify RF RX and RF TX power modes and conditions for RX termination.

Syntax

 

void setRFmode(uns8 mode)

Parameters

 

mode: PWTTNFRR in binary

P     Preamble length in STD TX

       0    Standard preamble length (4 ms)

       1    Prolonged preamble length (8 ms). Suitable e.g. when working at two different RF channels.

W     Wait packet end

       0    Terminate RFRXpacket unconditionally when toutRF expired.

       1    Do not terminate RFRXpacket (ignore toutRF expiry) if the packet is currently receiving.

TT   TX mode

       00  STD TX mode (standard ~4 ms or prolonged ~8 ms preamble)

       01  LP TX mode (prolonged preamble ~50 ms)

       10  XLP TX mode (prolonged preamble ~900 ms)

       11  Reserved, do not use

Reserved for future use

Enable immediate RX termination (before toutRF timeout) when low level on the C5 (for TRs       for SIM mounting, e.g. TR-72G) or Q12 (for TRs for SMT mounting, e.g.TR-76G) pin occurred. For low LP RX and XLP RX modes only.

RR   RX mode

       00  STD RX mode (Standard RX). Use STD TX mode at the counterpart.

       01  LP RX mode (Low power RX). Use LP TX or XLP TX mode at the counterpart.

       10  XLP RX mode (Extra low power RX). Use XLP TX mode at the counterpart.

       11  Reserved, do not use.

Return value

 

  –

Output values

 

Available read only in the RFmodeByte register.

Preconditions

 

Default value is mode = 0.

Remarks

 

Tip:  As the parameters, use constants (and their ored combinations), especially the predefined ones in IQRF-macros.h header file instead of binary values. See Examples E10-RFMODE-TX, E10‑RFMODE‑RX, and Examples 1 to 4 below.

Side effects

 

RF circuitry and MCU is temporarily set to sleep during low power RX modes. Thus, all tasks running on the OS background (e.g. SPI communication, LED indication, etc.) can be untimely canceled. To avoid this, use setRFmode after finishing all background tasks. See Example 4.

See also

 

checkRF

Example 1

 

       // RX: STD, TX: for STD RX (standard, preamble 4 ms)

setRFmode(0b00000000);           // Using numeral value

setRFmode(_RX_STD | _TX_STD)     // The same using predefined constants for clarity

Example 2

 

       // RX: LP, TX: for LP RX (prolonged preamble ~50 ms)

setRFmode(0b00010001);           // Using numeral value

setRFmode(_RX_LP | _TX_LP)       // The same using predefined constants for clarity

Example 3

 

       // RX: STD, TX: for STD RX (standard, preamble 8 ms)

setRFmode(0b10000000);                  // Using numeral value

setRFmode(_RX_STD | _TX_STD | _STDL)    // The same using predefined constants for                                          // clarity

Example 4

 

while (getStatusSPI())           // Wait for finishing SPI on background

  clrwdt();

disableSPI();

SWDTEN = 0;                       // Possibly disable WDT for lower consumption

setRFmode(_RX_LP | _TX_LP);      // and go to LP mode then


 

Example 5

 

// RFRXpacket terminated after low level on C5/Q12 is detected and

// current cycle is finished.

 

toutRF = 100;              // [in cycles], 1 cycle = ~790 ms

 

while (1)

{

  setRFmode(_RX_XLP | _RLPMAT);  // RX_XLP + LP/XLP RX termination

  if (RFRXpacket())

  {

    ...

  }

 

  …                        // Goes here after every 79 s (toutRF=100) or

                           //   if low level appears on the C5/Q12 pin

                           //      in a moment when RX XLP cycle is finished

 

  if (buttonPressed)

  {

    ...

    setRFmode(_RX_STD);   // Set required TX preamble

    RFTXpacket();

  }

}

Example 6

 

// RFRXpacket terminated immediately after low level on C5/Q12 is detected.

// It is necessary to activate interrupt on change periodically.

 

toutRF = 100;                    // [in cycles], 1 cycle = ~790 ms

 

while (1)

{

  setRFmode(_RX_XLP | _RLPMAT);  // RX_XLP + LP/XLP RX termination

 

  writeToRAM(&IOCBN, IOCBN | 0x10);     // Negative edge active.

                                         // Instead of IOCBN.4=1;

                                         // Bit IOCBN.4 cannot be accessed

                                         // directly due to OS restriction.

  IOCBP.4 = 1;                          // Positive edge active too

  IOCIE = 1;                     // Interrupt on change enabled

 

  writeToRAM(&IOCBF, IOCBF & 0xEF); // Clear interrupt on change flag.

                                         // Instead of IOCBF.4=0;

                                         // Bit IOCBF.4 cannot be accessed                                                     // directly due to OS restriction.

 

  if (RFRXpacket())

  {

    ...

  }

  …                     // Goes here after every 79 s (toutRF=100) or

                        //   immediately if low level appears on the C5/Q12 pin

 

  if (buttonPressed)

  {

    ...

    setRFmode(_RX_STD);                 // Set required TX preamble

    RFTXpacket();

  }

}