Haberler:

Forum kuralları güncellendi LÜTFEN  okuyunuz:  https://bit.ly/2IjR3ME

Ana Menü

Nrf24l01 Pin problemi

Başlatan mistek, 21 Şubat 2014, 20:53:40

mistek

Nrf24l01 modül ile tek yönlü(iki yönlüde olabilir) iletişim kuracağım. Alıcı tarafta çok sayıda röle/led kontrolü yapılacak. Daha önce SPI ve NRF modül ile hiç çalışmadım o yüzden çok fazla bilgim yok.

Şurada stm32f1 için kütüphane buldum.
http://blog.iteadstudio.com/iflat32-nrf24l01-library-for-stm32-gcc-demo/

Kütüphanede Modül üzerindeki CE ve CSN bacakları için bişey yazılmamış.

@muhittin_kaplan f4 için örnek yapmıştı ancak stm32f1 için spi kütüphanesini düzenlemek zor geldi. Birde o kütüphanede CE bacağı için aç kapa yapan bişey tanımlanmış.

Konuya tepeden indiğim için herşeyi yarım yamalak anlıyorum.

CSN ve CE pinlerini kontrol etmeyip direk VCC veya GND ye bağlasam olur mu?


Birde NSS pini varmış

boş işlerin adamı ---- OHM Kanunu: I = V/R ---- Güç Formülü: P = V*I = I^2*R = V^2/R

Ramiz

1-2 sene önce bu ic ilgili bir firmaya modül tasarlamıştım. Hatırladığım kadarı ile CSN ve CE pinlerini kontrol etmelisiniz. (yanlış hatırlıyorda olabilirim)
Electrical & Electronics Engineering -> Step one

mistek

Ne yaptıysam çalıştıramadım.

Örnekleri düzenledim data gönderiliyor gibi gözüküyor ama ekrana hep 0 yazıyor.

Kod ekleyeceğim ama çok karışık gözükecek konu.
boş işlerin adamı ---- OHM Kanunu: I = V/R ---- Güç Formülü: P = V*I = I^2*R = V^2/R

Ramiz

Bu tarz ic lere bende tav im.. Gelistirme esnasinda hatanin nerede oldugunu anlamak hic kolay olmuyor. Verici duzgun calisiyormu? Alici duzgun calisiyormu? anlayamiyoruz. Birde spi olmalari cok sikinti oluyor.. Arabirim uart olsa ne olurdu yani?

Alicinin interrupt cikisi olmasi lazim. Pin adi olarak suan ismini animsayamiyorum. Onu scop ile inceleyip, veri alimi varmi diye bakilabilir. Baska disaridan izlenebilecek bir seyi yok bu ic lerin..
Electrical & Electronics Engineering -> Step one

muhittin_kaplan

#4
mistek f4 den devşir çalışıyor.

mesaj birleştirme:: 22 Şubat 2014, 00:48:31

Alıntı yapılan: Ramiz - 22 Şubat 2014, 00:43:28
Bu tarz ic lere bende tav im.. Gelistirme esnasinda hatanin nerede oldugunu anlamak hic kolay olmuyor. Verici duzgun calisiyormu? Alici duzgun calisiyormu? anlayamiyoruz. Birde spi olmalari cok sikinti oluyor.. Arabirim uart olsa ne olurdu yani?

Alicinin interrupt cikisi olmasi lazim. Pin adi olarak suan ismini animsayamiyorum. Onu scop ile inceleyip, veri alimi varmi diye bakilabilir. Baska disaridan izlenebilecek bir seyi yok bu ic lerin..
Hiç Çalıştın mı Ramiz bu IC ile ?

mesaj birleştirme:: 22 Şubat 2014, 00:49:40

bende bu kütüphaneyi kullanmıştım. ITEAD ın hazırladığı kütüphaneyi.

Ramiz

Yazilimsal olarak, mistek in suana kadar calistigi kadar calistim, donanimsal olarakta bu ic ile bir modul tasarladim muhittin.
Electrical & Electronics Engineering -> Step one

muhittin_kaplan

Fırsat bulup Multiciever yapamadım, O konuda Çalışman Oldumu, çoklu verici tek alıcı şeklinde..

Ramiz

Bu sekil bir calismam olmadi ne yazikki.. Firsatin varsa bu ic icin sunu deneyebilirmisin,

Ayni frekans ve kanalda 2 verici 1 alici.

Vericiler aktif olacak ama ayni anda asla konusmayacaklar.

Birbirlerini bastiracaklarmi cok merak ediyorum.
Electrical & Electronics Engineering -> Step one

mistek

@muhittin_kaplan hocam itead'ın hazırladığı kütüphaneyi sizin örnekle birleştirdim nrf24l01_hw_init fonksiyonunu stm32f100 için düzenledim.

Tx tarafta ekrana gelen değerler doğru iletişim için nasıl olmalı

fifo 17
config 8 gibi bişey geliyordu hepsini hatırlayamıyorum.  Alıcı taraftada sizin örneğin aynısını kullandım.
Birde modülü kaç Volt ile besliyordunuz? Ben aldığım yeri unuttum bazılarında 5v yazıyor bazılarında 3.6v.
boş işlerin adamı ---- OHM Kanunu: I = V/R ---- Güç Formülü: P = V*I = I^2*R = V^2/R

mistek

Alıcı tarafta İf şartı sağlanmadığı için ekrana bişey gelmiyor.

2 tane ulink2 olmadığı için aynı anda debug yapamıyorum. Program çakılmıyor ama iletişimde sağlanmıyor.   :'(
Tx main.c
#include "stdio.h"
#include "stm32f10x.h"
#include "stm32f10x_conf.h"
#include "nRF24l01P.h"
#include "serial.h"

unsigned char i;
unsigned char ADD[3]={0x01,0x01,0x01};
unsigned char tx_buff[TX_PLOAD_WIDTH]={0};
unsigned char rx_buff[RX_PLOAD_WIDTH]={0};
static __IO uint32_t TimingDelay;
unsigned char Tx_Buf[32]=
{
   0x01,0x02,0x03,0x4,0x05,0x06,0x07,0x08,
   0x09,0x10,0x11,0x12,0x13,0x14,0x15,0x16,
   0x17,0x18,0x19,0x20,0x21,0x22,0x23,0x24,
   0x25,0x26,0x27,0x28,0x29,0x30,0x31,0x32,
};


/* Private typedef -----------------------------------------------------------*/
GPIO_InitTypeDef  GPIO_InitStructure;
SPI_InitTypeDef   SPI_InitStructure;


/* Private define ------------------------------------------------------------*/

//Define the commands for operate the nRF24L01P
#define READ_nRF_REG    0x00  // Command for read register
#define WRITE_nRF_REG   0x20    // Command for write register
#define RD_RX_PLOAD     0x61  // Command for read Rx payload
#define WR_TX_PLOAD     0xA0  // Command for write Tx payload
#define FLUSH_TX        0xE1    // Command for flush Tx FIFO
#define FLUSH_RX        0xE2  // Command for flush Rx FIFO
#define REUSE_TX_PL     0xE3  // Command for reuse Tx payload
#define NOP             0xFF  // Reserve

//Define the register address for nRF24L01P
#define CONFIG          0x00  //  Configurate the status of transceiver, mode of CRC and the replay of transceiver status
#define EN_AA           0x01  //  Enable the atuo-ack in all channels
#define EN_RXADDR       0x02  //  Enable Rx Address
#define SETUP_AW        0x03  // Configurate the address width
#define SETUP_RETR      0x04  //  setup the retransmit
#define RF_CH           0x05  // Configurate the RF frequency
#define RF_SETUP        0x06  // Setup the rate of data, and transmit power
#define NRFRegSTATUS    0x07  //
#define OBSERVE_TX      0x08  //
#define CD              0x09  // Carrier detect
#define RX_ADDR_P0      0x0A  // Receive address of channel 0
#define RX_ADDR_P1      0x0B  // Receive address of channel 1
#define RX_ADDR_P2      0x0C  // Receive address of channel 2
#define RX_ADDR_P3      0x0D  // Receive address of channel 3
#define RX_ADDR_P4      0x0E  // Receive address of channel 4
#define RX_ADDR_P5      0x0F  // Receive address of channel 5
#define TX_ADDR         0x10  //       Transmit address
#define RX_PW_P0        0x11  //  Size of receive data in channel 0
#define RX_PW_P1        0x12  //  Size of receive data in channel 1
#define RX_PW_P2        0x13  //  Size of receive data in channel 2
#define RX_PW_P3        0x14  //  Size of receive data in channel 3
#define RX_PW_P4        0x15  // Size of receive data in channel 4
#define RX_PW_P5        0x16  //  Size of receive data in channel 5
#define FIFO_STATUS     0x17  // FIFO Status


/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
void Delay_ms(uint32_t nTime);
void TimingDelay_Decrement(void);

//void Delay(__IO uint32_t nCount);
/* Private functions ---------------------------------------------------------*/

/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
  
    unsigned char status;

void chop_tat(void);

int main(void)
{
   SystemInit();

	UART1_init();

   nRF24L01_HW_Init();
   TX_Mode();
   SPI_WR_Reg(WRITE_nRF_REG + CONFIG, 0x38); // enable power up and ptx

    Delay_ms(500);
//    GPIO_ResetBits(GPIOA, GPIO_Pin_3);
//    SPI_WR_Reg(WRITE_nRF_REG+NRFRegSTATUS, 0x70); // Write 1 to clear bit
  while (1)
  {


       nRF24L01_TxPacket(Tx_Buf);

      Delay_ms(10);

      status=SPI_RD_Reg(NRFRegSTATUS);
      //status=SPI_RD_Reg(0x17);
      //status=SPI_RD_Reg(CONFIG);
      //status=SPI_RD_Reg(RF_SETUP);
     //status=SPI_RD_Reg(RF_CH);
      if((status & 0x20)==0x20)

      chop_tat();
      while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET); // Wait for Empty
      printf("\r status is: %d \n",status);
      status=SPI_RD_Reg(0x17);
      printf("\r fifo is: %d\n",status);
      status=SPI_RD_Reg(RF_SETUP);
      printf("\r rf setup is: %d\n",status);
     status=SPI_RD_Reg(RF_CH);
      printf("\r rf chanel is: %d\n",status);
      status=SPI_RD_Reg(CONFIG);
      printf("\r config is: %d\n",status);
      GPIO_ResetBits(GPIOA, GPIO_Pin_3);
      SPI_WR_Reg(WRITE_nRF_REG + CONFIG, 0x3B); // enable power up and prx

      Delay_ms(30);
  }
}

/**
  * @brief  Delay Function.
  * @param  nCount:specifies the Delay time length.
  * @retval None
  */
// void Delay(__IO uint32_t nCount)
// {
//   while(nCount--)
//   {
//   }
// }
void Delay_ms(__IO uint32_t nTime)
{
  while(--nTime);
}
void TimingDelay_Decrement(void)
{
  if (TimingDelay != 0x00)
  {
    TimingDelay--;
  }
}

void chop_tat(void)
{
   GPIO_SetBits(GPIOD, GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15);
   Delay_ms(500);
   GPIO_ResetBits(GPIOD, GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15);
   Delay_ms(500);
}



Rx main.c
#include "stdio.h"
#include "stm32f10x.h"
#include "stm32f10x_conf.h"
#include "nRF24l01P.h"
#include "serial.h"


unsigned char i;
unsigned char ADD[3]={0};
unsigned char tx_buff[32];
unsigned char rx_buff[32];
static __IO uint32_t TimingDelay;

/* Private typedef -----------------------------------------------------------*/
GPIO_InitTypeDef  GPIO_InitStructure;
SPI_InitTypeDef   SPI_InitStructure;


/* Private define ------------------------------------------------------------*/

//Define the commands for operate the nRF24L01P
#define READ_nRF_REG    0x00  // Command for read register
#define WRITE_nRF_REG   0x20    // Command for write register
#define RD_RX_PLOAD     0x61  // Command for read Rx payload
#define WR_TX_PLOAD     0xA0  // Command for write Tx payload
#define FLUSH_TX        0xE1    // Command for flush Tx FIFO
#define FLUSH_RX        0xE2  // Command for flush Rx FIFO
#define REUSE_TX_PL     0xE3  // Command for reuse Tx payload
#define NOP             0xFF  // Reserve

//Define the register address for nRF24L01P
#define CONFIG          0x00  //  Configurate the status of transceiver, mode of CRC and the replay of transceiver status
#define EN_AA           0x01  //  Enable the atuo-ack in all channels
#define EN_RXADDR       0x02  //  Enable Rx Address
#define SETUP_AW        0x03  // Configurate the address width
#define SETUP_RETR      0x04  //  setup the retransmit
#define RF_CH           0x05  // Configurate the RF frequency
#define RF_SETUP        0x06  // Setup the rate of data, and transmit power
#define NRFRegSTATUS    0x07  //
#define OBSERVE_TX      0x08  //
#define CD              0x09  // Carrier detect
#define RX_ADDR_P0      0x0A  // Receive address of channel 0
#define RX_ADDR_P1      0x0B  // Receive address of channel 1
#define RX_ADDR_P2      0x0C  // Receive address of channel 2
#define RX_ADDR_P3      0x0D  // Receive address of channel 3
#define RX_ADDR_P4      0x0E  // Receive address of channel 4
#define RX_ADDR_P5      0x0F  // Receive address of channel 5
#define TX_ADDR         0x10  //       Transmit address
#define RX_PW_P0        0x11  //  Size of receive data in channel 0
#define RX_PW_P1        0x12  //  Size of receive data in channel 1
#define RX_PW_P2        0x13  //  Size of receive data in channel 2
#define RX_PW_P3        0x14  //  Size of receive data in channel 3
#define RX_PW_P4        0x15  // Size of receive data in channel 4
#define RX_PW_P5        0x16  //  Size of receive data in channel 5
#define FIFO_STATUS     0x17  // FIFO Status


/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
void Delay_ms(uint32_t nTime);
void TimingDelay_Decrement(void);
void SPI_Configuration(void);

//void Delay(__IO uint32_t nCount);
/* Private functions ---------------------------------------------------------*/

/**
  * @brief  Main program
  * @param  None
  * @retval None
  */

   unsigned char status;

void chop_tat(void);

int main(void)
{
   SystemInit();


  //if (SysTick_Config(SystemCoreClock / 1000))
  //{
    /* Capture error */
  //  while (1);
  //}

   nRF24L01_HW_Init();
   UART1_init();

  while (1)
  {
      RX_Mode();
      if(nRF24L01_RxPacket(rx_buff))
      {

          for(i=0;i<32;i++)
          {
             //USART_SendData(USART2, rx_buff[i]);
             printf("%d",rx_buff[i]);
          }
          printf("\n\r");
          chop_tat();
      }
		
      status=SPI_RD_Reg(FIFO_STATUS);

       Delay_ms(500);
        for(i=0;i<32;i++)
                 {
                    //USART_SendData(USART2, rx_buff[i]);
                   rx_buff[i]=0x00;
                 }
  }
}

/**
  * @brief  Delay Function.
  * @param  nCount:specifies the Delay time length.
  * @retval None
  */
// void Delay(__IO uint32_t nCount)
// {
//   while(nCount--)
//   {
//   }
// }
void Delay_ms(__IO uint32_t nTime)
{
  while(--nTime);
}
void TimingDelay_Decrement(void)
{
  if (TimingDelay != 0x00)
  {
    TimingDelay--;
  }
}

void chop_tat(void)
{
   GPIO_SetBits(GPIOD, GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15);
   Delay_ms(5000);
   GPIO_ResetBits(GPIOD, GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15);
   Delay_ms(5000);
}



nrf24l01.c
#include "stm32f10x.h"
#include "stm32f10x_conf.h"
#include "nRF24l01P.h"

//Define the commands for operate the nRF24L01P
#define READ_nRF_REG    0x00  // Command for read register
#define WRITE_nRF_REG   0x20 	// Command for write register
#define RD_RX_PLOAD     0x61  // Command for read Rx payload
#define WR_TX_PLOAD     0xA0  // Command for write Tx payload
#define FLUSH_TX        0xE1 	// Command for flush Tx FIFO
#define FLUSH_RX        0xE2  // Command for flush Rx FIFO
#define REUSE_TX_PL     0xE3  // Command for reuse Tx payload
#define NOP             0xFF  // Reserve

//Define the register address for nRF24L01P
#define CONFIG          0x00  //  Configurate the status of transceiver, mode of CRC and the replay of transceiver status
#define EN_AA           0x01  //  Enable the atuo-ack in all channels
#define EN_RXADDR       0x02  //  Enable Rx Address
#define SETUP_AW        0x03  // Configurate the address width
#define SETUP_RETR      0x04  //  setup the retransmit
#define RF_CH           0x05  // Configurate the RF frequency
#define RF_SETUP        0x06  // Setup the rate of data, and transmit power
#define NRFRegSTATUS    0x07  //
#define OBSERVE_TX      0x08  //
#define CD              0x09  // Carrier detect
#define RX_ADDR_P0      0x0A  // Receive address of channel 0
#define RX_ADDR_P1      0x0B  // Receive address of channel 1
#define RX_ADDR_P2      0x0C  // Receive address of channel 2
#define RX_ADDR_P3      0x0D  // Receive address of channel 3
#define RX_ADDR_P4      0x0E  // Receive address of channel 4
#define RX_ADDR_P5      0x0F  // Receive address of channel 5
#define TX_ADDR         0x10  //       Transmit address
#define RX_PW_P0        0x11  //  Size of receive data in channel 0
#define RX_PW_P1        0x12  //  Size of receive data in channel 1
#define RX_PW_P2        0x13  //  Size of receive data in channel 2
#define RX_PW_P3        0x14  //  Size of receive data in channel 3
#define RX_PW_P4        0x15  // Size of receive data in channel 4
#define RX_PW_P5        0x16  //  Size of receive data in channel 5
#define FIFO_STATUS     0x17  // FIFO Status
// define  GPIO for SPI

#define SPI                   			   SPI1
#define GPIO_CS_CE                  	   GPIOA
#define GPIO_Pin_CE              			GPIO_Pin_3
#define GPIO_Pin_CS              			GPIO_Pin_4
#define RCC_APB2Periph_GPIO_CS_CE   	RCC_APB2Periph_GPIOA


#define GPIO_SPI              			  GPIOA
#define GPIO_Pin_SPI_SCK      			  GPIO_Pin_5
#define GPIO_Pin_SPI_MISO     			  GPIO_Pin_6
#define GPIO_Pin_SPI_MOSI     			  GPIO_Pin_7
#define RCC_APBPeriph_SPI     			  RCC_APB2Periph_SPI1
#define GPIO_Pin_SPI_CS_SOURCE        GPIO_PinSource4
#define GPIO_Pin_SPI_SCK_SOURCE       GPIO_PinSource5
#define GPIO_Pin_SPI_MISO_SOURCE      GPIO_PinSource6
#define GPIO_Pin_SPI_MOSI_SOURCE      GPIO_PinSource7
#define RCC_APB2Periph_GPIO_SPI       RCC_APB2Periph_GPIOA
///**************************************************************************************

//define the private constants in this library
//#define TX_ADR_WIDTH 5
//#define RX_ADR_WIDTH 5

unsigned char TxBuf[Buffer_Size] = {0};
unsigned char RxBuf[Buffer_Size] = {0};

unsigned char nRF24L01_Freq = 0;
unsigned char nRF24L01_power_rate = 0;

//define the initial Address
unsigned char  TX_ADDRESS[ADR_WIDTH]= {0xE7,0xE7,0xE7,0xE7,0xE7};
unsigned char  RX_ADDRESS[ADR_WIDTH]= {0xE7,0xE7,0xE7,0xE7,0xE7};
// unsigned char  TX_ADDRESS[ADR_WIDTH]= {0xB3,0xB4,0xB5,0xB6,0xF1};
// unsigned char  RX_ADDRESS[ADR_WIDTH]= {0xB3,0xB4,0xB5,0xB6,0xF1};
// unsigned char  TX_ADDRESS[ADR_WIDTH]= {0x01,0x23,0x45,0x67,0x89};
// unsigned char  RX_ADDRESS[ADR_WIDTH]= {0x01,0x23,0x45,0x67,0x89};
//Define the layer1:HW operation
unsigned char nRF24L01_SPI_Send_Byte(unsigned char dat);
void nRF24L01_HW_Init(void);
void nRF24L01_Init_Soft(void);
void nRF24L01_SPI_NSS_L(void);
void nRF24L01_SPI_NSS_H(void);
void nRF24L01_CE_L(void);
void nRF24L01_CE_H(void);
//Define the layer2:Reg operation
unsigned char SPI_WR_Reg(unsigned char reg, unsigned char value);
unsigned char SPI_RD_Reg(unsigned char reg);
unsigned char SPI_Read_Buf(unsigned char reg, unsigned char *pBuf, unsigned char Len);
unsigned char SPI_Write_Buf(unsigned char reg, unsigned char *pBuf, unsigned char Len);


//Define the layer3:application operation
/****************************************

All the functions is in "nRF24l01P.h"

****************************************/

//Define the other function
void nRF24L01_Delay_us(unsigned long n);


void TX_Mode(void)
{
  nRF24L01_CE_L();
	SPI_WR_Reg(WRITE_nRF_REG + SETUP_AW, 0x03); // setup add width 5 bytes
	nRF24L01_Delay_us(20);
	SPI_WR_Reg(WRITE_nRF_REG + CONFIG, 0x38); // enable power up and ptx
	nRF24L01_Delay_us(20);
	SPI_WR_Reg(WRITE_nRF_REG + EN_RXADDR, 0x01); //Enable data P0
	nRF24L01_Delay_us(20);
	SPI_WR_Reg(WRITE_nRF_REG + SETUP_RETR, 0x00);//Auto Retransmit Delay: 500 us, Auto Retransmit Count: Up to 2 Re-Transmit
	nRF24L01_Delay_us(20);
	SPI_WR_Reg(WRITE_nRF_REG + RF_CH,0x02);// setup frequency
	nRF24L01_Delay_us(20);
	SPI_WR_Reg(WRITE_nRF_REG + RF_SETUP ,0x07); //setup power 0dbm, rate 1Mbps
	nRF24L01_Delay_us(20);
	SPI_Write_Buf(WRITE_nRF_REG + TX_ADDR, TX_ADDRESS, ADR_WIDTH); // write address into tx_add
	nRF24L01_Delay_us(20);
	SPI_Write_Buf(WRITE_nRF_REG + RX_ADDR_P0, RX_ADDRESS, ADR_WIDTH); // write address into rx_add_p0
	nRF24L01_Delay_us(20);
	SPI_WR_Reg(WRITE_nRF_REG + EN_AA, 0x00);     // Disable Auto.Ack:Pipe0
	
	
	
  //nRF24L01_CE_H();
	nRF24L01_Delay_us(200);
	
}


void nRF24L01_TxPacket(unsigned char * tx_buf)
{
  nRF24L01_CE_L();
	
	
	//SPI_Write_Buf(WRITE_nRF_REG + RX_ADDR_P0, TX_ADDRESS, ADR_WIDTH);
	//SPI_Write_Buf(WRITE_nRF_REG + TX_ADDR, TX_ADDRESS, ADR_WIDTH); // write address into tx_add
	SPI_WR_Reg(WRITE_nRF_REG+NRFRegSTATUS, 0x7E); // Write 1 to clear bit
	nRF24L01_Delay_us(20);
	SPI_WR_Reg(WRITE_nRF_REG + CONFIG, 0x3A); // enable power up and ptx
	nRF24L01_Delay_us(20);
	nRF24L01_SPI_NSS_L();  
	nRF24L01_SPI_Send_Byte(FLUSH_TX);
	nRF24L01_SPI_Send_Byte(0x00);
	nRF24L01_SPI_NSS_H();  
	nRF24L01_Delay_us(20);
	SPI_Write_Buf(WR_TX_PLOAD, tx_buf, TX_PLOAD_WIDTH);
 	
	//SPI_WR_Reg(WRITE_nRF_REG+NRFRegSTATUS, 0x20); // Write 1 to clear bit
  //nRF24L01_CE_H();
	//nRF24L01_Delay_us(200);
  nRF24L01_CE_H();
	//nRF24L01_CE_L();
	nRF24L01_Delay_us(3000);
	nRF24L01_CE_L();

}

unsigned char nRF24L01_RxPacket(unsigned char* rx_buf)
{
	unsigned char flag=0;
  unsigned char status;

	status=SPI_RD_Reg(NRFRegSTATUS);

	if(status & 0x40) //Data Ready RX FIFO interrupt
	{
		 SPI_Read_Buf(RD_RX_PLOAD,rx_buf,RX_PLOAD_WIDTH);
		 flag =1;
	}
	SPI_WR_Reg(WRITE_nRF_REG+NRFRegSTATUS, status); // Write 1 to clear bit
	return flag;
}

//Define the layer2 functions
unsigned char SPI_RD_Reg(unsigned char reg)
{
	unsigned char reg_val;

	nRF24L01_SPI_NSS_L();                // CSN low, initialize SPI communication...
	nRF24L01_Delay_us(20);
	nRF24L01_SPI_Send_Byte(reg);            // Select register to read from..
	reg_val = nRF24L01_SPI_Send_Byte(0);    // ..then read register value
	nRF24L01_SPI_NSS_H();                // CSN high, terminate SPI communication

	return(reg_val);        // return register value
}

unsigned char SPI_WR_Reg(unsigned char reg, unsigned char value)
{
	unsigned char status;

	nRF24L01_SPI_NSS_L();  
  nRF24L01_Delay_us(20);	// CSN low, init SPI transaction
	status = nRF24L01_SPI_Send_Byte(reg);// select register
	nRF24L01_SPI_Send_Byte(value);             // ..and write value to it..
	nRF24L01_SPI_NSS_H();                   // CSN high again

	return(status);            // return nRF24L01 status unsigned char
}

unsigned char SPI_Read_Buf(unsigned char reg, unsigned char *pBuf, unsigned char Len)
{
	unsigned int status,i;

	nRF24L01_SPI_NSS_L();                  // Set CSN low, init SPI tranaction
	nRF24L01_Delay_us(20);
	status = nRF24L01_SPI_Send_Byte(reg);  // Select register to write to and read status unsigned char

  for(i=0;i<Len;i++)
  {
     pBuf[i] = nRF24L01_SPI_Send_Byte(0);
  }

	nRF24L01_SPI_NSS_H();

	return(status);                    // return nRF24L01 status unsigned char
}

unsigned char SPI_Write_Buf(unsigned char reg, unsigned char *pBuf, unsigned char Len)
{
	unsigned int status,i;

	nRF24L01_SPI_NSS_L();
	nRF24L01_Delay_us(20);
	status = nRF24L01_SPI_Send_Byte(reg);
	for(i=0; i<Len; i++) //
	{
		nRF24L01_SPI_Send_Byte(*pBuf);
		pBuf ++;
	}
	nRF24L01_SPI_NSS_H();    
	return(status);   
}



//Define the layer1 functions
unsigned char nRF24L01_SPI_Send_Byte(unsigned char dat)
{
  /* Loop while DR register in not emplty */
  while(SPI_I2S_GetFlagStatus(SPI, SPI_I2S_FLAG_TXE) == RESET);

  /* Send byte through the SPIx peripheral */
  SPI_I2S_SendData(SPI, dat);

  /* Wait to receive a byte */
  while(SPI_I2S_GetFlagStatus(SPI, SPI_I2S_FLAG_RXNE) == RESET);

  /* Return the byte read from the SPI bus */
  return SPI_I2S_ReceiveData(SPI);
}

void nRF24L01_SPI_NSS_H(void)
{
	GPIO_SetBits(GPIO_CS_CE, GPIO_Pin_CS);
}

void nRF24L01_SPI_NSS_L(void)
{
	GPIO_ResetBits(GPIO_CS_CE, GPIO_Pin_CS);
}

void nRF24L01_CE_L(void)
{
	GPIO_ResetBits(GPIO_CS_CE, GPIO_Pin_CE);
}

void nRF24L01_CE_H(void)
{
	GPIO_SetBits(GPIO_CS_CE, GPIO_Pin_CE);
}

void nRF24L01_HW_Init(void)
{
	SPI_InitTypeDef  SPI_InitStructure;
  GPIO_InitTypeDef GPIO_InitStructure;

	/* Enable GPIO clocks */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIO_SPI, ENABLE);
	/* SPI Periph clock enable */
	RCC_APB2PeriphClockCmd(RCC_APBPeriph_SPI | RCC_APB2Periph_AFIO, ENABLE);
	
	
	
	/* Configure SPI pins:  SCK ,MOSI, MISO*/
	GPIO_InitStructure.GPIO_Pin =   GPIO_Pin_SPI_SCK | GPIO_Pin_SPI_MOSI | GPIO_Pin_SPI_MISO;
	GPIO_InitStructure.GPIO_Mode =  GPIO_Mode_AF_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_Init(GPIO_SPI, &GPIO_InitStructure);

	/* Enable GPIO of CHIP SELECT */
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIO_CS_CE, ENABLE);
	/* Configure CS pin */
	//SPI_SSOutputCmd(SPI, ENABLE);
	GPIO_InitStructure.GPIO_Pin =   GPIO_Pin_CS|GPIO_Pin_CE;
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
     //GPIO_Init(GPIOB, &GPIO_InitStructure);
	GPIO_Init(GPIO_CS_CE, &GPIO_InitStructure);

	
	/* SPI configuration */
  SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
  SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
  SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
  SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
  SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
  SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
  SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256; // 84000kHz/256=328kHz < 400kHz
  SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
  SPI_InitStructure.SPI_CRCPolynomial = 7;

	SPI_Init(SPI1, &SPI_InitStructure);
	
	/* SPI1 enable */
	SPI_Cmd(SPI, ENABLE);

}

void nRF24L01_Delay_us(unsigned long n)
{
	unsigned long i;

	while(n--)  // delay n us
	{
 	   i=100;   
 	   while(i--); // delay 1 us
  }
}


nrf24l01.h
#define ADR_WIDTH 5

#define RX_PLOAD_WIDTH 32
#define TX_PLOAD_WIDTH 32
#define Buffer_Size 32

//Define RF power value
#define P0dBm   0
#define Pm6dBm  1
#define Pm12dBm 2
#define Pm18dBm 3

//#define RF rate
#define R2mbps   0
#define R1mbps   1
#define R250kbps 3


unsigned char nRF24L01_Config(unsigned char freq,unsigned char power,unsigned char rate);
void RX_Mode(void);
void TX_Mode(void);
void nRF24L01_TxPacket(unsigned char * tx_buf);
unsigned char nRF24L01_RxPacket(unsigned char* rx_buf);
void nRF24L01_HW_Init(void);
void nRF24L01_Init_Soft(void);
void nRF24L01_Set_TX_Address(unsigned char A,unsigned char B,unsigned char C,unsigned char D,unsigned char E);
void nRF24L01_Set_RX_Address(unsigned char A,unsigned char B,unsigned char C,unsigned char D,unsigned char E);
unsigned char SPI_RD_Reg(unsigned char reg);
unsigned char SPI_WR_Reg(unsigned char reg, unsigned char value);
boş işlerin adamı ---- OHM Kanunu: I = V/R ---- Güç Formülü: P = V*I = I^2*R = V^2/R

elektronart

ilk bakışta görebildiğim kodları kaynağında olduğu gibi kullandığınız için adresler aynı kalmış.
Bu iki modülü haberleştirebilmek için vericiye yazılacak TX adres ile alıcıdaki RX adres aynı olmalı.
#define ile RX ve TX adresler verilmiş, kodun içinde nerede kullanılmış göremedim, NRF24L01 in RX ve TX adresleri kodun neresinde set edilmiş, set edilirken #define adresleri mi kullanılmış yoksa başka adresler mi yazılmış onu da göremedim. Mainler içinde de ADD[3] ler var bunlar da aynı değil ama onların da nerede kullanıldığını göremedim. Bunları bir kontrol etmenizi öneririm.
Özetle vericinin TX adresi ile alıcının RX adresi aynı olmalı. Sorun yaşamamak için başlangıçta gördüğünüz tüm adresleri aynı yapın. Sonra sonra çipe ısındıkça düzenlemeler yaparsınız.
Açık Elektronik