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.
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:
//#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:
#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… :think:
as I chosed to use the following pin for CE, CSN and IRQ
#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:
#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
/*****************************************************************************
*
* 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… :!: