We have a product on the market that uses the nRF24 and a PIC, chosen primarily for it's cost and rapid development time. We are now looking into using a nRF52 to replace both the nRF24 and the PIC. I think I understand how ESB works on the nRF52, but I am confused about a couple of things:
#1: nrf_esb_set_prefixes & nrf_esb_set_base_address_1 – currently we are using a 3 byte Tx/Rx address: uint8_t RX_ADDR1[3] = {0x20, 0x23, 0x23}; I can’t tell if nrf_esb_set_prefixes is required on the nrf52, or can it be safely ignored and just use a 3 byte “esb_set_base_address_1”?
#2: nRF52 doesn’t seem to allow: “NRF_ESB_BITRATE_250KBPS”, which is ok. We can adjust, if necessary, on the Transmitter side.
#3: I am using “C:\nRF5_SDK_17.1.0_ddde560\examples\proprietary_rf\esb_prx”. Cortex/nRF52 is very new to me. I am more familiar with Microchip PIC C & Arduino C++ so if there are other things that would be helpful to be aware of please don’t hesitate to point them out to me.
#4 I have a “Nordic Semiconductor nRF52840-DK” to prototype with, but I am open to suggestions on low power, low cost nRF5x options for a simple application: ESB and some simple programming to control a couple of gpio pins. (no BLE, etc...)
my current PIC nRF24_Setup()
const uint8_t R_REG = 0x00;
const uint8_t W_REG = 0x20;
const uint8_t RX_PAYLOAD = 0x61;
const uint8_t TX_PAYLOAD = 0xA0;
const uint8_t FLUSH_TX = 0xE1;
const uint8_t FLUSH_RX = 0xE2;
const uint8_t ACTIVATE = 0x50;
const uint8_t R_STATUS = 0xFF;
//Registers
const uint8_t NRF_CONFIG = 0x00;
const uint8_t EN_AA = 0x01;
const uint8_t EN_RXADDR = 0x02;
const uint8_t SETUP_AW = 0x03;
const uint8_t SETUP_RETR = 0x04;
const uint8_t RF_CH = 0x05;
const uint8_t RF_SETUP = 0x06;
const uint8_t NRF_STATUS = 0x07;
const uint8_t OBSERVE_TX = 0x08;
const uint8_t CD = 0x09;
const uint8_t RX_ADDR_P0 = 0x0A;
const uint8_t RX_ADDR_P1 = 0x0B;
const uint8_t RX_ADDR_P2 = 0x0C;
const uint8_t RX_ADDR_P3 = 0x0D;
const uint8_t RX_ADDR_P4 = 0x0E;
const uint8_t RX_ADDR_P5 = 0x0F;
const uint8_t TX_ADDR = 0x10;
const uint8_t RX_PW_P0 = 0x11;
const uint8_t RX_PW_P1 = 0x12;
const uint8_t RX_PW_P2 = 0x13;
const uint8_t RX_PW_P3 = 0x14;
const uint8_t RX_PW_P4 = 0x15;
const uint8_t RX_PW_P5 = 0x16;
const uint8_t FIFO_STATUS = 0x17;
const uint8_t DYNPD = 0x1C;
const uint8_t FEATURE = 0x1D;
uint8_t TX_ADDR0[3] = {0x21, 0x23, 0x23}; //address actually = 0x23,0x23,0x21
uint8_t RX_ADDR1[3] = {0x20, 0x23, 0x23}; //address actually = 0x23,0x23,0x20
uint8_t rfCardPresent = 0x00; //False
//enums
enum nrfChannel{
channel_2402 = 0x02,
channel_2440 = 0x28,
channel_2480 = 0x50,
} channel;
enum nrfPower{
powerMinus_0 = 0x26, //250kbps, 0dBm
powerMinus_6 = 0x24, //250kbps, -6dBm
powerMinus_12 = 0x22, //250kbps, -12dBm
powerMinus_18 = 0x20, //250kbps, -18dBm
} power;
void nRF24_Setup(uint8_t _channel, uint8_t _power)
{
WriteRegister(NRF_CONFIG, 0x0B); //1 uint8_t CRC, POWER UP, PRX
WriteRegister(EN_AA, 0x00); //Disable auto ack
WriteRegister(EN_RXADDR, 0x01); //Enable data pipe 0
WriteRegister(SETUP_AW, 0x01); //3 uint8_t address
WriteRegister(SETUP_RETR, 0x00); //Retransmit disabled
WriteRegister(RF_CH, 0x01); //Randomly chosen RF channel
WriteRegister(RX_PW_P0, received_CCU_Payload_Length); //RX payload
WriteAddress(RX_ADDR_P0, 3, RX_ADDR1);
WriteAddress(TX_ADDR, 3, TX_ADDR0);
WriteRegister(RF_CH, _channel); //channel 2440
WriteRegister(RF_SETUP, _power); //250kbps, 0dBm
if ((ReadRegister(NRF_CONFIG) & 0x08) != 0)
rfCardPresent = 0x01;//True
}
and my proposed nRF52 esb_init( void ).
uint32_t esb_init( void )
{
uint32_t err_code;
uint8_t base_addr_0[4] = {0xE7, 0xE7, 0xE7, 0xE7};
uint8_t base_addr_1[4] = {0xC2, 0xC2, 0xC2, 0xC2};
uint8_t addr_prefix[8] = {0xE7, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8 };
nrf_esb_config_t nrf_esb_config = NRF_ESB_DEFAULT_CONFIG;
// Override - NRF_ESB_DEFAULT_CONFIG
nrf_esb_config.protocol = NRF_ESB_PROTOCOL_ESB;
nrf_esb_config.mode = NRF_ESB_MODE_PRX;
nrf_esb_config.event_handler = nrf_esb_event_handler;
nrf_esb_config.bitrate = NRF_ESB_BITRATE_1MBPS;
nrf_esb_config.crc = NRF_ESB_CRC_OFF;
nrf_esb_config.tx_output_power = NRF_ESB_TX_POWER_4DBM;
nrf_esb_config.payload_length = 32;
nrf_esb_config.selective_auto_ack = false;
err_code = nrf_esb_init(&nrf_esb_config);
VERIFY_SUCCESS(err_code);
err_code = nrf_esb_set_base_address_0(base_addr_0);
VERIFY_SUCCESS(err_code);
err_code = nrf_esb_set_base_address_1(base_addr_1);
VERIFY_SUCCESS(err_code);
err_code = nrf_esb_set_prefixes(addr_prefix, 8);
VERIFY_SUCCESS(err_code);
return err_code;
}