Dear All,
while evaluating low-power options in the context of wireless sensors, I've stumbled upon a strange behavior with the nRF52832 using ESB from SDK 14.2. Here's the outline of my test code:
#include "nrf_delay.h"
#include "nrf_drv_clock.h"
#include "nrf_drv_power.h"
#include "nrf_esb.h"
#include "nrf_pwr_mgmt.h"
#include "nrf.h"
static nrf_esb_config_t const m_esbConfig_TX=
{
.protocol = NRF_ESB_PROTOCOL_ESB_DPL,
.mode = NRF_ESB_MODE_PTX,
.event_handler = EsbEventHandler,
.bitrate = NRF_ESB_BITRATE_2MBPS,
.crc = NRF_ESB_CRC_16BIT,
.tx_output_power = NRF_ESB_TX_POWER_0DBM,
.retransmit_delay = 250,
.retransmit_count = 100,
.tx_mode = NRF_ESB_TXMODE_MANUAL,
.radio_irq_priority = 1,
.event_irq_priority = 2,
.payload_length = NRF_ESB_MAX_PAYLOAD_LENGTH,
.selective_auto_ack = false
};
static nrf_esb_config_t const m_esbConfig_RX=
{
.protocol = NRF_ESB_PROTOCOL_ESB_DPL,
.mode = NRF_ESB_MODE_PRX,
.event_handler = EsbEventHandler,
.bitrate = NRF_ESB_BITRATE_2MBPS,
.crc = NRF_ESB_CRC_16BIT,
.tx_output_power = NRF_ESB_TX_POWER_0DBM,
.retransmit_delay = 250,
.retransmit_count = 3,
.tx_mode = NRF_ESB_TXMODE_AUTO,
.radio_irq_priority = 1,
.event_irq_priority = 2,
.payload_length = NRF_ESB_MAX_PAYLOAD_LENGTH,
.selective_auto_ack = false
};
int main(void)
{
ret_code_t retCode= NRF_SUCCESS;
nrf_pwr_mgmt_init();
nrf_drv_clock_init();
nrf_drv_clock_lfclk_request(NULL);
nrf_drv_clock_hfclk_request(NULL);
nrf_esb_set_prefixes(m_esbAddressPrefix, 1);
nrf_esb_set_base_address_0(m_esbAddressBase0);
nrf_esb_set_base_address_1(m_esbAddressBase1);
nrf_esb_set_rf_channel(10);
// initialize radio in the specified ESB mode (use m_esbConfig_RX or m_esbConfig_TX)
nrf_esb_config_t esbConfig= m_esbConfig_TX;
nrf_esb_init(&esbConfig);
if (esbConfig.mode == NRF_ESB_MODE_PTX)
{
nrf_esb_payload_t payloadTx= {0};
payloadTx.length= 16;
nrf_esb_write_payload(&payloadTx);
nrf_delay_ms(1000);
nrf_esb_start_tx();
nrf_delay_ms(1000);
}
else if (esbConfig.mode == NRF_ESB_MODE_PRX)
{
nrf_delay_ms(1000);
nrf_esb_start_rx();
nrf_delay_ms(1000);
nrf_esb_stop_rx();
}
nrf_esb_disable();
nrf_drv_clock_hfclk_release();
while (1)
{
nrf_pwr_mgmt_run();
}
}
The last few lines put the system into System On low-power mode, and that's where it becomes interesting. It seems if I use the radio in RX mode and then disable it, the system draws about 1.4 µA (3V) current, whereas if I use the radio in TX mode and then disable it, the current drawn is about 8 µA. I briefly looked into the ESB implementation, but I can't find the bug (if any). Here two graphs showing the problem:
Things I tried:
- disabling all interrupts manually right after the nrf_esb_disable() call --> no difference;
- manually releasing PPI channels that may have been left configired by ESB --> no difference;
- setting m_address_hang_fix_enable in nrf_esb.c to false --> no difference;
- after using the ESB in PTX mode, re-setting it to PRX, then disable --> no difference.
I would really like to sort out this problem. Any help would be appreciated!
Thanks,
Tamas