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 support@ccsinfo.com

nRF24L01 using PIC18F2550 and CCS compiler with Brennen lib

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
thibow



Joined: 11 Apr 2012
Posts: 30

View user's profile Send private message

nRF24L01 using PIC18F2550 and CCS compiler with Brennen lib
PostPosted: Wed May 02, 2012 1:26 pm     Reply with quote

Hello,
I'm trying to get my nRF24L01+ board working with 2 Pic 18LF2550. Thank's to Brennen's library I managed to understand how it works but I am facing some building's errors as I modified some minor things to compile with CCS Compiler (Brennen uses C18).

I use to get spi working between my two PIC using wires (still with CCS Compiler), I now try to put the nRF24L01+ in between..

Here is what I changed to Brennen's library according to my compiler :
I did not include "spi.c" or "uart.h" as I don't think I need it, and I modified the spic1.c as followed
spi1.c:
Code:
//#include <spi.h>
#include <18f2550.h>
#byte SSPBUF=getenv("SFR:SSPBUF")

unsigned char spi1_send_read_byte(unsigned char byte)
{
   SSPBUF = byte;
   
   while(!spi_data_is_in());
   
   return SSPBUF;
}   


Then I managed to change every "#include #include <p18f452.h>" by "#include <18f2550.h>" and finally I tried to define IO port as follow:
Code:
#include <18f2550.h>

//defines for uC pins CE pin is connected to
//This is used so that the routines can send TX payload data and
//   properly initialize the nrf24l01 in TX and RX states.
//Change these definitions (and then recompile) to suit your particular application.
#define nrf24l01_CE_IOREGISTER      PORTC //pin_C4 10 000
#define nrf24l01_CE_PINMASK         pin_C4 //0x10

//defines for uC pins CSN pin is connected to
//This is used so that the routines can send properly operate the SPI interface
// on the nrf24l01.
//Change these definitions (and then recompile) to suit your particular application.
#define nrf24l01_CSN_IOREGISTER      PORTA // pin_A5 100 000
#define nrf24l01_CSN_PINMASK      pin_A5//0x20

//defines for uC pins IRQ pin is connected to
//This is used so that the routines can poll for IRQ or create an ISR.
//Change these definitions (and then recompile) to suit your particular application.
#define nrf24l01_IRQ_IOREGISTER      PORTC // pin_C2 100
#define nrf24l01_IRQ_PINMASK      pin_C2 //0x04

BUT, "PORTC", "PORTB", an "PORTA" are not defined in my pic18f2550.h and I don't know what to set here..
as I chosed to use the following pin for CE, CSN and IRQ
Code:
#define SPI_CSN pin_A5
#define SPI_CE pin_C4
#define SPI_IRQ pin_C2


Do you think there is anything I should change for my project to compile.. here is the code I try to compile:
Code:
#include <18F2550.H>
#include <STDLIB.H>
#include "nRF24L01.h"

#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,PLL2,CPUDIV4,NOVREGEN,NOMCLR
#use delay(clock=16000000)

#use rs232(baud=115200,parity=N,xmit=PIN_C6,rcv=PIN_C5,bits=8,STOP=1)
#define SPI_CSN pin_A5
#define SPI_CE pin_C4
#define SPI_IRQ pin_C2
#define LED1 pin_A1
#define LED0 pin_A0

char *mychar=NULL;
int i=0;
int length;
unsigned char data;

void init(void){
   //configure the device to be a master, data transmitted on H-to-L clock transition
   setup_spi(spi_master | spi_l_to_h | spi_clk_div_16 | spi_xmit_l_to_h);
   output_HIGH(LED1); //Led lit
   output_HIGH(LED0); //Led lit   
   output_HIGH(SPI_CSN); // CSN initialized
   nrf24l01_initialize_debug(false, 1, false); //initialize the 24L01 to the debug configuration as TX, 1 data byte, and auto-ack disabled
}

void main (void){
   
   init();

   while(1){
      getc();
      //delay_us(100);
      nrf24l01_write_tx_payload(&data, 1, true); //transmit received char over RF   
      //wait until the packet has been sent or the maximum number of retries has been reached
      while(!(nrf24l01_irq_pin_active() && nrf24l01_irq_tx_ds_active()));

      nrf24l01_irq_clear_all(); //clear all interrupts in the 24L01
      nrf24l01_set_as_rx(true); //change the device to an RX to get the character back from the other 24L01

      //wait a while to see if we get the data back (change the loop maximum and the lower if
      //  argument (should be loop maximum - 1) to lengthen or shorten this time frame
      for(count = 0; count < 20000; count++)
      {
         //check to see if the data has been received.  if so, get the data and exit the loop.
         //  if the loop is at its last count, assume the packet has been lost and set the data
         //  to go to the UART to "?".  If neither of these is true, keep looping.
         if((nrf24l01_irq_pin_active() && nrf24l01_irq_rx_dr_active()))
         {
            nrf24l01_read_rx_payload(&data, 1); //get the payload into data
            break;
         }
         
         //if loop is on its last iteration, assume packet has been lost.
         if(count == 19999)
            data = '?';
      }
      
      nrf24l01_irq_clear_all(); //clear interrupts again
      printf("%c", data); //print the received data (or ? if none) to the screen
   
      Delay_US(130); //wait for receiver to come from standby to RX
      nrf24l01_set_as_tx(); //resume normal operation as a TX      
   }
}



I am getting weird errors such as
"Expecting an identifier" on the line "unsigned char spi1_send_read_byte(unsigned char byte); " from my spi1.H

here it is
Code:
/*****************************************************************************
*
* File: spi1.h
*
* Copyright S. Brennen Ball, 2006-2007
*
* The author provides no guarantees, warantees, or promises, implied or
*   otherwise.  By using this software you agree to indemnify the author
*    of any damages incurred by using it.
*
*****************************************************************************/

#ifndef _SPI1_H_
#define _SPI1_H_

//#include <spi.h>

unsigned char spi1_send_read_byte(unsigned char byte);

#endif //_SPI_H_


If you have any idea..
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 02, 2012 1:50 pm     Reply with quote

Why not just get rid of that file ? All it has in it is a function prototype.
If necessary, move the prototype statement into your main program.
thibow



Joined: 11 Apr 2012
Posts: 30

View user's profile Send private message

PostPosted: Wed May 02, 2012 5:53 pm     Reply with quote

well, I managed to understand that what was wrong was the fact that this library uses variable names that are reserved (such as byte)... I'll have a closer look at Eduardo's library much more recent and made for CCS.

Here it is : http://www.ccsinfo.com/forum/viewtopic.php?t=47351
mrdongus



Joined: 18 Jun 2012
Posts: 2

View user's profile Send private message Yahoo Messenger

@thibow
PostPosted: Mon Jun 18, 2012 6:32 am     Reply with quote

Hi thibow,

I also work nRF24L01 with PIC18F2550, the same with you. I am beginner with both of them.
Could you share code and your email with me !

Thank you ! Smile
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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