Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Negative TX power bug in ble_dtm.c

As far as I can tell there is a sign error bug when setting the tx power to a negative value. ble_dtm.c uses an int32_t to represent the tx power so when calling dtm_set_txpower with -4 (0xFC) the resulting bits in m_tx_power will be 0xFFFFFFFC.

Later when dtm_init() is called, m_tx_power is validated in ble_dtm_hw_nrf51.c and checked against the valid values in nrf51_bitfields.h, all of which are defined as (0xXXUL). This comparison will always fail and dtm_init reports invalid configuration.

It can be solved by adding the following line of code in dtm_set_txpower:

m_tx_power &= 0xFF;

Am I missing something here? Is there another way that this is supposed to work?

Parents Reply
  • I am indeed using an older version (12.3.0), but I have looked at ble_dtm.c in SDK 14.2 and the code related code looks exactly the same (int32_t m_tx_power, validation against unsigned long values and casting from int8_t to int32_t which fills the msb of m_tx_power with FF).
    I have changed my code to always set tx power to 0 before I call dtm_init() and then resetting it to the negative value. That works, but the RADIO->TX_POWER will still be set with 0xFFFFFFFC (-4) even though the reference manual kind of states that it should be set to 0x000000FC.

Children
No Data
Related