The PTX is nRF24L01+ and the PRX is nRF52833.
The code for the nRF24L01+:
void RF24L01_Init( void )
{
uint8_t addr[5] = {0x34,0x43,0x10,0x10,0x03};
uint8_t txAddr[5] = {0x34,0x43,0x10,0x10,0x02};
RF24L01_SET_CE_HIGH( );
NRF24L01_Clear_IRQ_Flag( IRQ_ALL );
NRF24L01_Write_Reg( DYNPD, ( 1 << 0 ) );
NRF24L01_Write_Reg( FEATRUE, 0x07);
NRF24L01_Read_Reg( DYNPD );
NRF24L01_Read_Reg( FEATRUE );
NRF24L01_Write_Reg( CONFIG, /*( 1<<MASK_RX_DR ) |*/
( 1 << EN_CRC ) |
( 1 << PWR_UP ) );
NRF24L01_Write_Reg( EN_AA, ( 1 << ENAA_P0 ) );
NRF24L01_Write_Reg( EN_RXADDR, ( 1 << ERX_P0 ) );
NRF24L01_Write_Reg( SETUP_AW, AW_5BYTES );
NRF24L01_Write_Reg( SETUP_RETR, ARD_4000US |
( REPEAT_CNT & 0x0F ) );
NRF24L01_Write_Reg( RF_CH, 10 );
NRF24L01_Write_Reg( RF_SETUP, 0x26 );
NRF24L01_Write_Reg( RX_PW_P0, 18 );
NRF24L01_Set_TxAddr( &txAddr[0], 5 );
NRF24L01_Set_RxAddr( 0, &addr[0], 5 );
NRF24L01_Set_Speed(SPEED_2M);
NRF24L01_Set_Power(POWER_0DBM);
}
uint8_t NRF24L01_TxPacket( uint8_t *txbuf, uint8_t Length )
{
uint8_t l_Status = 0;
uint32_t l_MsTimes = 0;
RF24L01_SET_CS_LOW( );
do
{
uint8_t RegAddr = FLUSH_TX;
HAL_StatusTypeDef errorcode = HAL_OK;
errorcode = HAL_SPI_Transmit(NF24L01_SPI, &RegAddr, 1, NF24L01_SPI_OP_TIMEOUT);
if(errorcode != HAL_OK)
{
printf("### NRF24L01_TxPacket fail %d ###\r\n", errorcode);
break;
}
} while (0);
RF24L01_SET_CS_HIGH( );
RF24L01_SET_CE_LOW( );
NRF24L01_Write_Buf( WR_TX_PLOAD, txbuf, Length );
RF24L01_SET_CE_HIGH( );
l_MsTimes = xTaskGetTickCount();
while( 0 != RF24L01_GET_IRQ_STATUS( ))
{
if ((xTaskGetTickCount() - l_MsTimes) > 100)
{
NRF24L01_Write_Reg(FLUSH_TX, 0xff);
NRF24L01_Write_Reg(STATUS, 0x30);
break;
}
}
l_Status = NRF24L01_Read_Reg(STATUS);
NRF24L01_Write_Reg( STATUS, l_Status );
if( l_Status & MAX_TX )
{
NRF24L01_Write_Reg( FLUSH_TX,0xff );
return MAX_TX;
}
if( l_Status & TX_OK )
{
return TX_OK;
}
return 0xFF;
}
Everytime I call NRF24L01_TxPacket to send out 32 bytes data I get the error code MAX_TX. But the nRF52833 actually has received the data.
So I think the nRF52833 doesn't reply back to the nRF24L01+ . And how do I fix this issue?
The nRF52833 sdk version is nRF5_SDK_17.1.0_ddde560.
And I use esb_prx (pca10100e) this project.
/**
* Copyright (c) 2014 - 2021, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "nrf_esb.h"
#include <stdbool.h>
#include <stdint.h>
#include "sdk_common.h"
#include "nrf.h"
#include "nrf_esb_error_codes.h"
#include "nrf_delay.h"
#include "nrf_gpio.h"
#include "nrf_error.h"
#include "boards.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
uint8_t led_nr;
nrf_esb_payload_t rx_payload;
/*lint -save -esym(40, BUTTON_1) -esym(40, BUTTON_2) -esym(40, BUTTON_3) -esym(40, BUTTON_4) -esym(40, LED_1) -esym(40, LED_2) -esym(40, LED_3) -esym(40, LED_4) */
void nrf_esb_event_handler(nrf_esb_evt_t const * p_event)
{
static uint8_t count = 0;
switch (p_event->evt_id)
{
case NRF_ESB_EVENT_TX_SUCCESS:
NRF_LOG_DEBUG("TX SUCCESS EVENT");
break;
case NRF_ESB_EVENT_TX_FAILED:
NRF_LOG_DEBUG("TX FAILED EVENT");
break;
case NRF_ESB_EVENT_RX_RECEIVED:
//NRF_LOG_DEBUG("RX RECEIVED EVENT");
if (nrf_esb_read_rx_payload(&rx_payload) == NRF_SUCCESS)
{
// Set LEDs identical to the ones on the PTX.
/*
nrf_gpio_pin_write(LED_1, !(rx_payload.data[1]%8>0 && rx_payload.data[1]%8<=4));
nrf_gpio_pin_write(LED_2, !(rx_payload.data[1]%8>1 && rx_payload.data[1]%8<=5));
nrf_gpio_pin_write(LED_3, !(rx_payload.data[1]%8>2 && rx_payload.data[1]%8<=6));
nrf_gpio_pin_write(LED_4, !(rx_payload.data[1]%8>3));
*/
nrf_gpio_pin_write(LED_1, count % 2);
nrf_gpio_pin_write(LED_2, count % 2);
nrf_gpio_pin_write(LED_3, count % 2);
nrf_gpio_pin_write(LED_4, count % 2);
count++;
//NRF_LOG_DEBUG("Receiving packet: Length == %d, rssi == %d", rx_payload.length, rx_payload.rssi);
}
break;
}
}
void clocks_start( void )
{
NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
NRF_CLOCK->TASKS_HFCLKSTART = 1;
while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0);
}
void gpio_init( void )
{
bsp_board_init(BSP_INIT_LEDS);
}
uint32_t esb_init( void )
{
uint32_t err_code;
/*
uint8_t base_addr_0[4] = {0x43,0x10,0x10,0x01};
uint8_t base_addr_1[4] = {0x43,0x10,0x10,0x01};
uint8_t addr_prefix[8] = {0x34, 0x34, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8 };
*/
uint8_t base_addr_0[4] = {0x43,0x10,0x10,0x02};
uint8_t base_addr_1[4] = {0x43,0x10,0x10,0x02};
uint8_t addr_prefix[8] = {0x34, 0x34, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8 };
nrf_esb_config_t nrf_esb_config = NRF_ESB_LEGACY_CONFIG;
nrf_esb_config.payload_length = 18;
nrf_esb_config.protocol = NRF_ESB_PROTOCOL_ESB_DPL;
nrf_esb_config.bitrate = NRF_ESB_BITRATE_2MBPS;
nrf_esb_config.mode = NRF_ESB_MODE_PRX;
nrf_esb_config.event_handler = nrf_esb_event_handler;
nrf_esb_config.selective_auto_ack = true;
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);
err_code = nrf_esb_set_rf_channel(10);
VERIFY_SUCCESS(err_code);
return err_code;
}
int main(void)
{
uint32_t err_code;
gpio_init();
err_code = NRF_LOG_INIT(NULL);
APP_ERROR_CHECK(err_code);
NRF_LOG_DEFAULT_BACKENDS_INIT();
clocks_start();
err_code = esb_init();
APP_ERROR_CHECK(err_code);
NRF_LOG_DEBUG("Enhanced ShockBurst Receiver Example started.");
err_code = nrf_esb_start_rx();
APP_ERROR_CHECK(err_code);
while (true)
{
//if (NRF_LOG_PROCESS() == false)
{
// __WFE();
}
}
}
/*lint -restore */