This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrf52832 can not receive pkt from nrf24le1

hi, all

I met a communication problem between nrf52832 and nrf24le1, I used nrf52832 as receiver and nrf24le1 as transmitter, but unfortunately,nrf52832 can not receive pkt from nrf24le1。my code are as follows: nrf52832:

static uint8_t sp_bits(uint8_t inp)

{

uint8_t i;
uint8_t retval = 0;

for (i = 0; i < 8; i++)
{
    retval |= ((inp >> i) & 0x01) << (7 - i);
}

return retval;

}

static uint32_t sp_byte(uint32_t inp) {

uint8_t i, inp_byte;
uint32_t retval = 0;

for ( i = 0; i < 4; i++) {
	inp_byte = (inp >> (i * 8));
	inp_byte = sp_bits(inp_byte);
	retval |= (inp_byte << (i * 8));
}

return retval;

}

void radio_config_init()

{

/* 0dbm */
NRF_RADIO->TXPOWER   = (RADIO_TXPOWER_TXPOWER_0dBm << RADIO_TXPOWER_TXPOWER_Pos);
/* 2400 */
NRF_RADIO->FREQUENCY = 0UL;
/* 250kbps */
NRF_RADIO->MODE      = (RADIO_MODE_MODE_Nrf_250Kbit << RADIO_MODE_MODE_Pos);

// Radio address config
NRF_RADIO->PREFIX0 =
    (sp_bits(0xC3) << 24) // Prefix byte of address 3 converted to nRF24L series format
  | (sp_bits(0xC2) << 16) // Prefix byte of address 2 converted to nRF24L series format
  | (sp_bits(0xC1) << 8)  // Prefix byte of address 1 converted to nRF24L series format
  | (sp_bits(0xE7) << 0); // Prefix byte of address 0 converted to nRF24L series format

NRF_RADIO->PREFIX1 =
    (sp_bits(0xC7) << 24) // Prefix byte of address 7 converted to nRF24L series format
  | (sp_bits(0xC6) << 16) // Prefix byte of address 6 converted to nRF24L series format
  | (sp_bits(0xC4) << 0); // Prefix byte of address 4 converted to nRF24L series format

NRF_RADIO->BASE0 = sp_byte(0xE7E7E7E7UL);  // Base address for prefix 0 converted to nRF24L series format

NRF_RADIO->TXADDRESS   = 0x00UL;  // Set device address 0 to use when transmitting
NRF_RADIO->RXADDRESSES = 0x01UL;  // Enable device address 0 to use to select which addresses to receive

// Packet configuration
NRF_RADIO->PCNF0 = (0     << RADIO_PCNF0_S1LEN_Pos) |
                   (0     << RADIO_PCNF0_S0LEN_Pos) |
                   (0 << RADIO_PCNF0_LFLEN_Pos); //lint !e845 "The right argument to operator '|' is certain to be 0"

// Packet configuration
NRF_RADIO->PCNF1 = (RADIO_PCNF1_WHITEEN_Disabled << RADIO_PCNF1_WHITEEN_Pos) |
                   (RADIO_PCNF1_ENDIAN_Big       << RADIO_PCNF1_ENDIAN_Pos)  |
                   (4   << RADIO_PCNF1_BALEN_Pos)   |
                   (5         << RADIO_PCNF1_STATLEN_Pos) |
                   (5       << RADIO_PCNF1_MAXLEN_Pos); //lint !e845 "The right argument to operator '|' is certain to be 0"

// CRC Config
NRF_RADIO->CRCCNF = (RADIO_CRCCNF_LEN_One<< RADIO_CRCCNF_LEN_Pos); // Number of checksum bits
if ((NRF_RADIO->CRCCNF & RADIO_CRCCNF_LEN_Msk) == (RADIO_CRCCNF_LEN_Two << RADIO_CRCCNF_LEN_Pos))
{
    NRF_RADIO->CRCINIT = 0xFFFFUL;   // Initial value
    NRF_RADIO->CRCPOLY = 0x11021UL;  // CRC poly: x^16 + x^12^x^5 + 1
}
else if ((NRF_RADIO->CRCCNF & RADIO_CRCCNF_LEN_Msk) == (RADIO_CRCCNF_LEN_One << RADIO_CRCCNF_LEN_Pos))
{
    NRF_RADIO->CRCINIT = 0xFFUL;   // Initial value
    NRF_RADIO->CRCPOLY = 0x107UL;  // CRC poly: x^8 + x^2^x^1 + 1
}

}

static uint8_t rxbuffer[64];

int main(void) {

uint32_t err_code;
uint8_t i;

bsp_board_leds_init();

const app_uart_comm_params_t comm_params =
  {
      RX_PIN_NUMBER,
      TX_PIN_NUMBER,
      RTS_PIN_NUMBER,
      CTS_PIN_NUMBER,
      APP_UART_FLOW_CONTROL_ENABLED,
      false,
      UART_BAUDRATE_BAUDRATE_Baud115200
  };

APP_UART_FIFO_INIT(&comm_params,
                     UART_RX_BUF_SIZE,
                     UART_TX_BUF_SIZE,
                     uart_error_handle,
                     APP_IRQ_PRIORITY_LOWEST,
                     err_code);

APP_ERROR_CHECK(err_code);
		
/* init radio */	
radio_config_init();
printf("\r\nStart: \r\n");

while (true)
{
NRF_RADIO->PACKETPTR = (uint32_t)rxbuffer;

NRF_RADIO->EVENTS_READY = 0U;
// Enable radio and wait for ready
NRF_RADIO->TASKS_RXEN = 1U;

while (NRF_RADIO->EVENTS_READY == 0U)
{
    // wait
}
NRF_RADIO->EVENTS_END = 0U;
// Start listening and wait for address received event
NRF_RADIO->TASKS_START = 1U;

// Wait for end of packet or buttons state changed
while (NRF_RADIO->EVENTS_END == 0U)
{
    // wait
}

if (NRF_RADIO->CRCSTATUS == 1U)
{
    /*  */
	for (i = 0; i < sizeof(rxbuffer); i++)
		app_uart_put(rxbuffer[i]);
}
NRF_RADIO->EVENTS_DISABLED = 0U;
// Disable radio
NRF_RADIO->TASKS_DISABLE = 1U;

while (NRF_RADIO->EVENTS_DISABLED == 0U)
{
    // wait
}
}

}

nrf24le1 config are follows:

L01_WriteSingleReg( L01REG_RX_PW_P0, FIXED_PACKET_LEN );  /* SET pipe0 rx number */
L01_WriteSingleReg( L01REG_CONFIG, /*( 1<<MASK_RX_DR ) |*///receive interrupt
                                  ( 1<<EN_CRC ) |     //Enable CRC, 1 byte
                                  ( 1<<PWR_UP ) );    //Power up the device
L01_WriteSingleReg( L01REG_EN_AA, ( 1<<ENAA_P0 ) );   //Auto ack in pipe 0
L01_WriteSingleReg( L01REG_EN_RXADDR, ( 1<<ERX_P0 ) );//Enable pipe 0 receive
L01_WriteSingleReg( L01REG_SETUP_AW, AW_5BYTES );     //Address width : 5Byte
L01_WriteSingleReg( L01REG_RETR, ARD_4000US |
                    ( REPEAT_CNT & 0x0F ) );         //repeat wait : 4000us, 15 repeat
L01_WriteSingleReg( L01REG_RF_CH, 0x00 );             //Initial channel
L01_WriteSingleReg( L01REG_RF_SETUP, 0x26 );  /* 0dbm, 250kbps */
L01_SetTXAddr( &addr[0], 5 );                          //Set TX address, own address
L01_SetRXAddr( 0, &addr[0], 5 ); 

the &addr[0] is the address of addr[5]= {0xE7,0xE7,0xE7,0xE7,0xE7} ;

by using debug session with keil 5.15, running is stopped at NRF_RADIO->TASKS_START = 1U;

can anybody tell me what's wrong with the code. BR

Parents
  • Hi DK

    I would strongly recommend using the ESB library in the nRF5 SDK. It is made to be compatible with the nRF24L series: ESB example documentation

    Then you will get all the ESB functionality for free, including auto ACK, ACK payload and dynamic payload length.

    Another thing to be aware of is that the nRF52832 doesn't support the 250kbps on air radio mode. If you want compatibility between it and the nRF24LE1 you would have to use the 1Mbps or 2Mbps mode instead.

    Best regards
    Torbjørn

Reply
  • Hi DK

    I would strongly recommend using the ESB library in the nRF5 SDK. It is made to be compatible with the nRF24L series: ESB example documentation

    Then you will get all the ESB functionality for free, including auto ACK, ACK payload and dynamic payload length.

    Another thing to be aware of is that the nRF52832 doesn't support the 250kbps on air radio mode. If you want compatibility between it and the nRF24LE1 you would have to use the 1Mbps or 2Mbps mode instead.

    Best regards
    Torbjørn

Children
Related