This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Controlling BLE TX power within Timeslot API ?

Any idea how I can control the TX power within the Timeslot API in SDK v6 SD110 v7?

Are there something similar to "sd_ble_gap_tx_power_set(tx_power)" in the Timeslot API for adjusting the output power of the BLE?

Justin

Parents
  • I have also found a way to set the TX power using radio_init() in "ts_peripheral.c". The default TX Power is set in the function to 0dBm as follows, but there is no reason why we cannot change it to any other legal values we desire.

    static __INLINE void radio_init(void) 
    {
      /* Set radio configuration parameters */
      NRF_RADIO->TXPOWER = (RADIO_TXPOWER_TXPOWER_0dBm << RADIO_TXPOWER_TXPOWER_Pos); 
    ... 
    

    The legal values are defined in "nrf51_bitfields.h" as:

    #define RADIO_TXPOWER_TXPOWER_Pos4dBm  (0x04UL) /*!< +4dBm. */
    #define RADIO_TXPOWER_TXPOWER_0dBm     (0x00UL) /*!< 0dBm. */
    #define RADIO_TXPOWER_TXPOWER_Neg4dBm  (0xFCUL) /*!< -4dBm. */
    #define RADIO_TXPOWER_TXPOWER_Neg8dBm  (0xF8UL) /*!< -8dBm. */
    #define RADIO_TXPOWER_TXPOWER_Neg12dBm (0xF4UL) /*!< -12dBm. */
    #define RADIO_TXPOWER_TXPOWER_Neg16dBm (0xF0UL) /*!< -16dBm. */
    #define RADIO_TXPOWER_TXPOWER_Neg20dBm (0xECUL) /*!< -20dBm. */
    #define RADIO_TXPOWER_TXPOWER_Neg30dBm (0xD8UL) /*!< -30dBm.*/
    

    To set this value in "main.c" programmatically rather than hard coding it in radio_init(), I created a local variable in "ts_peripheral.c" with the same 0dBm default value:

    static uint8_t tx_power = (RADIO_TXPOWER_TXPOWER_0dBm << RADIO_TXPOWER_TXPOWER_Pos);
    

    Then I created a modifier function in "ts_peripheral.c" to update the value:

    void ts_set_tx_power(uint8_t custom_tx_power) //Funtion to set tx_power
    {
         tx_power = (custom_tx_power << RADIO_TXPOWER_TXPOWER_Pos); 
    }
    

    and in radio_init(), change the TXPOWER assignment to:

    NRF_RADIO->TXPOWER = tx_power; 
    

    All we need to do now is publicise this function in "ts_peripheral.h" and include it in "main.c". Calling it before enabling BLE advertisement will set the tx power, e.g.:

    #include "ts_peripheral.h"
     ...
    int main(void)
     {
          ...
          ts_set_tx_power(RADIO_TXPOWER_TXPOWER_Pos4dBm);
          ...
     }
    

    Update: I found out today that this will also work during runtime after initialisation, because "radio_init()" is always called before sending each advertising packet. So you can call "ts_set_tx_power(custom_tx_power)" any time you like, and the following packet will be sent at the new tx power.

Reply
  • I have also found a way to set the TX power using radio_init() in "ts_peripheral.c". The default TX Power is set in the function to 0dBm as follows, but there is no reason why we cannot change it to any other legal values we desire.

    static __INLINE void radio_init(void) 
    {
      /* Set radio configuration parameters */
      NRF_RADIO->TXPOWER = (RADIO_TXPOWER_TXPOWER_0dBm << RADIO_TXPOWER_TXPOWER_Pos); 
    ... 
    

    The legal values are defined in "nrf51_bitfields.h" as:

    #define RADIO_TXPOWER_TXPOWER_Pos4dBm  (0x04UL) /*!< +4dBm. */
    #define RADIO_TXPOWER_TXPOWER_0dBm     (0x00UL) /*!< 0dBm. */
    #define RADIO_TXPOWER_TXPOWER_Neg4dBm  (0xFCUL) /*!< -4dBm. */
    #define RADIO_TXPOWER_TXPOWER_Neg8dBm  (0xF8UL) /*!< -8dBm. */
    #define RADIO_TXPOWER_TXPOWER_Neg12dBm (0xF4UL) /*!< -12dBm. */
    #define RADIO_TXPOWER_TXPOWER_Neg16dBm (0xF0UL) /*!< -16dBm. */
    #define RADIO_TXPOWER_TXPOWER_Neg20dBm (0xECUL) /*!< -20dBm. */
    #define RADIO_TXPOWER_TXPOWER_Neg30dBm (0xD8UL) /*!< -30dBm.*/
    

    To set this value in "main.c" programmatically rather than hard coding it in radio_init(), I created a local variable in "ts_peripheral.c" with the same 0dBm default value:

    static uint8_t tx_power = (RADIO_TXPOWER_TXPOWER_0dBm << RADIO_TXPOWER_TXPOWER_Pos);
    

    Then I created a modifier function in "ts_peripheral.c" to update the value:

    void ts_set_tx_power(uint8_t custom_tx_power) //Funtion to set tx_power
    {
         tx_power = (custom_tx_power << RADIO_TXPOWER_TXPOWER_Pos); 
    }
    

    and in radio_init(), change the TXPOWER assignment to:

    NRF_RADIO->TXPOWER = tx_power; 
    

    All we need to do now is publicise this function in "ts_peripheral.h" and include it in "main.c". Calling it before enabling BLE advertisement will set the tx power, e.g.:

    #include "ts_peripheral.h"
     ...
    int main(void)
     {
          ...
          ts_set_tx_power(RADIO_TXPOWER_TXPOWER_Pos4dBm);
          ...
     }
    

    Update: I found out today that this will also work during runtime after initialisation, because "radio_init()" is always called before sending each advertising packet. So you can call "ts_set_tx_power(custom_tx_power)" any time you like, and the following packet will be sent at the new tx power.

Children
Related