nRF24LE1 SDK

Questions for programming 8051 microcontrollers in C or assembly using SDCC

Re: nRF24LE1 SDK

Postby anlpereira » Fri Apr 19, 2013 1:33 am

Hi Brennen. I have been trying to send only one byte using my nRF24LE1 board with chip antenna I bought from your website for over 3 weeks now. I'm using the sdcc compiler without problem. In the other side I have a nrf24l01 with a PIC microcontroller witch is working properlly, I can assure that. The code is bellow. It is very simple. I like to write simple codes accessing registers without using of HAL. Can you please take a look because I'm starting to think that my board is not working. I'm using a flash programmer without the need of bootloader. In the main you can see that there is a led blinking, it is working ok, I mean the code is compiling correct.

Thank you.


#include "regs24e1.h"
#include "API.h"

typedef unsigned char uint8_t; ///< 8 bit unsigned int

typedef signed char int8_t; ///< 8 bit signed int

typedef unsigned int uint16_t; ///< 16 bit unsigned int

typedef signed int int16_t; ///< 16 bit signed int

typedef unsigned long uint32_t; ///< 32 bit unsigned int

typedef signed long int32_t; ///< 32 bit signed int


#define TX_ADDR_WIDTH 5 // RF addr 5 bytes
#define TX_PLOAD_WIDTH 1 // 1 byte

uint8_t TX_ADDRESS[TX_ADDR_WIDTH] = {0xE7,0xE7,0xE7,0xE7,0xE7}; // DEFAULT ADDRESS

uint8_t dado;

/**************************************************
DELAY IN MS
**************************************************/
void delay(uint16_t x)
{
uint16_t i,j;
i=0;
for(i=0;i<x;i++)
{
j=1080;
while(j--);
}
}
/**************************************************
WRITE IN THE SPI
**************************************************/
void SPI_RW(uint8_t value)
{
SPIRDAT = value;
while(!(SPIRSTAT & 0x02));
}
/**************************************************
WRITE IN THE TRANSCEIVER REGISTER
**************************************************/
void SPI_RW_Reg(uint8_t reg, uint8_t value)
{
RFCSN = 0;
SPI_RW(reg);
SPI_RW(value);
RFCSN = 1;
}
/**************************************************
WRITE IN THE BUFFER
**************************************************/
void SPI_Write_Buf(uint8_t reg, uint8_t *buf, uint8_t bytes)
{
uint8_t byte_ctr;
RFCSN = 0; //ENABLE RF COMMAND
SPI_RW(reg); //WRITE REGISTER
for(byte_ctr=0; byte_ctr<bytes; byte_ctr++)
SPI_RW(*buf++);
RFCSN = 1;
}
/**************************************************
TRANSMIT THE PAYLOAD
**************************************************/
void TX_Payload(void)
{
RFCE=0;
SPI_RW_Reg(WRITE_REG + STATUS, 0xe7); //Clear previous ints
SPI_RW_Reg(WRITE_REG + CONFIG, 0x0a); //ENABLE CRC 1 bytes, PWR_UP, PTX
delay(10);
RFCSN=0;
SPI_RW(FLUSH_TX);
RFCSN=1;
RFCSN=0;
SPI_RW(WR_TX_PLOAD);
RFCSN=1;
RFCSN=0;
dado = 0x34;
SPI_RW(dado);
RFCSN=1;
RFCE=1; //INITIATE TRANSMITION
delay(10);
RFCE=0;
}
/**************************************************
INIT RF
**************************************************/
void rf_init(void)
{
RFCE = 0; // DISABLE RF TRANSCEIVER
RFCKEN = 1; // ENABLE CLOCK TO RF TRANSCEIVER
RFCSN=1;
//EA=1;
//RF = 1; // ENABLE RF INTERRUPT

delay(1000);

SPI_RW_Reg(WRITE_REG + CONFIG, 0x08); //0b00001010. PTX, CRC enabled, TX_DS on IRQ pin
SPI_RW_Reg(WRITE_REG + EN_AA, 0x00);
SPI_RW_Reg(WRITE_REG + SETUP_RETR, 0x00); //AUTO RETRANSMIT OFF
SPI_RW_Reg(WRITE_REG + SETUP_AW, 0x03); //ADDRESS WIDTH 5
SPI_RW_Reg(WRITE_REG + RF_SETUP, 0x06); //1MBPS, 0dBm
SPI_RW_Reg(WRITE_REG + RF_CH, 0x02); //CHANNEL 2
SPI_Write_Buf(WRITE_REG + TX_ADDR, TX_ADDRESS, TX_ADDR_WIDTH); // SET ADDRESS

}
/**************************************************
INIT IO'S
**************************************************/
void io_init(void)
{
P0DIR = 0x00; //P0 AS OUTPUT

P00=1; //BLINK LED
delay(1000);
P00=0;
}
/**************************************************
MAIN FUNCTION
**************************************************/
void main(void)
{

//unsigned long time_out;
CLKCTRL = 0x20; // Clock sourced by XCOSC16M, 16MHz CLOCK
delay(50);
io_init(); // INIT IO'S
rf_init(); // INIT RF

while(1){
P00=1;
delay(10);
TX_Payload();
P00=0;
delay(1000);
}

}
anlpereira
 
Posts: 3
Joined: Fri Apr 19, 2013 1:22 am

Re: nRF24LE1 SDK

Postby brennen » Fri Apr 19, 2013 1:08 pm

While I can appreciate wanting to use your own hardware code rather than our SDK, it has cost you three weeks in development time when you could have already had it working. I would *strongly* suggest at least starting out with our SDK and then doing whatever changes you need to get it working with your own register accesses. You should be able to start out with the example RF code and work from there.
brennen
Site Admin
 
Posts: 395
Joined: Sun Aug 17, 2008 2:15 pm

Re: nRF24LE1 SDK

Postby anlpereira » Tue Oct 08, 2013 3:54 pm

brennen wrote:While I can appreciate wanting to use your own hardware code rather than our SDK, it has cost you three weeks in development time when you could have already had it working. I would *strongly* suggest at least starting out with our SDK and then doing whatever changes you need to get it working with your own register accesses. You should be able to start out with the example RF code and work from there.



I bougth from you a nrf24le1 board one year ago but until now I couldn't make it transmit any data. I only could make it receive. I'm using the sdcc compiler from sourceforge, which I like very much. The codes are very simple but I can't transmit anyway. I don't know why it is happening, there is more than one year I'm trying to do that without any success. Bellow are both code, you can see they are very similiar. Can you take a look and see if there is one mistake, because if I can't make it work I will resend it to you. Thank you.


****************************** TX ****************************************
#include "regs24e1.h"
#include "api.h"

//Function Prototypes
void putchar (char c);
char getchar();
void Puts(char* str);


typedef unsigned char uint8_t; ///< 8 bit unsigned int
typedef signed char int8_t; ///< 8 bit signed int
typedef unsigned int uint16_t; ///< 16 bit unsigned int
typedef signed int int16_t; ///< 16 bit signed int
typedef unsigned long uint32_t; ///< 32 bit unsigned int
typedef signed long int32_t; ///< 32 bit signed int


#define TX_ADDR_WIDTH 5 // RF addr 5 bytes
#define TX_PLOAD_WIDTH 1 // 1 byte

uint8_t TX_ADDRESS[TX_ADDR_WIDTH] = {0xE7,0xE7,0xE7,0xE7,0xE7}; // DEFAULT ADDRESS

uint8_t dado;

/**************************************************
DELAY IN MS
**************************************************/
void delay(uint16_t x)
{
uint16_t i,j;
i=0;
for(i=0;i<x;i++)
{
j=1080;
while(j--);
}
}
/**************************************************
WRITE IN THE SPI
**************************************************/
void SPI_RW(uint8_t value)
{
SPIRDAT = value;
while(!(SPIRSTAT & 0x02));
}
/**************************************************
WRITE IN THE TRANSCEIVER REGISTER
**************************************************/
void SPI_RW_Reg(uint8_t reg, uint8_t value)
{
RFCSN = 0;
SPI_RW(reg);
SPI_RW(value);
RFCSN = 1;
}
/**************************************************
WRITE IN THE BUFFER
**************************************************/
void SPI_Write_Buf(uint8_t reg, uint8_t bytes)
{

uint8_t byte_ctr;
RFCSN = 0; //ENABLE RF COMMAND
SPI_RW(reg); //WRITE REGISTER
for(byte_ctr=0; byte_ctr<bytes; byte_ctr++){
SPI_RW(TX_ADDRESS[byte_ctr]);
}
RFCSN = 1;
}

/**************************************************
READ REGISTER
**************************************************/
uint8_t SPI_Read_Reg(uint8_t reg)
{
uint8_t reg_val;

RFCSN=0;
SPI_RW(reg);
SPIRDAT=0;
while(!(SPIRSTAT & (uint8_t)0x02));
reg_val=SPIRDAT;
RFCSN=1;
return(reg_val);
}
/**************************************************
TRANSMIT THE PAYLOAD
**************************************************/
void TX_Payload(void)
{
//RFCE=0;
SPI_RW_Reg(WRITE_REG + STATUS, 0x70); //Clear previous ints
SPI_RW_Reg(WRITE_REG + CONFIG, 0b01011010); //ENABLE CRC 1 bytes, PWR_UP, PTX
delay(10);
RFCSN=0;
SPI_RW(FLUSH_TX);
delay(10);
SPI_RW(WR_TX_PLOAD);
SPI_RW(0x34);
RFCSN=1;
delay(1);
RFCE=1; //INITIATE TRANSMITION
P00=1;
delay(1);

RFCE=0;
delay(100);
P00=0;

}
/**************************************************
INIT RF
**************************************************/
void rf_init(void)
{
//RFCON = 0x02;
//RFCON = 0x04;
RFCKEN = 1; // ENABLE CLOCK TO RF TRANSCEIVER
RFCE = 0; // DISABLE RF TRANSCEIVER
RFCSN=1;
//EA=1;
//RFIRQ = 1; // ENABLE RF INTERRUPT

P00=1;
delay(1000);
P00=0;
delay(100);

SPI_RW_Reg(WRITE_REG + CONFIG, 0b01011000); //PTX, CRC enabled
SPI_RW_Reg(WRITE_REG + EN_AA, 0x00); //Disable Auto-Ack
SPI_RW_Reg(WRITE_REG + SETUP_RETR, 0x00); //AUTO RETRANSMIT OFF
SPI_RW_Reg(WRITE_REG + SETUP_AW, 0x03); //ADDRESS WIDTH 5
SPI_RW_Reg(WRITE_REG + RF_SETUP, 0x06); //1MBPS, 0dBm
SPI_RW_Reg(WRITE_REG + RF_CH, 0x01); //CHANNEL 1
SPI_Write_Buf(WRITE_REG + TX_ADDR, 5); //SET ADDRESS
SPI_RW_Reg(WRITE_REG + STATUS, 0x70); //Clear Ints

P00=1;
delay(1000);
P00=0;
delay(100);

}
/**************************************************
INIT IO'S
**************************************************/
void io_init(void)
{
P0DIR = 0b00100000; //P0 AS OUTPUT

P00=1; //BLINK LED
delay(1000);
P00=0;
delay(100);
}
/**************************************************
MAIN FUNCTION
**************************************************/
void main(void)
{

io_init(); // INIT IO'S
rf_init(); // INIT RF

while(1){
delay(1000);
TX_Payload();
}

}


******************** RX *************************

#include "regs24e1.h"
#include "api.h"

typedef unsigned char uint8_t; ///< 8 bit unsigned int

typedef signed char int8_t; ///< 8 bit signed int

typedef unsigned int uint16_t; ///< 16 bit unsigned int

typedef signed int int16_t; ///< 16 bit signed int

typedef unsigned long uint32_t; ///< 32 bit unsigned int

typedef signed long int32_t; ///< 32 bit signed int


#define RX_ADDR_WIDTH 5 // RF addr 5 bytes
#define RX_PLOAD_WIDTH 1 // 1 byte

uint8_t RX_ADDRESS[RX_ADDR_WIDTH] = {0xE7,0xE7,0xE7,0xE7,0xE7}; // DEFAULT ADDRESS

uint8_t dado;

/**************************************************
DELAY IN MS
**************************************************/
void delay(uint16_t x)
{
uint16_t i,j;
i=0;
for(i=0;i<x;i++)
{
j=1080;
while(j--);
}
}
/**************************************************
WRITE IN THE SPI
**************************************************/
void SPI_RW(uint8_t value)
{
SPIRDAT = value;
while(!(SPIRSTAT & (uint8_t)0x02));
}
/**************************************************
WRITE IN THE TRANSCEIVER REGISTER
**************************************************/
void SPI_RW_Reg(uint8_t reg, uint8_t value)
{
RFCSN = 0;
SPI_RW(reg);
SPI_RW(value);
RFCSN = 1;
}

/**************************************************
READ REGISTER
**************************************************/
uint8_t SPI_Read_Reg(uint8_t reg)
{
uint8_t reg_val;

RFCSN=0;
SPI_RW(reg);
SPIRDAT=0;
while(!(SPIRSTAT & (uint8_t)0x02));
reg_val=SPIRDAT;
RFCSN=1;
return(reg_val);
}

uint8_t RX_Payload(){

uint8_t payload;
RFCSN=0;
SPI_RW(RD_RX_PLOAD);
while(!(SPIRSTAT & (uint8_t)0x04)); //wait for data in RX FIFO
payload=SPIRDAT;
SPI_RW(FLUSH_RX);
RFCSN=1;
return(payload);

}
/**************************************************
WRITE IN THE BUFFER
**************************************************/
//void SPI_Write_Buf(uint8_t reg, uint8_t *buf, uint8_t bytes)
void SPI_Write_Buf(uint8_t reg, uint8_t bytes)
{
uint8_t byte_ctr;
RFCSN = 0; //ENABLE RF COMMAND
SPI_RW(reg); //WRITE REGISTER
for(byte_ctr=0; byte_ctr<bytes; byte_ctr++){
SPI_RW(RX_ADDRESS[byte_ctr]); //*buf++
}
RFCSN = 1;
}
/**************************************************
INIT RF
**************************************************/
void rf_init(void)
{
RFCE = 0; // DISABLE RF TRANSCEIVER
RFCKEN = 1; // ENABLE CLOCK TO RF TRANSCEIVER
RFCSN = 1;

P00=1;
delay(1000);
P00=0;
delay(500);

SPI_RW_Reg(WRITE_REG + CONFIG, 0b00111011); //0b00001011. PRX, CRC enabled 1 Byte, RX_DR on IRQ pin
SPI_RW_Reg(WRITE_REG + EN_AA, 0x00); //DISABLE AUTO ACK
SPI_RW_Reg(WRITE_REG + SETUP_RETR, 0x00); //AUTO RETRANSMIT OFF
SPI_RW_Reg(WRITE_REG + SETUP_AW, 0x03); //ADDRESS WIDTH 5
SPI_RW_Reg(WRITE_REG + RF_SETUP, 0x06); //1MBPS, 0dBm
SPI_RW_Reg(WRITE_REG + RF_CH, 0x02); //CHANNEL 2
SPI_Write_Buf(WRITE_REG + RX_ADDR_P0, 5); // SET ADDRESS
SPI_RW_Reg(WRITE_REG + RX_PW_P0, 0x01); //1 byte payload
SPI_RW_Reg(WRITE_REG + STATUS, 0xe7); //CLEAR ALL INTS

P00=1;
delay(1000);
P00=0;
delay(500);
RFCE=1;

}
/**************************************************
INIT IO'S
**************************************************/
void io_init(void)
{
//delay(1000);
P0DIR = 0x00; //P0 AS OUTPUT
P00=1; //BLINK LED
delay(50);
P00=0;
delay(500);
P00=1; //BLINK LED
delay(50);
P00=0;
delay(1000);

}

/**************************************************
MAIN FUNCTION
**************************************************/
void main(void)
{

uint8_t setup_reg;
CLKCTRL = 0x20; // Clock sourced by XCOSC16M, 16MHz CLOCK
delay(10);
io_init(); // INIT IO'S
rf_init(); // INIT RF


delay(1);

while(1){
setup_reg=SPI_Read_Reg(RF_SETUP);
if((setup_reg & 0x40)){ //RX_DR active?
SPI_RW_Reg(WRITE_REG + STATUS, 0xe7); //clear all ints
dado=RX_Payload();
if(dado==0x34){
dado=0;
P00=1;
delay(100);
P00=0;
delay(100);
setup_reg=0;
}
}
delay(10);
}

}
anlpereira
 
Posts: 3
Joined: Fri Apr 19, 2013 1:22 am

Re: nRF24LE1 SDK

Postby brennen » Wed Oct 09, 2013 12:02 pm

Have you used our example RF test code? I can help you debugging our code if you want to go from there.
brennen
Site Admin
 
Posts: 395
Joined: Sun Aug 17, 2008 2:15 pm

Previous

Return to 8051 Programming

Who is online

Users browsing this forum: No registered users and 2 guests

cron