Hello,
I m working hours on this chip and i cant recive any data from it
i can read TX_DR from tx but no any interrupt from RX IRQ
my codes
#include "nrf24l01lib.h"
unsigned int adress_r[5]={0xE7,0xE7,0xE7,0xE7,0xE7};
void setup_device(unsigned int rxortx)
{
GPIO_ResetBits(GPIOA,CE);
GPIO_SetBits(GPIOA,CSN);
if(rxortx==RX)
{
w_register(WRITE_REGISTER+EN_AA_R,0x00); //AA Disbled
delay_us(20);
//check_register(EN_AA_R,0x00);
w_register(WRITE_REGISTER+EN_RXADDR_R,0x05); //RX data pipe 5
delay_us(20);
//check_register(EN_RXADDR_R,0x01);
w_register(WRITE_REGISTER+SETUP_AW_R,0x03); // TX/RX Adress 5 Byte
delay_us(20);
//check_register(SETUP_AW_R,0x03);
w_register(WRITE_REGISTER+RF_CH_R,0x02); // RF Channel Default
delay_us(20);
//check_register(RF_CH_R,0x02);
w_register(WRITE_REGISTER+RF_SETUP_R,0x07);
delay_us(20);
//check_register(RF_SETUP_R,0x07);
w_register(WRITE_REGISTER+RX_PW_P0_R,0x01);
delay_us(20);
w_register(WRITE_REGISTER+RX_PW_P1_R,0x01);
delay_us(20);
w_register(WRITE_REGISTER+RX_PW_P2_R,0x01);
delay_us(20);
w_register(WRITE_REGISTER+RX_PW_P3_R,0x01);
delay_us(20);
w_register(WRITE_REGISTER+RX_PW_P4_R,0x01);
delay_us(20);
w_register(WRITE_REGISTER+RX_PW_P5_R,0x01);
delay_us(20);
//check_register(RX_PW_P0_R,0x05);
Write_Buf(WRITE_REGISTER+RX_ADDR_P0_R,adress_r,5); //Adress
delay_us(20);
Write_Buf(WRITE_REGISTER+RX_ADDR_P1_R,adress_r,5); //Adress
delay_us(20);
w_register(WRITE_REGISTER+RX_ADDR_P2_R,0xE7);
delay_us(20);
w_register(WRITE_REGISTER+RX_ADDR_P3_R,0xE7);
delay_us(20);
w_register(WRITE_REGISTER+RX_ADDR_P4_R,0xE7);
delay_us(20);
w_register(WRITE_REGISTER+RX_ADDR_P5_R,0xE7);
delay_us(20);
w_register(WRITE_REGISTER+CONFIG_R,RX); //Config
delay_us(20);
//check_register(CONFIG_R,RX);
GPIO_SetBits(GPIOA,CE);
GPIO_ResetBits(GPIOD,GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15);
GPIO_SetBits(GPIOD,GPIO_Pin_12);
}
else
{
w_register(WRITE_REGISTER+EN_AA_R,0x00); //AA Disabled
delay_us(20);
//check_register(EN_AA_R,0x00);
w_register(WRITE_REGISTER+EN_RXADDR_R,0x01); //RX data pipe 0
delay_us(20);
//check_register(EN_RXADDR_R,0x01);
w_register(WRITE_REGISTER+SETUP_AW_R,0x03); // TX/RX Adress 5 Byte
delay_us(20);
//check_register(SETUP_AW_R,0x03);
w_register(WRITE_REGISTER+SETUP_RETR_R,0x1A); //500us + 86us, 10 retrans..
delay_us(20);
//check_register(SETUP_AW_R,0x00);
w_register(WRITE_REGISTER+RF_CH_R,0x02); // RF Channel Default
delay_us(20);
//check_register(RF_CH_R,0x02);
w_register(WRITE_REGISTER+RF_SETUP_R,0x07);
delay_us(20);
//check_register(RF_SETUP_R,0x07);
Write_Buf(WRITE_REGISTER+RX_ADDR_P0_R,adress_r,5); //RX Adress
delay_us(20);
Write_Buf(WRITE_REGISTER+TX_ADDR_R,adress_r,5); //TX Adress
w_register(WRITE_REGISTER+CONFIG_R,TX); //Config
delay_us(20);
//check_register(CONFIG_R,TX);
GPIO_ResetBits(GPIOD,GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15);
GPIO_SetBits(GPIOD,GPIO_Pin_14);
}
}
void check_register(unsigned int reg,unsigned int val)
{
unsigned int status,i;
status=r_register(reg);
if(status&val)
{
GPIO_ResetBits(GPIOD,GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15);
GPIO_SetBits(GPIOD,GPIO_Pin_12);
delay_ms(300);
GPIO_SetBits(GPIOD,GPIO_Pin_14);
delay_ms(300);
GPIO_ResetBits(GPIOD,GPIO_Pin_12|GPIO_Pin_14);
delay_ms(300);
}
else
{
for(i=0;i<2;i++)
{
GPIO_ResetBits(GPIOD,GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15);
GPIO_SetBits(GPIOD,GPIO_Pin_14);
delay_ms(300);
GPIO_ResetBits(GPIOD,GPIO_Pin_14);
delay_ms(300);
}
}
}
unsigned int recive_packet( unsigned int *data)
{
unsigned int flag=0,status;
GPIO_ResetBits(GPIOA,CE);
status=r_register(STATUS_R);
if((status & 0x40))
{
Read_Buf(R_RX_PLOAD,data,1);
flag=1;
}
w_register(WRITE_REGISTER+STATUS_R,status);
GPIO_SetBits(GPIOA,CE);
return(flag);
}
void send_packet(unsigned int *data)
{
unsigned int status=0,i;
GPIO_ResetBits(GPIOA,CE);
delay_us(20);
w_register(WRITE_REGISTER+STATUS_R,0x7E);
delay_us(20);
GPIO_ResetBits(GPIOA,CSN);
SPI_Send_Byte(FLUSH_TX);
SPI_Send_Byte(0x00);
GPIO_SetBits(GPIOA,CSN);
delay_us(20);
Write_Buf(W_TX_PLOAD,data,1);
GPIO_SetBits(GPIOA,CE);
delay_us(20);
GPIO_ResetBits(GPIOA,CE);
delay_ms(10);
check_register(STATUS_R,TX_DR);
status=r_register(STATUS_R);
w_register(WRITE_REGISTER+STATUS_R,status);
}
unsigned int Write_Buf(unsigned int op,unsigned int *data, unsigned int length)
{
unsigned int status,i;
GPIO_ResetBits(GPIOA,CSN);
delay_us(20);
status=SPI_Send_Byte(op);
for(i=0;i<length;i++)
{
SPI_Send_Byte(*data++);
}
GPIO_SetBits(GPIOA,CSN);
return(status);
}
unsigned int Read_Buf(unsigned int op,unsigned int *data,unsigned int length)
{
unsigned int status,i;
GPIO_ResetBits(GPIOA,CSN);
delay_us(20);
status=SPI_Send_Byte(op);
for(i=0;i<length;i++)
{
data[i]=SPI_Send_Byte(0);
}
GPIO_SetBits(GPIOA,CSN);
return(status);
}
unsigned int r_register(unsigned int r_adress)
{
unsigned int r_value;
GPIO_ResetBits(GPIOA,CSN);
delay_us(20);
SPI_Send_Byte(r_adress);
r_value=SPI_Send_Byte(0);
GPIO_SetBits(GPIOA,CSN);
return(r_value);
}
unsigned int w_register(unsigned int r_adress,unsigned int r_value)
{
unsigned int status;
GPIO_ResetBits(GPIOA,CSN);
delay_us(20);
status=SPI_Send_Byte(r_adress);
SPI_Send_Byte(r_value);
GPIO_SetBits(GPIOA,CSN);
return(status);
}
unsigned int SPI_Send_Byte(unsigned int value)
{
while(SPI_I2S_GetFlagStatus(SPI1,SPI_FLAG_TXE)==RESET);
SPI_I2S_SendData(SPI1,value);
while(SPI_I2S_GetFlagStatus(SPI1,SPI_FLAG_RXNE)==RESET);
return(SPI_I2S_ReceiveData(SPI1));
}
void Hardware_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
SPI_InitTypeDef SPI_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1,ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,ENABLE);
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;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(SPI1, &SPI_InitStructure);
SPI_CalculateCRC(SPI1, DISABLE);
SPI_Cmd(SPI1,ENABLE);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd =GPIO_PuPd_DOWN;
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_3|GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource5, GPIO_AF_SPI1);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_SPI1);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource7, GPIO_AF_SPI1);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_100MHz;
GPIO_Init(GPIOD,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN;
GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_100MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
}
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_tim.h"
#include "stm32f4xx_syscfg.h"
#include "stm32f4xx.h"
#include "misc.h"
#include "stm32f4xx_usart.h"
#include "stm32f4xx_spi.h"
#include "stm32f4xx_i2c.h"
#include "stm32f4xx_dma.h"
#include "delay.h"
#ifdef __cplusplus
extern "C" {
#endif
#define READ_REGISTER 0x00
#define WRITE_REGISTER 0x20
#define R_RX_PLOAD 0x61
#define W_TX_PLOAD 0xA0
#define FLUSH_TX 0xE1
#define FLUSH_RX 0xE2
#define REUSE_TX_PL 0xE3
#define NOP 0xFF
#define RX_DR 0x40
#define TX_DR 0x20
#define MAX_RT 0x10
#define TX_FULL 0x01
#define CONFIG_R 0x00
#define EN_AA_R 0x01
#define EN_RXADDR_R 0x02
#define SETUP_AW_R 0x03
#define SETUP_RETR_R 0x04
#define RF_CH_R 0x05
#define RF_SETUP_R 0x06
#define STATUS_R 0x07
#define OBSERVE_TX_R 0x08
#define RPD_R 0x09
#define RX_ADDR_P0_R 0x0A
#define RX_ADDR_P1_R 0x0B
#define RX_ADDR_P2_R 0x0C
#define RX_ADDR_P3_R 0x0D
#define RX_ADDR_P4_R 0x0E
#define RX_ADDR_P5_R 0x0F
#define TX_ADDR_R 0x10
#define RX_PW_P0_R 0x11
#define RX_PW_P1_R 0x12
#define RX_PW_P2_R 0x13
#define RX_PW_P3_R 0x14
#define RX_PW_P4_R 0x15
#define RX_PW_P5_R 0x16
#define FIFO_STATUS_R 0x17
#define DYNPO_R 0x18
#define FEATURE_R 0x19
#define HIGH 1
#define LOW 0
#define CSN GPIO_Pin_3
#define CE GPIO_Pin_4
#define SCK GPIO_Pin_5
#define MISO GPIO_Pin_6
#define MOSI GPIO_Pin_7
#define IRQ GPIO_Pin_2
#define TX 0x0A
#define RX 0x0B
void setup_device(unsigned int rxortx);
void send_packet(unsigned int *data);
unsigned int recive_packet( unsigned int *data);
unsigned int SPI_Send_Byte(unsigned int value);
unsigned int r_register(unsigned int r_adress);
unsigned int w_register(unsigned int r_adress,unsigned int r_value);
unsigned int Write_Buf(unsigned int op,unsigned int *data, unsigned int length);
unsigned int Read_Buf(unsigned int op,unsigned int *data,unsigned int length);
void Hardware_Init(void);
void check_register(unsigned int reg,unsigned int val);
#ifdef __cplusplus
}
#endif
and main programs RX
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_tim.h"
#include "stm32f4xx_syscfg.h"
#include "stm32f4xx.h"
#include "misc.h"
#include "stm32f4xx_usart.h"
#include "stm32f4xx_spi.h"
#include "stm32f4xx_i2c.h"
#include "stm32f4xx_dma.h"
#include "delay.h"
#include "nRF24L01lib.h"
void GPIO_Ayarlari(void);
int main(void)
{
unsigned int r_packet[1]={0},status;
GPIO_Ayarlari();
Hardware_Init();
setup_device(RX);
while(1)
{
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_2)==RESET)
{
recive_packet(r_packet);
if(r_packet[0]==2)
{
GPIO_ToggleBits(GPIOD,GPIO_Pin_15);
}
check_register(FIFO_STATUS_R,0x01);
}
}
}
void GPIO_Ayarlari(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD|RCC_AHB1Periph_GPIOA,ENABLE);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_100MHz;
GPIO_Init(GPIOD,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN;
GPIO_Init(GPIOA,&GPIO_InitStructure);
}
main program TX
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_tim.h"
#include "stm32f4xx_syscfg.h"
#include "stm32f4xx.h"
#include "misc.h"
#include "stm32f4xx_usart.h"
#include "stm32f4xx_spi.h"
#include "stm32f4xx_i2c.h"
#include "stm32f4xx_dma.h"
#include "delay.h"
#include "nRF24L01lib.h"
void GPIO_Ayarlari(void);
int main(void)
{
unsigned int packet[1]={2},status,i;
GPIO_Ayarlari();
Hardware_Init();
setup_device(TX);
while(1)
{
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0))
{
delay_ms(50);
send_packet(packet);
check_register(STATUS_R,TX_DR);
}
}
}
void GPIO_Ayarlari(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD|RCC_AHB1Periph_GPIOA,ENABLE);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_100MHz;
GPIO_Init(GPIOD,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN;
GPIO_Init(GPIOA,&GPIO_InitStructure);
}