CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

nRF24L01+ full driver by Eduardo Guilherme Brandt
Goto page Previous  1, 2, 3 ... 15, 16, 17, 18, 19, 20  Next
 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
Pret



Joined: 18 Jul 2006
Posts: 92
Location: Iasi, Romania

View user's profile Send private message

PostPosted: Sun Dec 07, 2014 6:28 pm     Reply with quote

I don't want to rewrite all the registers by hand to their default value. I was looking for a simple nRF command that is supposed to clear all regs to default at once. But I guess there isn't such command...
spilz



Joined: 30 Jan 2012
Posts: 220

View user's profile Send private message

PostPosted: Tue Dec 16, 2014 4:15 am     Reply with quote

Hi Eduardo and everyone

Thanks for your code

Did someone find a way to compile it with PICC CCS V5.xxx ?
And do not have to switch to V4
spilz



Joined: 30 Jan 2012
Posts: 220

View user's profile Send private message

PostPosted: Tue Dec 16, 2014 8:55 am     Reply with quote

is there a way to convert :
Code:
rv=spi_xfer(RF24_SPI, comm1,commDS);

by something like this :
Code:
int i;
for(i=0;i<commDS;i++){
   rv=spi_xfer(RF24_SPI, comm1);
}

I know it's not exactly that, but I don't know how to do it

thanks for your help
40inD



Joined: 30 Jul 2007
Posts: 112
Location: Moscow, Russia

View user's profile Send private message

PostPosted: Thu Apr 16, 2015 9:21 am     Reply with quote

Which functions can be removed to simplify this driver if I need to work with it just like as radio transceiver to exchange several bytes between 2 devices?
40inD



Joined: 30 Jul 2007
Posts: 112
Location: Moscow, Russia

View user's profile Send private message

PostPosted: Fri Apr 24, 2015 4:19 am     Reply with quote

is it possible to use INT_EXT isr with RF24_IRQ_state() to wake up MCU and not polling IRQ pin all time?
onepiro



Joined: 26 May 2015
Posts: 1

View user's profile Send private message

PostPosted: Tue May 26, 2015 12:23 pm     Reply with quote

Hi. A simple example(rx-tx) and connection schematic one can share? I'm try simple tx and rx code in to library file but not work.
amanver



Joined: 06 May 2015
Posts: 4
Location: bonab

View user's profile Send private message

PostPosted: Fri May 29, 2015 2:49 am     Reply with quote

hi.
please try the code in 4th page of this topic.
aaronik19



Joined: 25 Apr 2011
Posts: 297

View user's profile Send private message

PostPosted: Mon Jun 01, 2015 12:32 am     Reply with quote

Thanks Eduardo, your work is very nice and very gentle that you shared this driver on the forum. I will try this driver in the coming days. I would like to ask, how many transceivers can be used on the network?

I saw this video on Youtube, and i would like to share it with you as an introduction. Although it is aimed to Arduino, it explains some basics of this transceiver. Referring to my question, the video mentioned that 6 tx and 1 rx can be used, but i am making a design where i need to have about 100 transceivers https://m.youtube.com/watch?v=BjId_6tlYvE
Eduardo__



Joined: 23 Nov 2011
Posts: 197
Location: Brazil

View user's profile Send private message

PostPosted: Mon Jun 01, 2015 7:13 am     Reply with quote

Yes, you can use 100 transceivers in the same channel (or in different channels). But you must implement a protocol to handle with it!
_________________
Eduardo Guilherme Brandt
amanver



Joined: 06 May 2015
Posts: 4
Location: bonab

View user's profile Send private message

how to use in ccs only?
PostPosted: Sat Jun 06, 2015 5:56 am     Reply with quote

hi all.
my question is that how i use example in 4th page in ccs compiler only?(that means not use mplab or any IDE)
when i create 2 project, one for receive and another for transfer and using the codes in the 4th page and compile, in the side of rx give me errors but transfer side compile very well.

the error is:
Undefined identifier STREAM_SPI
in .c file on RF24_xfer(comm); line
can anyone help me?
thanks a'lot.
ccs v4.130
microcontroller :18f452
--------------------------------------------------------------------------
when i change the micro controller to 16f628a the error acoure it is "Internal error-Contact CCS PPUSE
hassasian



Joined: 05 Jul 2015
Posts: 3

View user's profile Send private message AIM Address

dezso's code for 16f628A
PostPosted: Wed Aug 05, 2015 1:54 pm     Reply with quote

I'm using dezso's code for my homework. I edit a little his code. But I cannot light the reader led. Pls help. I send 1234 from sender. Then try to receive it from reader. But I cannot.

Here my receiver code.
Code:
/*
 * File:   main.c
 * Author: DevXP
 *
 * Created on March 8, 2013, 9:40 PM
 */
#include <16F628A.H>
#device ICD=TRUE
#device *=16
#FUSES NOWDT                    //No Watch Dog Timer
//#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O

#use delay(internal=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B2,rcv=PIN_B1,bits=8,stream=PORT1))
//---------------- change this for Rx/Tx-----------------------
//#define TX_Mode       // setup as Rx
//#define TX_Mode         // setup as Tx
//-------------------------------------------------------------
#define W_REGISTER 0x20
#define R_RX_PAYLOAD 0x61
#define W_TX_PAYLOAD 0xa0
//********** DEFINE PORT NAMES
#define  SPI_MISO       PIN_A4    //RC4; SPI
#define  SPI_MOSI       PIN_A3      //RC5; SPI
#define  SPI_CLK        PIN_A2      //RC3; SPI)
#define  RF24_IRQ       PIN_B0      //RA5;  interrupcao nRF24L01+
#define  RF24_CS        PIN_A1      //RC1;  chipselect nRF24L01+
#define  RF24_CE        PIN_A0      //RC2;  chipEnable nRF24L01+
#define RF24_xfer(xdata)   bb_xfer(xdata)  //Send/receive data through SPI
#define RTX_CSN_Low()      output_low(RF24_CS)        //Controls bit Chipselect
#define RTX_CSN_High()     output_high(RF24_CS)       //Controls bit Chipselect
#define RTX_CE_Low()       output_low(RF24_CE)       //Controls bit Chipenable
#define RTX_CE_High()      output_high(RF24_CE)        //Controls bit Chipenable
#define RF24_IRQ_state()   !input(RF24_IRQ)
static int8        RF_DATA[4];
#define LED0  PIN_B4
#include <STDLIB.H>
/*******************************************************************************/
void pulse_CSN()
{
    RTX_CSN_High();;
    delay_us(20);
    RTX_CSN_Low();
}

int bb_xfer(spi_data)
{
//    SPI_MISO
//    SPI_MOSI
//    SPI_CLK
    delay_us(50);
    int rt;
    int result = 0;
    int1 d = 0;
    for(rt=0;rt<8;rt++)
    {
        d = bit_test(spi_data,7-rt);
        if(d)
        {
            output_high(SPI_MOSI);
        }
        else
        {
            output_low(SPI_MOSI);
        }
        delay_us(10);
        output_high(SPI_CLK);
        delay_us(60);
        output_low(SPI_CLK);
        delay_us(10);
        if(input(SPI_MISO))
        {
            bit_set(result,6-rt);
        }
        else
        {
            bit_clear(result,6-rt);
        }
    }
    output_low(SPI_MOSI);
    return(result);
}

void configure_TX()
{
    int i;
    RTX_CSN_Low();
    RTX_CE_Low();;
    bb_xfer(W_REGISTER); // PTX, CRC enabled, mask a couple of ints
    bb_xfer(0x38);
    pulse_CSN();
    delay_ms(2);
    //-----------
    bb_xfer(0x24); //auto retransmit off
    bb_xfer(0x00);
    pulse_CSN();;
    //-----------
    bb_xfer(0x23); //address width = 5
    bb_xfer(0x03);
    pulse_CSN();
    //-----------
    bb_xfer(0x26); //data rate = 1MB
    bb_xfer(0x07);
    pulse_CSN();
    //-----------
    bb_xfer(0x25);  //set channel 2, this is default
    bb_xfer(0x02);
    pulse_CSN();
    //-----------
    bb_xfer(0x30); //set address E7E7E7E7E7
    for(i=0;i<5;i++)
    {
        bb_xfer(0xe7);
    }
        pulse_CSN();
    //----------------
    bb_xfer(0x21); //disable auto-ack, RX mode
    bb_xfer(0x00);
    RTX_CSN_High();;
}

void configure_RX()
{
    int i;
    RTX_CSN_Low();
    RTX_CE_Low();;
    bb_xfer(W_REGISTER); //PRX, CRC enabled
    bb_xfer(0x39);
    pulse_CSN();
    delay_ms(2);
    //-----------
    bb_xfer(0x21);  //dissable auto-ack for all channels
    bb_xfer(0x00);
    pulse_CSN();
    //-----------
    bb_xfer(0x23); //address width = 5 bytes
    bb_xfer(0x03);
    pulse_CSN();
    //-----------
    bb_xfer(0x26); //data rate = 1MB
    bb_xfer(0x07);
    pulse_CSN();
    //-----------
    bb_xfer(0x31);  //4 byte payload
    bb_xfer(0x04);
    pulse_CSN();
    //-----------
    bb_xfer(0x25); //set channel 2
    bb_xfer(0x02);
    pulse_CSN();
    //-----------
    bb_xfer(0x30); //set address E7E7E7E7E7
    for(i=0;i<=5;i++)
    {
        bb_xfer(0xe7);
    }
        pulse_CSN();
    //----------------
    bb_xfer(W_REGISTER); //PWR_UP = 1
    bb_xfer(0x3b);
    RTX_CSN_High();;
    RTX_CE_High();
}

void read_Data()
{
    int i;
    RTX_CSN_Low();
    bb_xfer(R_RX_PAYLOAD); //Read RX payload
    for(i=0;i<4;i++)
    {
        RF_DATA[i] = bb_xfer(0x00);
        printf("%c",RF_DATA[i]);
    }
    printf("\n");
    pulse_CSN();
    //-----------
    bb_xfer(0xe2); //Flush RX FIFO
    pulse_CSN();
    //-----------
    bb_xfer(0x27); //reset int
    bb_xfer(0x40);
    RTX_CSN_High();
}

void transmit_Data()
{
    int i;
    RTX_CSN_High();
    RTX_CSN_Low();
//    printf("\n%u",bb_xfer(0x27)); //clear previous ints
    bb_xfer(0x27);
    bb_xfer(0x7e);
    RTX_CSN_High();;
    delay_us(20);
    RTX_CSN_Low();
    //-----------
    bb_xfer(W_REGISTER); //PWR_UP = 1
    bb_xfer(0x3a);
    RTX_CSN_High();;
    delay_us(20);
    RTX_CSN_Low();
    //-----------
    bb_xfer(0xe1); //clear TX fifo
    RTX_CSN_High();;
    delay_us(20);
    RTX_CSN_Low();
    //-----------
//    printf("\n%u",bb_xfer(0xa0)); //4 byte payload
    bb_xfer(W_TX_PAYLOAD);
    for(i=0;i<4;i++)
        {
            bb_xfer(RF_DATA[i]); //clock in payload
        }
    RTX_CSN_High();;
    RTX_CE_High();
    delay_us(50);
    RTX_CE_Low();;
}

void main()
{
    output_toggle(LED0);
    RTX_CE_Low();
    RTX_CSN_High();
    printf("\nHello\n");
    delay_ms(500);
    output_toggle(LED0);
#if defined(TX_Mode)
    configure_TX();
    delay_ms(100);

    while(true)
    {
        RF_Data[0]="1";
        RF_Data[1]="2";
        RF_Data[2]="3";
        RF_Data[3]="4";
        transmit_Data();
        output_toggle(LED0);
        delay_ms(500);
    }
#else //must be rx :)
    configure_RX();
    delay_ms(100);

    while(true)
    {
        if(!input(RF24_IRQ))
        {
            read_Data();
           
        }
       
        if(RF_Data[0]=="1")
        {
        output_toggle(LED0); }
       
        delay_ms(250);
    }
#endif
}



here sender code


Code:
/*
 * File:   main.c
 * Author: DevXP
 *
 * Created on March 8, 2013, 9:40 PM
 */
#include <16F628A.H>
#device ICD=TRUE
#device *=16
#FUSES NOWDT                    //No Watch Dog Timer
//#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O

#use delay(internal=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B2,rcv=PIN_B1,bits=8,stream=PORT1))
//---------------- change this for Rx/Tx-----------------------
//#define TX_Mode       // setup as Rx
#define TX_Mode         // setup as Tx
//-------------------------------------------------------------
#define W_REGISTER 0x20
#define R_RX_PAYLOAD 0x61
#define W_TX_PAYLOAD 0xa0
//********** DEFINE PORT NAMES
#define  SPI_MISO       PIN_A4    //RC4; SPI
#define  SPI_MOSI       PIN_A3      //RC5; SPI
#define  SPI_CLK        PIN_A2      //RC3; SPI)
#define  RF24_IRQ       PIN_B0      //RA5;  interrupcao nRF24L01+
#define  RF24_CS        PIN_A1      //RC1;  chipselect nRF24L01+
#define  RF24_CE        PIN_A0      //RC2;  chipEnable nRF24L01+
#define RF24_xfer(xdata)   bb_xfer(xdata)  //Send/receive data through SPI
#define RTX_CSN_Low()      output_low(RF24_CS)        //Controls bit Chipselect
#define RTX_CSN_High()     output_high(RF24_CS)       //Controls bit Chipselect
#define RTX_CE_Low()       output_low(RF24_CE)       //Controls bit Chipenable
#define RTX_CE_High()      output_high(RF24_CE)        //Controls bit Chipenable
#define RF24_IRQ_state()   !input(RF24_IRQ)
static int8        RF_DATA[4];
#define LED0 PIN_B4
#include <STDLIB.H>
/*******************************************************************************/
void pulse_CSN()
{
    RTX_CSN_High();;
    delay_us(20);
    RTX_CSN_Low();
}

int bb_xfer(spi_data)
{
//    SPI_MISO
//    SPI_MOSI
//    SPI_CLK
    delay_us(50);
    int rt;
    int result = 0;
    int1 d = 0;
    for(rt=0;rt<8;rt++)
    {
        d = bit_test(spi_data,7-rt);
        if(d)
        {
            output_high(SPI_MOSI);
        }
        else
        {
            output_low(SPI_MOSI);
        }
        delay_us(10);
        output_high(SPI_CLK);
        delay_us(60);
        output_low(SPI_CLK);
        delay_us(10);
        if(input(SPI_MISO))
        {
            bit_set(result,6-rt);
        }
        else
        {
            bit_clear(result,6-rt);
        }
    }
    output_low(SPI_MOSI);
    return(result);
}

void configure_TX()
{
    int i;
    RTX_CSN_Low();
    RTX_CE_Low();;
    bb_xfer(W_REGISTER); // PTX, CRC enabled, mask a couple of ints
    bb_xfer(0x38);
    pulse_CSN();
    delay_ms(2);
    //-----------
    bb_xfer(0x24); //auto retransmit off
    bb_xfer(0x00);
    pulse_CSN();;
    //-----------
    bb_xfer(0x23); //address width = 5
    bb_xfer(0x03);
    pulse_CSN();
    //-----------
    bb_xfer(0x26); //data rate = 1MB
    bb_xfer(0x07);
    pulse_CSN();
    //-----------
    bb_xfer(0x25);  //set channel 2, this is default
    bb_xfer(0x02);
    pulse_CSN();
    //-----------
    bb_xfer(0x30); //set address E7E7E7E7E7
    for(i=0;i<5;i++)
    {
        bb_xfer(0xe7);
    }
        pulse_CSN();
    //----------------
    bb_xfer(0x21); //disable auto-ack, RX mode
    bb_xfer(0x00);
    RTX_CSN_High();;
}

void configure_RX()
{
    int i;
    RTX_CSN_Low();
    RTX_CE_Low();;
    bb_xfer(W_REGISTER); //PRX, CRC enabled
    bb_xfer(0x39);
    pulse_CSN();
    delay_ms(2);
    //-----------
    bb_xfer(0x21);  //dissable auto-ack for all channels
    bb_xfer(0x00);
    pulse_CSN();
    //-----------
    bb_xfer(0x23); //address width = 5 bytes
    bb_xfer(0x03);
    pulse_CSN();
    //-----------
    bb_xfer(0x26); //data rate = 1MB
    bb_xfer(0x07);
    pulse_CSN();
    //-----------
    bb_xfer(0x31);  //4 byte payload
    bb_xfer(0x04);
    pulse_CSN();
    //-----------
    bb_xfer(0x25); //set channel 2
    bb_xfer(0x02);
    pulse_CSN();
    //-----------
    bb_xfer(0x30); //set address E7E7E7E7E7
    for(i=0;i<=5;i++)
    {
        bb_xfer(0xe7);
    }
        pulse_CSN();
    //----------------
    bb_xfer(W_REGISTER); //PWR_UP = 1
    bb_xfer(0x3b);
    RTX_CSN_High();;
    RTX_CE_High();
}

void read_Data()
{
    int i;
    RTX_CSN_Low();
    bb_xfer(R_RX_PAYLOAD); //Read RX payload
    for(i=0;i<4;i++)
    {
        RF_DATA[i] = bb_xfer(0x00);
        printf("%c",RF_DATA[i]);
    }
    printf("\n");
    pulse_CSN();
    //-----------
    bb_xfer(0xe2); //Flush RX FIFO
    pulse_CSN();
    //-----------
    bb_xfer(0x27); //reset int
    bb_xfer(0x40);
    RTX_CSN_High();
}

void transmit_Data()
{
    int i;
    RTX_CSN_High();
    RTX_CSN_Low();
//    printf("\n%u",bb_xfer(0x27)); //clear previous ints
    bb_xfer(0x27);
    bb_xfer(0x7e);
    RTX_CSN_High();;
    delay_us(20);
    RTX_CSN_Low();
    //-----------
    bb_xfer(W_REGISTER); //PWR_UP = 1
    bb_xfer(0x3a);
    RTX_CSN_High();;
    delay_us(20);
    RTX_CSN_Low();
    //-----------
    bb_xfer(0xe1); //clear TX fifo
    RTX_CSN_High();;
    delay_us(20);
    RTX_CSN_Low();
    //-----------
//    printf("\n%u",bb_xfer(0xa0)); //4 byte payload
    bb_xfer(W_TX_PAYLOAD);
    for(i=0;i<4;i++)
        {
            bb_xfer(RF_DATA[i]); //clock in payload
        }
    RTX_CSN_High();;
    RTX_CE_High();
    delay_us(50);
    RTX_CE_Low();;
}

void main()
{
    output_toggle(LED0);
    RTX_CE_Low();
    RTX_CSN_High();
    printf("\nHello\n");
    delay_ms(500);
    output_toggle(LED0);
#if defined(TX_Mode)
    configure_TX();
    delay_ms(100);

    while(true)
    {
        RF_Data[0]="1";
        RF_Data[1]="2";
        RF_Data[2]="3";
        RF_Data[3]="4";
        transmit_Data();
        output_toggle(LED0);
        delay_ms(500);
    }
#else //must be rx :)
    configure_RX();
    delay_ms(100);

    while(true)
    {
        if(!input(RF24_IRQ))
        {
            read_Data();
        }
        output_toggle(LED0);
        delay_ms(250);
    }
#endif
}


on the sender the led is blinking. But on the receiver nothing happens
Eduardo__



Joined: 23 Nov 2011
Posts: 197
Location: Brazil

View user's profile Send private message

Re: how to use in ccs only?
PostPosted: Wed Aug 05, 2015 3:48 pm     Reply with quote

How did you initialize SPI? It seems you not initialyzed correcly SPI.

e.g.:
#USE SPI(MASTER,DI=pin_C4,DO=pin_C5,CLK=pin_C3, BAUD=1000000, MODE=0, BITS=8, MSB_FIRST, STREAM=STREAM_SPI2) //this will set SPI in 4MHz(maximum for 16MHz Xtal. #Use SPI is a little buggy)


amanver wrote:
hi all.
my question is that how i use example in 4th page in ccs compiler only?(that means not use mplab or any IDE)
when i create 2 project, one for receive and another for transfer and using the codes in the 4th page and compile, in the side of rx give me errors but transfer side compile very well.

the error is:
Undefined identifier STREAM_SPI
in .c file on RF24_xfer(comm); line
can anyone help me?
thanks a'lot.
ccs v4.130
microcontroller :18f452
--------------------------------------------------------------------------
when i change the micro controller to 16f628a the error acoure it is "Internal error-Contact CCS PPUSE

_________________
Eduardo Guilherme Brandt
dezso



Joined: 04 Mar 2010
Posts: 102

View user's profile Send private message

PostPosted: Fri Aug 07, 2015 2:37 pm     Reply with quote

My spi init code is in a separate file, I'll try to locate this project and update you.
Ty
_________________
I'm could be wrong many time's, at least I know what I'm doing Smile
hassasian



Joined: 05 Jul 2015
Posts: 3

View user's profile Send private message AIM Address

thx for your reply.
PostPosted: Sat Aug 08, 2015 2:49 am     Reply with quote

I'm waiting for your answers. This is important for me. Thanks again.
dezso



Joined: 04 Mar 2010
Posts: 102

View user's profile Send private message

PostPosted: Sat Aug 08, 2015 3:08 pm     Reply with quote

After checking this code now I see that I'm not using hardware SPI, its a simple bit-bang SPI communication.
If you use the F628A chip than it should work fine, if you using different chip than please check to be sure your ports are configured properly.
_________________
I'm could be wrong many time's, at least I know what I'm doing Smile
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library All times are GMT - 6 Hours
Goto page Previous  1, 2, 3 ... 15, 16, 17, 18, 19, 20  Next
Page 16 of 20

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group