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

Having problem for connection between nRF24l01+ and nRF51822

Hi. 

Hope you are well.

I want to send data from nRF51822 to nRF24L01+. I used the esb library to configure the nRF51 and I just change the settings as I want ( some settings such as RF channel, CRC, Data Rate &...). 

I use a STM32f103c8t6 micro-controller to configure nRF24l01+. I know that I am connecting with nRF24 via SPI because I am able to read the registers that I configure. all the necessary configurations that should be the same in both chips, are the same but the do not get connected.  in the following I will attach the main source code for both of the modules I am using.

 I will be happy to get some help.

here is the main code that I wrote for nRF24 configuartion 

 

/** NRF24L01 Congiguration
  ******************************************************************************
  * File Name          : main.c
  * Description        : Main program body
  ******************************************************************************
  *
  * COPYRIGHT(c) 2020 STMicroelectronics
  *
  * 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 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 STMicroelectronics nor the names of its contributors
  *      may be used to endorse or promote products derived from this software
  *      without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
  *
  ******************************************************************************
  */
/* Includes ------------------------------------------------------------------*/
#include "stm32f1xx_hal.h"

/* USER CODE BEGIN Includes */
#include <stdio.h>
/* USER CODE END Includes */

/* Private variables ---------------------------------------------------------*/
SPI_HandleTypeDef hspi2;

UART_HandleTypeDef huart2;
UART_HandleTypeDef huart3;
DMA_HandleTypeDef hdma_usart2_tx;

DMA_HandleTypeDef hdma_memtomem_dma1_channel1;

/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/

// opcode commands
const uint8_t R_REGISTER[]={0x00};
const uint8_t W_REGISTER[]={0x20};
const uint8_t R_RX_PAYLOAD[]={0x61};
const uint8_t W_TX_PAYLOAD[]={0xA0};
const uint8_t FLUSH_TX[]={0xE1};
const uint8_t FLUSH_RX[]={0xE2};
const uint8_t REUSE_TX_PL[]={0xE3};
const uint8_t R_RX_PL_WID[]={0x60};
const uint8_t W_ACK_PAYLOAD[]={0xA8};
const uint8_t W_TX_PAYLOAD_NOACK[]={0xB0};
const uint8_t NOP[]={0xFF};

// Register ADDRESSES

const uint8_t READ_CONFIG[]={0x00};
const uint8_t WRITE_CONFIG[]={0x20};
const uint8_t READ_EN_AA[]={0x01};
const uint8_t WRITE_EN_AA[]={0x21};
const uint8_t READ_EN_RXADDR[]={0x02};
const uint8_t WRITE_EN_RXADDR[]={0x22};
const uint8_t READ_SETUP_AW[]={0x03};
const uint8_t WRITE_SETUP_AW[]={0x23};
const uint8_t READ_SETUP_RETR[]={0x04};
const uint8_t WRITE_SETUP_RETR[]={0x24};
const uint8_t READ_RF_CH[]={0x05};
const uint8_t WRITE_RF_CH[]={0x25};
const uint8_t READ_RF_SETUP[]={0x06};
const uint8_t WRITE_RF_SETUP[]={0x26};
const uint8_t READ_STATUS[]={0x07};
const uint8_t WRITE_STATUS[]={0x27};
const uint8_t READ_OBSERVE_TX[]={0x08};
const uint8_t READ_PRD[]={0x09};
const uint8_t READ_RX_ADDR_P0[]={0x0A};
const uint8_t WRITE_RX_ADDR_P0[]={0x2A};
const uint8_t READ_RX_ADDR_P1[]={0x0B};
const uint8_t WRITE_RX_ADDR_P1[]={0x2B};
const uint8_t READ_RX_ADDR_P2[]={0x0C};
const uint8_t WRITE_RX_ADDR_P2[]={0x2C};
const uint8_t READ_RX_ADDR_P3[]={0x0D};
const uint8_t WRITE_RX_ADDR_P3[]={0x2D};
const uint8_t READ_RX_ADDR_P4[]={0x0E};
const uint8_t WRITE_RX_ADDR_P4[]={0x2E};
const uint8_t READ_RX_ADDR_P5[]={0x0F};
const uint8_t WRITE_RX_ADDR_P5[]={0x2F};
const uint8_t READ_TX_ADDR[]={0x10};
const uint8_t WRITE_TX_ADDR[]={0x30};
const uint8_t READ_RX_PW_P0[]={0x11};
const uint8_t WRITE_RX_PW_P0[]={0x31};
const uint8_t READ_RX_PW_P1[]={0x12};
const uint8_t WRITE_RX_PW_P1[]={0x32};
const uint8_t READ_RX_PW_P2[]={0x13};
const uint8_t WRITE_RX_PW_P2[]={0x33};
const uint8_t READ_RX_PW_P3[]={0x14};
const uint8_t WRITE_RX_PW_P3[]={0x34};
const uint8_t READ_RX_PW_P4[]={0x15};
const uint8_t WRITE_RX_PW_P4[]={0x35};
const uint8_t READ_RX_PW_P5[]={0x16};
const uint8_t WRITE_RX_PW_P5[]={0x36};
const uint8_t READ_FIFO_STATUS[]={0x17};
const uint8_t READ_DYNPD[]={0x1C};
const uint8_t WRITE_DYNPD[]={0x3C};
const uint8_t READ_FEATURE[]={0x1D};
const uint8_t WRITE_FEATURE[]={0x3D};

uint8_t Rxbuffer[]={0x00};
uint8_t num[]={0};
uint8_t buff[2]={0,0};
uint8_t zero[2]={0,0};
uint8_t header[3]={255,255,50};
const int RX_Mode=1;
const int TX_Mode=2;
uint8_t STATUS[]={0};

uint8_t CONFIG[]={0x0F}; // Rx mode = 0x0F  ; Tx mode = 0x0E
uint8_t EN_AA[]={0x3F}; // 
uint8_t EN_RXADDR[]={0x3F};
uint8_t SETUP_AW[]={0x02};
uint8_t SETUP_RETR[]={0x2F};
uint8_t RF_CH[]={0x0F};
uint8_t RF_SETUP[]={0x9F};
uint8_t DYNPD[]={0x3F};	
uint8_t FEATURE[]={0x07};
uint8_t RX_PW_P0[]={0x20};
uint8_t RX_PW_P1[]={0x20};
uint8_t RX_PW_P2[]={0x20};
uint8_t RX_PW_P3[]={0x20};
uint8_t RX_PW_P4[]={0x20};
uint8_t RX_PW_P5[]={0x20};
uint8_t STAT[]={0x7E};
//uint8_t RX_ADDR_P0[]={0xE7,0xE7,0xE7,0xE7,0xE7};
//
/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
void Error_Handler(void);
static void MX_GPIO_Init(void);
static void MX_DMA_Init(void);
static void MX_SPI2_Init(void);
static void MX_USART3_UART_Init(void);
static void MX_USART2_UART_Init(void);

/* USER CODE BEGIN PFP */
/* Private function prototypes -----------------------------------------------*/
void Send_command(uint8_t *opcode);
void Write_Register(uint8_t *ADDR, uint8_t *Data);
void Read_Register(uint8_t *ADDR, uint16_t num);
void NRF_Deinit(void);
void NRF_Init(void);
void Radio_up(void);
void Radio_down(void);
/* USER CODE END PFP */

/* USER CODE BEGIN 0 */
/******************************************************************************
	CS    	-->   GPIOA-8
	CE    	-->   GPIOA-9
	IRQ   	-->   GPIOB-12
	MISO  	-->   GPIOB-14
	MOSI  	-->   GPIOB-15
	SCK 		-->   GPIOB-13
	
	SWDIO 	-->		GPIOA-13
	SWDCLK 	-->		GPIOA-14
	
	LED1		--> 	GPIOA-15
	LED2		--> 	GPIOB-3
	LED3		--> 	GPIOB-4
	LED4		--> 	GPIOB-5
	LED5		--> 	GPIOB-6
	LED6		--> 	GPIOB-7
	
	LED7		--> 	GPIOA-5
	LED8		--> 	GPIOA-6
	LED9		--> 	GPIOA-7
	LED10		--> 	GPIOB-0
	LED11		--> 	GPIOB-1
	LED12		--> 	GPIOB-2
	
	UART3RX -->		GPIOB-11
	UART3TX --> 	GPIOB-12
	
	UART2RX -->		GPIOA-3
	UART2TX -->		GPIOA-2
	*******************************************************************************/
/* USER CODE END 0 */

int main(void)
{

  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_SPI2_Init();
  MX_USART3_UART_Init();
  MX_USART2_UART_Init();

  /* USER CODE BEGIN 2 */
//	HAL_MspInit();
	HAL_UART_MspInit(&huart2);
	HAL_SPI_MspInit(&hspi2);
	HAL_UART_MspInit(&huart3);
	NRF_Init();
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */
//		Radio_up();
		HAL_Delay(1000);
		HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7, GPIO_PIN_SET);
		HAL_Delay(1000);
		HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7, GPIO_PIN_RESET);
		Read_Register((uint8_t*)READ_FIFO_STATUS,1);
		HAL_UART_Transmit(&huart2,Rxbuffer,1,10);	
		Send_command((uint8_t*)R_RX_PAYLOAD);
		HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
		HAL_SPI_Receive(&hspi2,Rxbuffer,4,10);
		HAL_UART_Transmit(&huart2,Rxbuffer,4,10);	
		HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);
		Write_Register((uint8_t*) WRITE_STATUS,(uint8_t*) STAT);
  }
  /* USER CODE END 3 */

}

/** System Clock Configuration
*/
void SystemClock_Config(void)
{

  RCC_OscInitTypeDef RCC_OscInitStruct;
  RCC_ClkInitTypeDef RCC_ClkInitStruct;

  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = 16;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2;
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  {
    Error_Handler();
  }

  HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

  HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

  /* SysTick_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
}

/* SPI2 init function */
static void MX_SPI2_Init(void)
{

  hspi2.Instance = SPI2;
  hspi2.Init.Mode = SPI_MODE_MASTER;
  hspi2.Init.Direction = SPI_DIRECTION_2LINES;
  hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
  hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
  hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
  hspi2.Init.NSS = SPI_NSS_SOFT;
  hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4;
  hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
  hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
  hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  hspi2.Init.CRCPolynomial = 10;
  if (HAL_SPI_Init(&hspi2) != HAL_OK)
  {
    Error_Handler();
  }

}

/* USART2 init function */
static void MX_USART2_UART_Init(void)
{

  huart2.Instance = USART2;
  huart2.Init.BaudRate = 921600;
  huart2.Init.WordLength = UART_WORDLENGTH_8B;
  huart2.Init.StopBits = UART_STOPBITS_1;
  huart2.Init.Parity = UART_PARITY_NONE;
  huart2.Init.Mode = UART_MODE_TX_RX;
  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  if (HAL_UART_Init(&huart2) != HAL_OK)
  {
    Error_Handler();
  }

}

/* USART3 init function */
static void MX_USART3_UART_Init(void)
{

  huart3.Instance = USART3;
  huart3.Init.BaudRate = 921600;
  huart3.Init.WordLength = UART_WORDLENGTH_8B;
  huart3.Init.StopBits = UART_STOPBITS_1;
  huart3.Init.Parity = UART_PARITY_NONE;
  huart3.Init.Mode = UART_MODE_TX_RX;
  huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart3.Init.OverSampling = UART_OVERSAMPLING_16;
  if (HAL_UART_Init(&huart3) != HAL_OK)
  {
    Error_Handler();
  }

}

/** 
  * Enable DMA controller clock
  * Configure DMA for memory to memory transfers
  *   hdma_memtomem_dma1_channel1
  */
static void MX_DMA_Init(void) 
{
  /* DMA controller clock enable */
  __HAL_RCC_DMA1_CLK_ENABLE();

  /* Configure DMA request hdma_memtomem_dma1_channel1 on DMA1_Channel1 */
  hdma_memtomem_dma1_channel1.Instance = DMA1_Channel1;
  hdma_memtomem_dma1_channel1.Init.Direction = DMA_MEMORY_TO_MEMORY;
  hdma_memtomem_dma1_channel1.Init.PeriphInc = DMA_PINC_ENABLE;
  hdma_memtomem_dma1_channel1.Init.MemInc = DMA_MINC_ENABLE;
  hdma_memtomem_dma1_channel1.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
  hdma_memtomem_dma1_channel1.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
  hdma_memtomem_dma1_channel1.Init.Mode = DMA_NORMAL;
  hdma_memtomem_dma1_channel1.Init.Priority = DMA_PRIORITY_HIGH;
  if (HAL_DMA_Init(&hdma_memtomem_dma1_channel1) != HAL_OK)
  {
    Error_Handler();
  }
        
  

  /* DMA interrupt init */
  /* DMA1_Channel1_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 5, 0);
  HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn);
  /* DMA1_Channel7_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(DMA1_Channel7_IRQn, 5, 0);
  HAL_NVIC_EnableIRQ(DMA1_Channel7_IRQn);

}

/** Configure pins as 
        * Analog 
        * Input 
        * Output
        * EVENT_OUT
        * EXTI
*/
static void MX_GPIO_Init(void)
{

  GPIO_InitTypeDef GPIO_InitStruct;

  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOA_CLK_ENABLE();
  __HAL_RCC_GPIOB_CLK_ENABLE();

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8 
                          |GPIO_PIN_9|GPIO_PIN_15, GPIO_PIN_RESET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3 
                          |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7, GPIO_PIN_RESET);

  /*Configure GPIO pins : PA5 PA6 PA7 PA15 */
  GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_15;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /*Configure GPIO pins : PB0 PB1 PB2 PB3 
                           PB4 PB5 PB6 PB7 */
  GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3 
                          |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  /*Configure GPIO pin : PB12 */
  GPIO_InitStruct.Pin = GPIO_PIN_12;
  GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  /*Configure GPIO pins : PA8 PA9 */
  GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /* EXTI interrupt init*/
  HAL_NVIC_SetPriority(EXTI15_10_IRQn, 5, 0);
  HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);

}

/* USER CODE BEGIN 4 */

/*Write register function*/
void Write_Register(uint8_t *ADDR, uint8_t *Data)
{
	/*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
	HAL_SPI_TransmitReceive(&hspi2,ADDR,STATUS,1,10);
	HAL_SPI_Transmit(&hspi2,Data,1,10);
  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);	
}

/*Read register function*/
void Read_Register(uint8_t *ADDR, uint16_t num)
{
	/*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
	HAL_SPI_TransmitReceive(&hspi2,ADDR,STATUS,1,10);
	HAL_SPI_Receive(&hspi2,Rxbuffer,num,10);
  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);
}

/*Send commands to NRF24L01+ function*/
void Send_command(uint8_t *opcode)
{
	/*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
	HAL_SPI_TransmitReceive(&hspi2,opcode,STATUS,1,10);
  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);
}
void Radio_up(void)
{
	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, GPIO_PIN_SET);
}
void Radio_down(void)
{
	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, GPIO_PIN_RESET);
}

/*initialize NRF24L01+ function*/
void NRF_Init(void)
{
	NRF_Deinit();
	Radio_down();
	Write_Register((uint8_t*)WRITE_CONFIG,(uint8_t*)CONFIG);
	Write_Register((uint8_t*)WRITE_EN_AA,(uint8_t*)EN_AA);
	Write_Register((uint8_t*)WRITE_EN_RXADDR,(uint8_t*)EN_RXADDR);
	Write_Register((uint8_t*)WRITE_SETUP_AW,(uint8_t*)SETUP_AW);
	Write_Register((uint8_t*)WRITE_SETUP_RETR,(uint8_t*)SETUP_RETR);
	Write_Register((uint8_t*)WRITE_RF_CH,(uint8_t*)RF_CH);
	Write_Register((uint8_t*)WRITE_RF_SETUP,(uint8_t*)RF_SETUP);
	Write_Register((uint8_t*)WRITE_RX_PW_P0,(uint8_t*)RX_PW_P0);
	Write_Register((uint8_t*)WRITE_RX_PW_P1,(uint8_t*)RX_PW_P1);
	Write_Register((uint8_t*)WRITE_RX_PW_P2,(uint8_t*)RX_PW_P2);
	Write_Register((uint8_t*)WRITE_RX_PW_P3,(uint8_t*)RX_PW_P3);
	Write_Register((uint8_t*)WRITE_RX_PW_P4,(uint8_t*)RX_PW_P4);
	Write_Register((uint8_t*)WRITE_RX_PW_P5,(uint8_t*)RX_PW_P5);

	Write_Register((uint8_t*)WRITE_DYNPD,(uint8_t*)DYNPD);
	Write_Register((uint8_t*)WRITE_FEATURE,(uint8_t*)FEATURE);
	Radio_up();
}

void NRF_Deinit(void)
{
	Radio_down();
	Write_Register((uint8_t*)WRITE_CONFIG,0x00);
	Write_Register((uint8_t*)WRITE_EN_RXADDR,0x00);
	Write_Register((uint8_t*)WRITE_SETUP_RETR,0x00);
	Write_Register((uint8_t*)WRITE_RF_CH,(uint8_t*)0x02);
	Write_Register((uint8_t*)WRITE_EN_AA,0x00);
	Write_Register((uint8_t*)WRITE_RF_SETUP,(uint8_t*)0x0E);
	Write_Register((uint8_t*)WRITE_DYNPD,0x00);
	Write_Register((uint8_t*)WRITE_FEATURE,0x00);
	Radio_up();
	Send_command((uint8_t*)FLUSH_TX);
	Send_command((uint8_t*)FLUSH_RX);
}

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
	if(GPIO_Pin == GPIO_PIN_12)
	{
//		HAL_GPIO_WritePin(GPIOA,GPIO_PIN_8, GPIO_PIN_RESET);
//		HAL_SPI_TransmitReceive(&hspi2,zero,Rxbuffer,3,10);
//		HAL_SPI_TransmitReceive(&hspi2,zero,buff,24,10);
//		HAL_UART_Transmit(&huart2,header,3,10);
//		HAL_UART_Transmit(&huart2,buff,24,10);
//		HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);
		HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);
	}
}


/* USER CODE END 4 */

/**
  * @brief  This function is executed in case of error occurrence.
  * @param  None
  * @retval None
  */
void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler */
  /* User can add his own implementation to report the HAL error return state */
  while(1) 
  {
  }
  /* USER CODE END Error_Handler */ 
}

#ifdef USE_FULL_ASSERT

/**
   * @brief Reports the name of the source file and the source line number
   * where the assert_param error has occurred.
   * @param file: pointer to the source file name
   * @param line: assert_param error line source number
   * @retval None
   */
void assert_failed(uint8_t* file, uint32_t line)
{
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
    ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */

}

#endif

/**
  * @}
  */ 

/**
  * @}
*/ 

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

here is the main.c file from esb library with my little changes 

/**ESB_PTX main.c
 * Copyright (c) 2014 - 2017, 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 <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "sdk_common.h"
#include "nrf.h"
#include "nrf_esb.h"
#include "nrf_error.h"
#include "nrf_esb_error_codes.h"
#include "nrf_delay.h"
#include "nrf_gpio.h"
#include "boards.h"
#include "nrf_delay.h"
#include "app_util.h"
#define NRF_LOG_MODULE_NAME "APP"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"

static nrf_esb_payload_t        tx_payload = NRF_ESB_CREATE_PAYLOAD(0, 0x01, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00);

static 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)
{
    switch (p_event->evt_id)
    {
        case NRF_ESB_EVENT_TX_SUCCESS:
            NRF_LOG_DEBUG("TX SUCCESS EVENT\r\n");
            break;
        case NRF_ESB_EVENT_TX_FAILED:
            NRF_LOG_DEBUG("TX FAILED EVENT\r\n");
            (void) nrf_esb_flush_tx();
            (void) nrf_esb_start_tx();
            break;
        case NRF_ESB_EVENT_RX_RECEIVED:
            NRF_LOG_DEBUG("RX RECEIVED EVENT\r\n");
            while (nrf_esb_read_rx_payload(&rx_payload) == NRF_SUCCESS)
            {
                if (rx_payload.length > 0)
                {
                    NRF_LOG_DEBUG("RX RECEIVED PAYLOAD\r\n");
                }
            }
            break;
    }
    NRF_GPIO->OUTCLR = 0xFUL << 12;
    NRF_GPIO->OUTSET = (p_event->tx_attempts & 0x0F) << 12;
}


void clocks_start( void )
{
    NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
    NRF_CLOCK->TASKS_HFCLKSTART = 1;

    while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0);
}


void gpio_init( void )
{
    nrf_gpio_range_cfg_output(8, 15);
    bsp_board_leds_init();
}


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;
    nrf_esb_config.protocol                 = NRF_ESB_PROTOCOL_ESB_DPL;
    nrf_esb_config.retransmit_delay         = 750;
    nrf_esb_config.bitrate                  = NRF_ESB_BITRATE_2MBPS;
    nrf_esb_config.event_handler            = nrf_esb_event_handler;
    nrf_esb_config.mode                     = NRF_ESB_MODE_PTX;
    nrf_esb_config.selective_auto_ack       = false; 
		
		nrf_esb_set_rf_channel((uint32_t) 0);
		
    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;
}


int main(void)
{
	
	ret_code_t err_code;

    gpio_init();

    err_code = NRF_LOG_INIT(NULL);
    APP_ERROR_CHECK(err_code);

    clocks_start();
	
    err_code = esb_init();
    APP_ERROR_CHECK(err_code);

    bsp_board_leds_init();

    NRF_LOG_DEBUG("Enhanced ShockBurst Transmitter Example running.\r\n");

    while (true)
    {
        NRF_LOG_DEBUG("Transmitting packet %02x\r\n", tx_payload.data[1]);

        tx_payload.noack = false;
        if (nrf_esb_write_payload(&tx_payload) == NRF_SUCCESS)
        {
            // Toggle one of the LEDs.
            nrf_gpio_pin_write(LED_1, !(tx_payload.data[1]%8>0 && tx_payload.data[1]%8<=4));
            nrf_gpio_pin_write(LED_2, !(tx_payload.data[1]%8>1 && tx_payload.data[1]%8<=5));
            nrf_gpio_pin_write(LED_3, !(tx_payload.data[1]%8>2 && tx_payload.data[1]%8<=6));
            nrf_gpio_pin_write(LED_4, !(tx_payload.data[1]%8>3));
            tx_payload.data[1]++;
        }
        else
        {
            NRF_LOG_WARNING("Sending packet failed\r\n");
        }

        nrf_delay_us(50000);
    }
}
/*lint -restore */

here is the nrf_esb.h

/**
 * Copyright (c) 2016 - 2017, 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.
 * 
 */

#ifndef __NRF_ESB_H
#define __NRF_ESB_H

#include <stdbool.h>
#include <stdint.h>
#include "nrf.h"
#include "app_util.h"

#ifdef __cplusplus
extern "C" {
#endif

/** @defgroup nrf_esb Enhanced ShockBurst
 * @{
 * @ingroup proprietary_api
 *
 * @brief Enhanced ShockBurst (ESB) is a basic protocol that supports two-way data
 *        packet communication including packet buffering, packet acknowledgment,
 *        and automatic retransmission of lost packets.
 */

#define DEBUGPIN1   12
#define DEBUGPIN2   13
#define DEBUGPIN3   14
#define DEBUGPIN4   15


#ifdef  NRF_ESB_DEBUG
#define DEBUG_PIN_SET(a)    (NRF_GPIO->OUTSET = (1 << (a)))
#define DEBUG_PIN_CLR(a)    (NRF_GPIO->OUTCLR = (1 << (a)))
#else
#define DEBUG_PIN_SET(a)
#define DEBUG_PIN_CLR(a)
#endif


// Hardcoded parameters - change if necessary
#ifndef NRF_ESB_MAX_PAYLOAD_LENGTH
#define     NRF_ESB_MAX_PAYLOAD_LENGTH          32                  /**< The maximum size of the payload. Valid values are 1 to 252. */
#endif

#define     NRF_ESB_TX_FIFO_SIZE                8                   /**< The size of the transmission first-in, first-out buffer. */
#define     NRF_ESB_RX_FIFO_SIZE                8                   /**< The size of the reception first-in, first-out buffer. */

// 252 is the largest possible payload size according to the nRF5 architecture.
STATIC_ASSERT(NRF_ESB_MAX_PAYLOAD_LENGTH <= 252);

#define     NRF_ESB_SYS_TIMER                   NRF_TIMER2          /**< The timer that is used by the module. */
#define     NRF_ESB_SYS_TIMER_IRQ_Handler       TIMER2_IRQHandler   /**< The handler that is used by @ref NRF_ESB_SYS_TIMER. */

#define     NRF_ESB_PPI_TIMER_START             10                  /**< The PPI channel used for timer start. */
#define     NRF_ESB_PPI_TIMER_STOP              11                  /**< The PPI channel used for timer stop. */
#define     NRF_ESB_PPI_RX_TIMEOUT              12                  /**< The PPI channel used for RX time-out. */
#define     NRF_ESB_PPI_TX_START                13                  /**< The PPI channel used for starting TX. */

// Interrupt flags
#define     NRF_ESB_INT_TX_SUCCESS_MSK          0x01                /**< The flag used to indicate a success since the last event. */
#define     NRF_ESB_INT_TX_FAILED_MSK           0x02                /**< The flag used to indicate a failure since the last event. */
#define     NRF_ESB_INT_RX_DR_MSK               0x04                /**< The flag used to indicate that a packet was received since the last event. */

#define     NRF_ESB_PID_RESET_VALUE             0xFF                /**< Invalid PID value that is guaranteed to not collide with any valid PID value. */
#define     NRF_ESB_PID_MAX                     3                   /**< The maximum value for PID. */
#define     NRF_ESB_CRC_RESET_VALUE             0xFFFF              /**< The CRC reset value. */

#define ESB_EVT_IRQ        SWI0_IRQn                                /**< The ESB event IRQ number when running on an nRF5x device. */
#define ESB_EVT_IRQHandler SWI0_IRQHandler                          /**< The handler for @ref ESB_EVT_IRQ when running on an nRF5x device. */

/** Default address configuration for ESB. Roughly equal to the nRF24Lxx default (except for the number of pipes, because more pipes are supported). */
#define NRF_ESB_ADDR_DEFAULT                                                    \
{                                                                               \
    .base_addr_p0       = {0xE7, 0xE7, 0xE7, 0xE7 },                           \
    .base_addr_p1       = {0xC2, 0xC2, 0xC2, 0xC2 },                           \
    .pipe_prefixes      = { 0xE7, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8 },   \
    .addr_length        = 4,                                                    \
    .num_pipes          = 1,                                                    \
    .rf_channel         = 0x0F,                                                    \
    .rx_pipes_enabled   = 0xFF                                                  \
}


/** Default radio parameters. Roughly equal to the nRF24Lxx default parameters (except for CRC, which is set to 16 bit, and protocol, which is set to DPL). */
#define NRF_ESB_DEFAULT_CONFIG {.protocol               = NRF_ESB_PROTOCOL_ESB_DPL,         \
                                .mode                   = NRF_ESB_MODE_PTX,                 \
                                .event_handler          = 0,                                \
                                .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         = 32,                               \
                                .selective_auto_ack     = false																	\
}


/** Default legacy radio parameters, identical to the nRF24Lxx defaults. */
#define NRF_ESB_LEGACY_CONFIG  {.protocol               = NRF_ESB_PROTOCOL_ESB,             \
                                .mode                   = NRF_ESB_MODE_PTX,                 \
                                .event_handler          = 0,                                \
                                .bitrate                = NRF_ESB_BITRATE_2MBPS,            \
                                .crc                    = NRF_ESB_CRC_8BIT,                 \
                                .tx_output_power        = NRF_ESB_TX_POWER_0DBM,            \
                                .retransmit_delay       = 600,                              \
                                .retransmit_count       = 3,                                \
                                .tx_mode                = NRF_ESB_TXMODE_AUTO,              \
                                .radio_irq_priority     = 1,                                \
                                .event_irq_priority     = 2,                                \
                                .payload_length         = 32,                               \
                                .selective_auto_ack     = false                             \
}


/**Macro to create an initializer for a TX data packet.
 *
 * @details This macro generates an initializer. Using the initializer is more efficient
 *          than setting the individual parameters dynamically.
 *
 * @param[in]   _pipe   The pipe to use for the data packet.
 * @param[in]   ...     Comma separated list of character data to put in the TX buffer.
 *                      Supported values consist of 1 to 63 characters.
 *
 * @return  Initializer that sets up the pipe, length, and byte array for content of the TX data.
 */
#define NRF_ESB_CREATE_PAYLOAD(_pipe, ...)                                                  \
        {.pipe = _pipe, .length = NUM_VA_ARGS(__VA_ARGS__), .data = {__VA_ARGS__}};         \
        STATIC_ASSERT(NUM_VA_ARGS(__VA_ARGS__) > 0 && NUM_VA_ARGS(__VA_ARGS__) <= 63)


/**@brief Enhanced ShockBurst protocols. */
typedef enum {
    NRF_ESB_PROTOCOL_ESB,      /*< Enhanced ShockBurst with fixed payload length.                                            */
    NRF_ESB_PROTOCOL_ESB_DPL   /*< Enhanced ShockBurst with dynamic payload length.                                          */
} nrf_esb_protocol_t;


/**@brief Enhanced ShockBurst modes. */
typedef enum {
    NRF_ESB_MODE_PTX,          /*< Primary transmitter mode. */
    NRF_ESB_MODE_PRX           /*< Primary receiver mode.    */
} nrf_esb_mode_t;


/**@brief Enhanced ShockBurst bitrate modes. */
typedef enum {
    NRF_ESB_BITRATE_2MBPS     = RADIO_MODE_MODE_Nrf_2Mbit,      /**< 2 Mb radio mode.                                                */
    NRF_ESB_BITRATE_1MBPS     = RADIO_MODE_MODE_Nrf_1Mbit,      /**< 1 Mb radio mode.                                                */
    NRF_ESB_BITRATE_250KBPS   = RADIO_MODE_MODE_Nrf_250Kbit,    /**< 250 Kb radio mode.                                              */
    NRF_ESB_BITRATE_1MBPS_BLE = RADIO_MODE_MODE_Ble_1Mbit       /**< 1 Mb radio mode using @e Bluetooth low energy radio parameters. */
} nrf_esb_bitrate_t;


/**@brief Enhanced ShockBurst CRC modes. */
typedef enum {
    NRF_ESB_CRC_16BIT = RADIO_CRCCNF_LEN_Two,                   /**< Use two-byte CRC. */
    NRF_ESB_CRC_8BIT  = RADIO_CRCCNF_LEN_One,                   /**< Use one-byte CRC. */
    NRF_ESB_CRC_OFF   = RADIO_CRCCNF_LEN_Disabled               /**< Disable CRC.      */
} nrf_esb_crc_t;


/**@brief Enhanced ShockBurst radio transmission power modes. */
typedef enum {
    NRF_ESB_TX_POWER_4DBM     = RADIO_TXPOWER_TXPOWER_Pos4dBm,  /**< 4 dBm radio transmit power.   */
    NRF_ESB_TX_POWER_0DBM     = RADIO_TXPOWER_TXPOWER_0dBm,     /**< 0 dBm radio transmit power.   */
    NRF_ESB_TX_POWER_NEG4DBM  = RADIO_TXPOWER_TXPOWER_Neg4dBm,  /**< -4 dBm radio transmit power.  */
    NRF_ESB_TX_POWER_NEG8DBM  = RADIO_TXPOWER_TXPOWER_Neg8dBm,  /**< -8 dBm radio transmit power.  */
    NRF_ESB_TX_POWER_NEG12DBM = RADIO_TXPOWER_TXPOWER_Neg12dBm, /**< -12 dBm radio transmit power. */
    NRF_ESB_TX_POWER_NEG16DBM = RADIO_TXPOWER_TXPOWER_Neg16dBm, /**< -16 dBm radio transmit power. */
    NRF_ESB_TX_POWER_NEG20DBM = RADIO_TXPOWER_TXPOWER_Neg20dBm, /**< -20 dBm radio transmit power. */
    NRF_ESB_TX_POWER_NEG30DBM = RADIO_TXPOWER_TXPOWER_Neg30dBm  /**< -30 dBm radio transmit power. */
} nrf_esb_tx_power_t;


/**@brief Enhanced ShockBurst transmission modes. */
typedef enum {
    NRF_ESB_TXMODE_AUTO,        /*< Automatic TX mode: When the TX FIFO contains packets and the radio is idle, packets are sent automatically. */
    NRF_ESB_TXMODE_MANUAL,      /*< Manual TX mode: Packets are not sent until @ref nrf_esb_start_tx is called. This mode can be used to ensure consistent packet timing. */
    NRF_ESB_TXMODE_MANUAL_START /*< Manual start TX mode: Packets are not sent until @ref nrf_esb_start_tx is called. Then, transmission continues automatically until the TX FIFO is empty. */
} nrf_esb_tx_mode_t;


/**@brief Enhanced ShockBurst event IDs used to indicate the type of the event. */
typedef enum
{
    NRF_ESB_EVENT_TX_SUCCESS,   /**< Event triggered on TX success.     */
    NRF_ESB_EVENT_TX_FAILED,    /**< Event triggered on TX failure.     */
    NRF_ESB_EVENT_RX_RECEIVED   /**< Event triggered on RX received.    */
} nrf_esb_evt_id_t;


/**@brief Enhanced ShockBurst payload.
 *
 * @details The payload is used both for transmissions and for acknowledging a
 *          received packet with a payload.
*/
typedef struct
{
    uint8_t length;                                 /**< Length of the packet (maximum value is NRF_ESB_MAX_PAYLOAD_LENGTH). */
    uint8_t pipe;                                   /**< Pipe used for this payload. */
    int8_t  rssi;                                   /**< RSSI for the received packet. */
    uint8_t noack;                                  /**< Flag indicating that this packet will not be acknowledged. */
    uint8_t pid;                                    /**< PID assigned during communication. */
    uint8_t data[NRF_ESB_MAX_PAYLOAD_LENGTH];       /**< The payload data. */
} nrf_esb_payload_t;


/**@brief Enhanced ShockBurst event. */
typedef struct
{
    nrf_esb_evt_id_t    evt_id;                     /**< Enhanced ShockBurst event ID. */
    uint32_t            tx_attempts;                /**< Number of TX retransmission attempts. */
} nrf_esb_evt_t;


/**@brief Definition of the event handler for the module. */
typedef void (* nrf_esb_event_handler_t)(nrf_esb_evt_t const * p_event);


/**@brief Main configuration structure for the module. */
typedef struct
{
    nrf_esb_protocol_t      protocol;               /**< Enhanced ShockBurst protocol. */
    nrf_esb_mode_t          mode;                   /**< Enhanced ShockBurst mode. */
    nrf_esb_event_handler_t event_handler;          /**< Enhanced ShockBurst event handler. */

    // General RF parameters
    nrf_esb_bitrate_t       bitrate;                /**< Enhanced ShockBurst bitrate mode. */
    nrf_esb_crc_t           crc;                    /**< Enhanced ShockBurst CRC modes. */

    nrf_esb_tx_power_t      tx_output_power;        /**< Enhanced ShockBurst radio transmission power mode.*/

    uint16_t                retransmit_delay;       /**< The delay between each retransmission of unacknowledged packets. */
    uint16_t                retransmit_count;       /**< The number of retransmissions attempts before transmission fail. */

    // Control settings
    nrf_esb_tx_mode_t       tx_mode;                /**< Enhanced ShockBurst transmission mode. */

    uint8_t                 radio_irq_priority;     /**< nRF radio interrupt priority. */
    uint8_t                 event_irq_priority;     /**< ESB event interrupt priority. */
    uint8_t                 payload_length;         /**< Length of the payload (maximum length depends on the platforms that are used on each side). */

    bool                    selective_auto_ack;     /**< Enable or disable selective auto acknowledgment. */
} nrf_esb_config_t;


/**@brief Function for initializing the Enhanced ShockBurst module.
 *
 * @param  p_config     Parameters for initializing the module.
 *
 * @retval  NRF_SUCCESS             If initialization was successful.
 * @retval  NRF_ERROR_NULL          If the @p p_config argument was NULL.
 * @retval  NRF_ERROR_BUSY          If the function failed because the radio is busy.
 */
uint32_t nrf_esb_init(nrf_esb_config_t const * p_config);


/**@brief Function for suspending the Enhanced ShockBurst module.
 *
 * Calling this function stops ongoing communications without changing the queues.
 *
 * @retval  NRF_SUCCESS             If Enhanced ShockBurst was suspended.
 * @retval  NRF_ERROR_BUSY          If the function failed because the radio is busy.
 */
uint32_t nrf_esb_suspend(void);


/**@brief Function for disabling the Enhanced ShockBurst module.
 *
 * Calling this function disables the Enhanced ShockBurst module immediately.
 * Doing so might stop ongoing communications.
 *
 * @note All queues are flushed by this function.
 *
 * @retval  NRF_SUCCESS             If Enhanced ShockBurst was disabled.
 */
uint32_t nrf_esb_disable(void);


/**@brief Function for checking if the Enhanced ShockBurst module is idle.
 *
 * @retval true                     If the module is idle.
 * @retval false                    If the module is busy.
 */
bool nrf_esb_is_idle(void);


/**@brief Function for writing a payload for transmission or acknowledgment.
 *
 * This function writes a payload that is added to the queue. When the module is in PTX mode, the
 * payload is queued for a regular transmission. When the module is in PRX mode, the payload
 * is queued for when a packet is received that requires an acknowledgment with payload.
 *
 * @param[in]   p_payload     Pointer to the structure that contains information and state of the payload.
 *
 * @retval  NRF_SUCCESS                     If the payload was successfully queued for writing.
 * @retval  NRF_ERROR_NULL                  If the required parameter was NULL.
 * @retval  NRF_INVALID_STATE               If the module is not initialized.
 * @retval  NRF_ERROR_NOT_SUPPORTED         If @p p_payload->noack was false, but selective acknowledgment is not enabled.
 * @retval  NRF_ERROR_NO_MEM                If the TX FIFO is full.
 * @retval  NRF_ERROR_INVALID_LENGTH        If the payload length was invalid (zero or larger than the allowed maximum).
 */
uint32_t nrf_esb_write_payload(nrf_esb_payload_t const * p_payload);


/**@brief Function for reading an RX payload.
 *
 * @param[in,out]   p_payload   Pointer to the structure that contains information and state of the payload.
 *
 * @retval  NRF_SUCCESS                     If the data was read successfully.
 * @retval  NRF_ERROR_NULL                  If the required parameter was NULL.
 * @retval  NRF_INVALID_STATE               If the module is not initialized.
 */
uint32_t nrf_esb_read_rx_payload(nrf_esb_payload_t * p_payload);


/**@brief Function for starting transmission.
 *
 * @retval  NRF_SUCCESS                     If the TX started successfully.
 * @retval  NRF_ERROR_BUFFER_EMPTY          If the TX does not start because the FIFO buffer is empty.
 * @retval  NRF_ERROR_BUSY                  If the function failed because the radio is busy.
 */
uint32_t nrf_esb_start_tx(void);


/**@brief Function for starting to transmit data from the FIFO buffer.
 *
 * @retval  NRF_SUCCESS                     If the transmission was started successfully.
 * @retval  NRF_ERROR_BUSY                  If the function failed because the radio is busy.
 */
uint32_t nrf_esb_start_rx(void);


/** @brief Function for stopping data reception.
 *
 * @retval  NRF_SUCCESS                     If data reception was stopped successfully.
 * @retval  NRF_ESB_ERROR_NOT_IN_RX_MODE    If the function failed because the module is not in RX mode.
 */
uint32_t nrf_esb_stop_rx(void);


/**@brief Function for removing remaining items from the TX buffer.
 *
 * This function clears the TX FIFO buffer.
 *
 * @retval  NRF_SUCCESS                     If pending items in the TX buffer were successfully cleared.
 * @retval  NRF_INVALID_STATE               If the module is not initialized.
 */
uint32_t nrf_esb_flush_tx(void);


/**@brief Function for removing the first item from the TX buffer.
 *
 * @retval  NRF_SUCCESS                     If the operation completed successfully.
 * @retval  NRF_INVALID_STATE               If the module is not initialized.
 * @retval  NRF_ERROR_BUFFER_EMPTY          If there are no items in the queue to remove.
 */
uint32_t nrf_esb_pop_tx(void);


/**@brief Function for removing remaining items from the RX buffer.
 *
 * @retval  NRF_SUCCESS                     If the pending items in the RX buffer were successfully cleared.
 * @retval  NRF_INVALID_STATE               If the module is not initialized.
 */
uint32_t nrf_esb_flush_rx(void);



/**@brief Function for setting the length of the address.
 *
 * @param[in]       length              Length of the ESB address (in bytes).
 *
 * @retval  NRF_SUCCESS                      If the address length was set successfully.
 * @retval  NRF_ERROR_INVALID_PARAM          If the address length was invalid.
 * @retval  NRF_ERROR_BUSY                   If the function failed because the radio is busy.
 */
uint32_t nrf_esb_set_address_length(uint8_t length);


/**@brief Function for setting the base address for pipe 0.
 *
 * @param[in]       p_addr      Pointer to the address data.
 *
 * @retval  NRF_SUCCESS                     If the base address was set successfully.
 * @retval  NRF_ERROR_BUSY                  If the function failed because the radio is busy.
 * @retval  NRF_ERROR_NULL                  If the required parameter was NULL.
 */
uint32_t nrf_esb_set_base_address_0(uint8_t const * p_addr);


/**@brief Function for setting the base address for pipe 1 to pipe 7.
 *
 * @param[in]       p_addr      Pointer to the address data.
 *
 * @retval  NRF_SUCCESS                     If the base address was set successfully.
 * @retval  NRF_ERROR_BUSY                  If the function failed because the radio is busy.
 * @retval  NRF_ERROR_NULL                  If the required parameter was NULL.
 */
uint32_t nrf_esb_set_base_address_1(uint8_t const * p_addr);


/**@brief Function for setting the number of pipes and the pipe prefix addresses.
 *
 * This function configures the number of available pipes, enables the pipes,
 * and sets their prefix addresses.
 *
 * @param[in]   p_prefixes      Pointer to a char array that contains the prefix for each pipe.
 * @param[in]   num_pipes       Number of pipes.
 *
 * @retval  NRF_SUCCESS                     If the prefix addresses were set successfully.
 * @retval  NRF_ERROR_BUSY                  If the function failed because the radio is busy.
 * @retval  NRF_ERROR_NULL                  If a required parameter was NULL.
 * @retval  NRF_ERROR_INVALID_PARAM         If an invalid number of pipes was given.
 */
uint32_t nrf_esb_set_prefixes(uint8_t const * p_prefixes, uint8_t num_pipes);


/**@brief Function for enabling pipes.
 *
 * The @p enable_mask parameter must contain the same number of pipes as has been configured
 * with @ref nrf_esb_set_prefixes.
 *
 * @param   enable_mask         Bitfield mask to enable or disable pipes. Setting a bit to
 *                              0 disables the pipe. Setting a bit to 1 enables the pipe.
 *
 * @retval  NRF_SUCCESS                     If the pipes were enabled and disabled successfully.
 * @retval  NRF_ERROR_BUSY                  If the function failed because the radio is busy.
 */
uint32_t nrf_esb_enable_pipes(uint8_t enable_mask);


/**@brief Function for updating the prefix for a pipe.
 *
 * @param   pipe    Pipe for which to set the prefix.
 * @param   prefix  Prefix to set for the pipe.
 *
 * @retval  NRF_SUCCESS                         If the operation completed successfully.
 * @retval  NRF_ERROR_BUSY                      If the function failed because the radio is busy.
 * @retval  NRF_ERROR_INVALID_PARAM             If the given pipe number was invalid.
 */
uint32_t nrf_esb_update_prefix(uint8_t pipe, uint8_t prefix);


/** @brief Function for setting the channel to use for the radio.
 *
 * The module must be in an idle state to call this function. As a PTX, the
 * application must wait for an idle state and as a PRX, the application must stop RX
 * before changing the channel. After changing the channel, operation can be resumed.
 *
 * @param[in]   channel                         Channel to use for radio.
 *
 * @retval  NRF_SUCCESS                         If the operation completed successfully.
 * @retval  NRF_INVALID_STATE                   If the module is not initialized.
 * @retval  NRF_ERROR_BUSY                      If the module was not in idle state.
 * @retval  NRF_ERROR_INVALID_PARAM             If the channel is invalid (larger than 125).
 */
uint32_t nrf_esb_set_rf_channel(uint32_t channel);


/**@brief Function for getting the current radio channel.
 *
 * @param[in, out] p_channel    Pointer to the channel data.
 *
 * @retval  NRF_SUCCESS                         If the operation completed successfully.
 * @retval  NRF_ERROR_NULL                      If the required parameter was NULL.
 */
uint32_t nrf_esb_rf_channel_get(uint32_t * p_channel);


/**@brief Function for setting the radio output power.
 *
 * @param[in]   tx_output_power    Output power.
 *
 * @retval  NRF_SUCCESS                         If the operation completed successfully.
 * @retval  NRF_ERROR_BUSY                      If the function failed because the radio is busy.
 */
uint32_t nrf_esb_set_tx_power(nrf_esb_tx_power_t tx_output_power);

/** @} */

#ifdef __cplusplus
}
#endif

#endif // NRF_ESB

  • Hi,

    Did you read the documentation for Backward compatibility and did you enable legacy support (#define NRF_ESB_LEGACY)?

  • I am not using the low power libraries in ESB. I am using esb_ptx. in this example we use NRF_ESB_DEFAULT. 

  • The difference between the Legacy and default define is dynamic payload and the length of the CRC. Did you check that these are the same on both ends?

  • yes I checked that. Since I am using nRF24L01+ not the nRF24E/U , and it doesn't have an internal micro I can use nrf sdk go library. I write the code below for nRF24L01+. 

    I don't know what's the problem I checked everything so many times but still the two don't connect. 

    /**
      ******************************************************************************
      * File Name          : main.c
      * Description        : Main program body
      ******************************************************************************
      *
      * COPYRIGHT(c) 2020 STMicroelectronics
      *
      * 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 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 STMicroelectronics nor the names of its contributors
      *      may be used to endorse or promote products derived from this software
      *      without specific prior written permission.
      *
      * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
      * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
      * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
      * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
      *
      ******************************************************************************
      */
    /* Includes ------------------------------------------------------------------*/
    #include "stm32f1xx_hal.h"
    
    /* USER CODE BEGIN Includes */
    #include <stdio.h>
    /* USER CODE END Includes */
    
    /* Private variables ---------------------------------------------------------*/
    SPI_HandleTypeDef hspi2;
    
    UART_HandleTypeDef huart2;
    UART_HandleTypeDef huart3;
    DMA_HandleTypeDef hdma_usart2_tx;
    
    DMA_HandleTypeDef hdma_memtomem_dma1_channel1;
    
    /* USER CODE BEGIN PV */
    /* Private variables ---------------------------------------------------------*/
    
    // opcode commands
    const uint8_t R_REGISTER[]={0x00};
    const uint8_t W_REGISTER[]={0x20};
    const uint8_t R_RX_PAYLOAD[]={0x61};
    const uint8_t W_TX_PAYLOAD[]={0xA0};
    const uint8_t FLUSH_TX[]={0xE1};
    const uint8_t FLUSH_RX[]={0xE2};
    const uint8_t REUSE_TX_PL[]={0xE3};
    const uint8_t R_RX_PL_WID[]={0x60};
    const uint8_t W_ACK_PAYLOAD[]={0xA8};
    const uint8_t W_TX_PAYLOAD_NOACK[]={0xB0};
    const uint8_t NOP[]={0xFF};
    
    // Register ADDRESSES
    
    const uint8_t READ_CONFIG[]={0x00};
    const uint8_t WRITE_CONFIG[]={0x20};
    const uint8_t READ_EN_AA[]={0x01};
    const uint8_t WRITE_EN_AA[]={0x21};
    const uint8_t READ_EN_RXADDR[]={0x02};
    const uint8_t WRITE_EN_RXADDR[]={0x22};
    const uint8_t READ_SETUP_AW[]={0x03};
    const uint8_t WRITE_SETUP_AW[]={0x23};
    const uint8_t READ_SETUP_RETR[]={0x04};
    const uint8_t WRITE_SETUP_RETR[]={0x24};
    const uint8_t READ_RF_CH[]={0x05};
    const uint8_t WRITE_RF_CH[]={0x25};
    const uint8_t READ_RF_SETUP[]={0x06};
    const uint8_t WRITE_RF_SETUP[]={0x26};
    const uint8_t READ_STATUS[]={0x07};
    const uint8_t WRITE_STATUS[]={0x27};
    const uint8_t READ_OBSERVE_TX[]={0x08};
    const uint8_t READ_PRD[]={0x09};
    const uint8_t READ_RX_ADDR_P0[]={0x0A};
    const uint8_t WRITE_RX_ADDR_P0[]={0x2A};
    const uint8_t READ_RX_ADDR_P1[]={0x0B};
    const uint8_t WRITE_RX_ADDR_P1[]={0x2B};
    const uint8_t READ_RX_ADDR_P2[]={0x0C};
    const uint8_t WRITE_RX_ADDR_P2[]={0x2C};
    const uint8_t READ_RX_ADDR_P3[]={0x0D};
    const uint8_t WRITE_RX_ADDR_P3[]={0x2D};
    const uint8_t READ_RX_ADDR_P4[]={0x0E};
    const uint8_t WRITE_RX_ADDR_P4[]={0x2E};
    const uint8_t READ_RX_ADDR_P5[]={0x0F};
    const uint8_t WRITE_RX_ADDR_P5[]={0x2F};
    const uint8_t READ_TX_ADDR[]={0x10};
    const uint8_t WRITE_TX_ADDR[]={0x30};
    const uint8_t READ_RX_PW_P0[]={0x11};
    const uint8_t WRITE_RX_PW_P0[]={0x31};
    const uint8_t READ_RX_PW_P1[]={0x12};
    const uint8_t WRITE_RX_PW_P1[]={0x32};
    const uint8_t READ_RX_PW_P2[]={0x13};
    const uint8_t WRITE_RX_PW_P2[]={0x33};
    const uint8_t READ_RX_PW_P3[]={0x14};
    const uint8_t WRITE_RX_PW_P3[]={0x34};
    const uint8_t READ_RX_PW_P4[]={0x15};
    const uint8_t WRITE_RX_PW_P4[]={0x35};
    const uint8_t READ_RX_PW_P5[]={0x16};
    const uint8_t WRITE_RX_PW_P5[]={0x36};
    const uint8_t READ_FIFO_STATUS[]={0x17};
    const uint8_t READ_DYNPD[]={0x1C};
    const uint8_t WRITE_DYNPD[]={0x3C};
    const uint8_t READ_FEATURE[]={0x1D};
    const uint8_t WRITE_FEATURE[]={0x3D};
    
    uint8_t Rxbuffer[]={0x00};
    uint8_t num[]={0};
    uint8_t buff[2]={0,0};
    uint8_t zero[2]={0,0};
    uint8_t header[3]={255,255,50};
    const int RX_Mode=1;
    const int TX_Mode=2;
    uint8_t STATUS[]={0};
    uint8_t icheck=1;
    
    uint8_t CONFIG[]={0x0B}; // Rx mode = 0x0F  ; Tx mode = 0x0E
    uint8_t EN_AA[]={0x3F}; // 
    uint8_t EN_RXADDR[]={0x3F};
    uint8_t SETUP_AW[]={0x03};
    uint8_t SETUP_RETR[]={0x2F};
    uint8_t RF_CH[]={0x0F};
    uint8_t RF_SETUP[]={0x9F};
    uint8_t DYNPD[]={0x3F};	
    uint8_t FEATURE[]={0x07};
    uint8_t RX_PW_P0[]={0x20};
    uint8_t RX_PW_P1[]={0x20};
    uint8_t RX_PW_P2[]={0x20};
    uint8_t RX_PW_P3[]={0x20};
    uint8_t RX_PW_P4[]={0x20};
    uint8_t RX_PW_P5[]={0x20};
    uint8_t STAT[]={0x7E};
    //uint8_t RX_ADDR_P0[]={0xE7,0xE7,0xE7,0xE7,0xE7};
    //
    /* USER CODE END PV */
    
    /* Private function prototypes -----------------------------------------------*/
    void SystemClock_Config(void);
    void Error_Handler(void);
    static void MX_GPIO_Init(void);
    static void MX_DMA_Init(void);
    static void MX_SPI2_Init(void);
    static void MX_USART3_UART_Init(void);
    static void MX_USART2_UART_Init(void);
    
    /* USER CODE BEGIN PFP */
    /* Private function prototypes -----------------------------------------------*/
    void Send_command(uint8_t *opcode);
    void Write_Register(uint8_t *ADDR, uint8_t *Data);
    void Read_Register(uint8_t *ADDR, uint16_t num);
    void NRF_Deinit(void);
    void NRF_Init(void);
    void Radio_up(void);
    void Radio_down(void);
    void Receive_Data(uint8_t *data);
    void Send_Data(uint8_t *data);
    
    /* USER CODE END PFP */
    
    /* USER CODE BEGIN 0 */
    /******************************************************************************
    	CS    	-->   GPIOA-8
    	CE    	-->   GPIOA-9
    	IRQ   	-->   GPIOB-12
    	MISO  	-->   GPIOB-14
    	MOSI  	-->   GPIOB-15
    	SCK 		-->   GPIOB-13
    	
    	SWDIO 	-->		GPIOA-13
    	SWDCLK 	-->		GPIOA-14
    	
    	LED1		--> 	GPIOA-15
    	LED2		--> 	GPIOB-3
    	LED3		--> 	GPIOB-4
    	LED4		--> 	GPIOB-5
    	LED5		--> 	GPIOB-6
    	LED6		--> 	GPIOB-7
    	
    	LED7		--> 	GPIOA-5
    	LED8		--> 	GPIOA-6
    	LED9		--> 	GPIOA-7
    	LED10		--> 	GPIOB-0
    	LED11		--> 	GPIOB-1
    	LED12		--> 	GPIOB-2
    	
    	UART3RX -->		GPIOB-11
    	UART3TX --> 	GPIOB-12
    	
    	UART2RX -->		GPIOA-3
    	UART2TX -->		GPIOA-2
    	*******************************************************************************/
    /* USER CODE END 0 */
    
    int main(void)
    {
    
      /* USER CODE BEGIN 1 */
    
      /* USER CODE END 1 */
    
      /* MCU Configuration----------------------------------------------------------*/
    
      /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
      HAL_Init();
    
      /* Configure the system clock */
      SystemClock_Config();
    
      /* Initialize all configured peripherals */
      MX_GPIO_Init();
      MX_DMA_Init();
      MX_SPI2_Init();
      MX_USART3_UART_Init();
      MX_USART2_UART_Init();
    
      /* USER CODE BEGIN 2 */
    //	HAL_MspInit();
    	HAL_UART_MspInit(&huart2);
    	HAL_SPI_MspInit(&hspi2);
    	HAL_UART_MspInit(&huart3);
    	NRF_Init();
      /* USER CODE END 2 */
    
      /* Infinite loop */
      /* USER CODE BEGIN WHILE */
      while (1)
      {
      /* USER CODE END WHILE */
    
      /* USER CODE BEGIN 3 */
    		Radio_up();
    		HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_7);
    		HAL_Delay(1000);
    		Read_Register((uint8_t*)READ_FIFO_STATUS,1);
    		HAL_UART_Transmit(&huart2,Rxbuffer,1,10);	
      }
      /* USER CODE END 3 */
    
    }
    
    /** System Clock Configuration
    */
    void SystemClock_Config(void)
    {
    
      RCC_OscInitTypeDef RCC_OscInitStruct;
      RCC_ClkInitTypeDef RCC_ClkInitStruct;
    
      RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
      RCC_OscInitStruct.HSIState = RCC_HSI_ON;
      RCC_OscInitStruct.HSICalibrationValue = 16;
      RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
      RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2;
      RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16;
      if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
      {
        Error_Handler();
      }
    
      RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                                  |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
      RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
      RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
      RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
      RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
      if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
      {
        Error_Handler();
      }
    
      HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
    
      HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
    
      /* SysTick_IRQn interrupt configuration */
      HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
    }
    
    /* SPI2 init function */
    static void MX_SPI2_Init(void)
    {
    
      hspi2.Instance = SPI2;
      hspi2.Init.Mode = SPI_MODE_MASTER;
      hspi2.Init.Direction = SPI_DIRECTION_2LINES;
      hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
      hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
      hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
      hspi2.Init.NSS = SPI_NSS_SOFT;
      hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4;
      hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
      hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
      hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
      hspi2.Init.CRCPolynomial = 10;
      if (HAL_SPI_Init(&hspi2) != HAL_OK)
      {
        Error_Handler();
      }
    
    }
    
    /* USART2 init function */
    static void MX_USART2_UART_Init(void)
    {
    
      huart2.Instance = USART2;
      huart2.Init.BaudRate = 921600;
      huart2.Init.WordLength = UART_WORDLENGTH_8B;
      huart2.Init.StopBits = UART_STOPBITS_1;
      huart2.Init.Parity = UART_PARITY_NONE;
      huart2.Init.Mode = UART_MODE_TX_RX;
      huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
      huart2.Init.OverSampling = UART_OVERSAMPLING_16;
      if (HAL_UART_Init(&huart2) != HAL_OK)
      {
        Error_Handler();
      }
    
    }
    
    /* USART3 init function */
    static void MX_USART3_UART_Init(void)
    {
    
      huart3.Instance = USART3;
      huart3.Init.BaudRate = 921600;
      huart3.Init.WordLength = UART_WORDLENGTH_8B;
      huart3.Init.StopBits = UART_STOPBITS_1;
      huart3.Init.Parity = UART_PARITY_NONE;
      huart3.Init.Mode = UART_MODE_TX_RX;
      huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
      huart3.Init.OverSampling = UART_OVERSAMPLING_16;
      if (HAL_UART_Init(&huart3) != HAL_OK)
      {
        Error_Handler();
      }
    
    }
    
    /** 
      * Enable DMA controller clock
      * Configure DMA for memory to memory transfers
      *   hdma_memtomem_dma1_channel1
      */
    static void MX_DMA_Init(void) 
    {
      /* DMA controller clock enable */
      __HAL_RCC_DMA1_CLK_ENABLE();
    
      /* Configure DMA request hdma_memtomem_dma1_channel1 on DMA1_Channel1 */
      hdma_memtomem_dma1_channel1.Instance = DMA1_Channel1;
      hdma_memtomem_dma1_channel1.Init.Direction = DMA_MEMORY_TO_MEMORY;
      hdma_memtomem_dma1_channel1.Init.PeriphInc = DMA_PINC_ENABLE;
      hdma_memtomem_dma1_channel1.Init.MemInc = DMA_MINC_ENABLE;
      hdma_memtomem_dma1_channel1.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
      hdma_memtomem_dma1_channel1.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
      hdma_memtomem_dma1_channel1.Init.Mode = DMA_NORMAL;
      hdma_memtomem_dma1_channel1.Init.Priority = DMA_PRIORITY_HIGH;
      if (HAL_DMA_Init(&hdma_memtomem_dma1_channel1) != HAL_OK)
      {
        Error_Handler();
      }
            
      
    
      /* DMA interrupt init */
      /* DMA1_Channel1_IRQn interrupt configuration */
      HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 5, 0);
      HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn);
      /* DMA1_Channel7_IRQn interrupt configuration */
      HAL_NVIC_SetPriority(DMA1_Channel7_IRQn, 5, 0);
      HAL_NVIC_EnableIRQ(DMA1_Channel7_IRQn);
    
    }
    
    /** Configure pins as 
            * Analog 
            * Input 
            * Output
            * EVENT_OUT
            * EXTI
    */
    static void MX_GPIO_Init(void)
    {
    
      GPIO_InitTypeDef GPIO_InitStruct;
    
      /* GPIO Ports Clock Enable */
      __HAL_RCC_GPIOA_CLK_ENABLE();
      __HAL_RCC_GPIOB_CLK_ENABLE();
    
      /*Configure GPIO pin Output Level */
      HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8 
                              |GPIO_PIN_9|GPIO_PIN_15, GPIO_PIN_RESET);
    
      /*Configure GPIO pin Output Level */
      HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3 
                              |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7, GPIO_PIN_RESET);
    
      /*Configure GPIO pins : PA5 PA6 PA7 PA15 */
      GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_15;
      GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
      GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
      HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
    
      /*Configure GPIO pins : PB0 PB1 PB2 PB3 
                               PB4 PB5 PB6 PB7 */
      GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3 
                              |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
      GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
      GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
      HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
    
      /*Configure GPIO pin : PB12 */
      GPIO_InitStruct.Pin = GPIO_PIN_12;
      GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
      GPIO_InitStruct.Pull = GPIO_PULLUP;
      HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
    
      /*Configure GPIO pins : PA8 PA9 */
      GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;
      GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
      GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
      HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
    
      /* EXTI interrupt init*/
      HAL_NVIC_SetPriority(EXTI15_10_IRQn, 5, 0);
      HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
    
    }
    
    /* USER CODE BEGIN 4 */
    
    /*Write register function*/
    void Write_Register(uint8_t *ADDR, uint8_t *Data)
    {
    	/*Configure GPIO pin Output Level */
      HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
    	HAL_SPI_TransmitReceive(&hspi2,ADDR,STATUS,1,10);
    	HAL_SPI_Transmit(&hspi2,Data,1,10);
      HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);	
    }
    
    /*Read register function*/
    void Read_Register(uint8_t *ADDR, uint16_t num)
    {
    	/*Configure GPIO pin Output Level */
      HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
    	HAL_SPI_TransmitReceive(&hspi2,ADDR,STATUS,1,10);
    	HAL_SPI_Receive(&hspi2,Rxbuffer,num,10);
      HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);
    }
    
    /*Send commands to NRF24L01+ function*/
    void Send_command(uint8_t *opcode)
    {
    	/*Configure GPIO pin Output Level */
      HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
    	HAL_SPI_TransmitReceive(&hspi2,opcode,STATUS,1,10);
      HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);
    }
    void Radio_up(void)
    {
    	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, GPIO_PIN_SET);
    }
    void Radio_down(void)
    {
    	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, GPIO_PIN_RESET);
    }
    
    /*initialize NRF24L01+ function*/
    void NRF_Init(void)
    {
    	NRF_Deinit();
    	Radio_down();
    	Write_Register((uint8_t*)WRITE_CONFIG,(uint8_t*)CONFIG);
    	Write_Register((uint8_t*)WRITE_EN_AA,(uint8_t*)EN_AA);
    	Write_Register((uint8_t*)WRITE_EN_RXADDR,(uint8_t*)EN_RXADDR);
    	Write_Register((uint8_t*)WRITE_SETUP_AW,(uint8_t*)SETUP_AW);
    	Write_Register((uint8_t*)WRITE_SETUP_RETR,(uint8_t*)SETUP_RETR);
    	Write_Register((uint8_t*)WRITE_RF_CH,(uint8_t*)RF_CH);
    	Write_Register((uint8_t*)WRITE_RF_SETUP,(uint8_t*)RF_SETUP);
    	Write_Register((uint8_t*)WRITE_RX_PW_P0,(uint8_t*)RX_PW_P0);
    	Write_Register((uint8_t*)WRITE_RX_PW_P1,(uint8_t*)RX_PW_P1);
    	Write_Register((uint8_t*)WRITE_RX_PW_P2,(uint8_t*)RX_PW_P2);
    	Write_Register((uint8_t*)WRITE_RX_PW_P3,(uint8_t*)RX_PW_P3);
    	Write_Register((uint8_t*)WRITE_RX_PW_P4,(uint8_t*)RX_PW_P4);
    	Write_Register((uint8_t*)WRITE_RX_PW_P5,(uint8_t*)RX_PW_P5);
    	Write_Register((uint8_t*)WRITE_DYNPD,(uint8_t*)DYNPD);
    	Write_Register((uint8_t*)WRITE_FEATURE,(uint8_t*)FEATURE);
    	Radio_up();
    	HAL_Delay(5);
    }
    
    void NRF_Deinit(void)
    {
    	Radio_down();
    	Write_Register((uint8_t*)WRITE_CONFIG,0x00);
    	Write_Register((uint8_t*)WRITE_EN_RXADDR,0x00);
    	Write_Register((uint8_t*)WRITE_SETUP_RETR,0x00);
    	Write_Register((uint8_t*)WRITE_RF_CH,(uint8_t*)0x02);
    	Write_Register((uint8_t*)WRITE_EN_AA,0x00);
    	Write_Register((uint8_t*)WRITE_RF_SETUP,(uint8_t*)0x0E);
    	Write_Register((uint8_t*)WRITE_DYNPD,0x00);
    	Write_Register((uint8_t*)WRITE_FEATURE,0x00);
    	Radio_up();
    	Send_command((uint8_t*)FLUSH_TX);
    	Send_command((uint8_t*)FLUSH_RX);
    }
    
    void Send_Data(uint8_t *data)
    {
    	Send_command((uint8_t*)FLUSH_TX);
    	Send_command((uint8_t*)W_TX_PAYLOAD);
    	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
    	HAL_SPI_TransmitReceive(&hspi2,data,STATUS,32,10);
      HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);
    	Write_Register((uint8_t*)WRITE_STATUS,(uint8_t *)0x2E);
    
    }
    
    
    void Receive_Data(uint8_t *data)
    {
    	Send_command((uint8_t*)R_RX_PAYLOAD);
    	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
    	HAL_SPI_Receive(&hspi2,data,32,10);
      HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);
    	Send_command((uint8_t*)FLUSH_RX);
    	Write_Register((uint8_t*)WRITE_STATUS,(uint8_t *)0x4E);
    }
    
    void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
    {
    	if(GPIO_Pin == GPIO_PIN_12)
    	{
    		Receive_Data((uint8_t *) Rxbuffer);
    		HAL_UART_Transmit(&huart2,Rxbuffer,32,10);
    		HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_7);
    		HAL_Delay(500);
    	}
    }
    
    
    /* USER CODE END 4 */
    
    /**
      * @brief  This function is executed in case of error occurrence.
      * @param  None
      * @retval None
      */
    void Error_Handler(void)
    {
      /* USER CODE BEGIN Error_Handler */
      /* User can add his own implementation to report the HAL error return state */
      while(1) 
      {
      }
      /* USER CODE END Error_Handler */ 
    }
    
    #ifdef USE_FULL_ASSERT
    
    /**
       * @brief Reports the name of the source file and the source line number
       * where the assert_param error has occurred.
       * @param file: pointer to the source file name
       * @param line: assert_param error line source number
       * @retval None
       */
    void assert_failed(uint8_t* file, uint32_t line)
    {
      /* USER CODE BEGIN 6 */
      /* User can add his own implementation to report the file name and line number,
        ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
      /* USER CODE END 6 */
    
    }
    
    #endif
    
    /**
      * @}
      */ 
    
    /**
      * @}
    */ 
    
    /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
    

  • Sorry for the late answer. Following the backward compatibility guide should help set up communication between nrf51 and L01+. But did you try to set up communication between two L01+ devices to make sure your spi and L01+ implementation is wprking? Also, please note that L01+ is a legacy product and not recommended for new designs.

Related