Here is the code of my slave, the initialization part is exactly the same as the master module, the only thing that changes is in the "nrf24l01_initialize_debug(true, 1, false);" that init the module to RX. The initialization IO part is exactly the same for master and slave...
My LED 0 blinks at startup, this means the initialization went all right. but then it seems never to get any interruption and gets stuck to " while(!(nrf24l01_irq_pin_active() && nrf24l01_irq_rx_dr_active())); "
Here is the code. I can't see what's wrong...
Code: Select all#include <p18F2620.H>
//#include <string.h>
#include <spi.h>
#include "delays.h"
#include "nrf24l01.h"
#pragma config OSC = HS//
//#pragma config FCMEN = OFF //Fail-Safe Clock Monitor disabled
//#pragma config IESO = OFF //Oscillator Switchover mode disabled
#pragma config PWRT = ON //Power-up Timer Enable
//#pragma config BOREN = OFF //Brown-out Reset disabled in hardware and software
//#pragma config BORV = 0 //Brown Out Reset Voltage: Maximum setting
#pragma config WDT = OFF //
//#pragma config WDTPS = 1 //Watchdog Timer Postscale Select 1:1
//#pragma config CCP2MX = PORTC //CCP2 input/output is multiplexed with RC1
//#pragma config PBADEN = OFF // PORTB<4:0> pins are configured as digital I/O on Reset
//#pragma config LPT1OSC = OFF //Timer1 configured for higher power operation
#pragma config MCLRE = ON //(ON)MCLR pin enabled; RE3 input pin disabled
#pragma config STVREN = ON //Stack full/underflow will not cause Reset
#pragma config LVP = OFF //Single-Supply ICSP disabled
void Initialize(void);
void InitializeIO(void);
void ToggleLED(int id); //toggle the current state of the on-board LED
//main routine
void main(void)
{
unsigned char data; //register to hold letter received and sent
Initialize(); //initialize PLL, IO, SPI, set up nRF24L01 as RX
//main program loop
while(1)
{
//wait until a packet has been received
while(!(nrf24l01_irq_pin_active() && nrf24l01_irq_rx_dr_active()));
ToggleLED(1);
nrf24l01_read_rx_payload(&data, 1); //read the packet into data
nrf24l01_irq_clear_all(); //clear all interrupts in the 24L01
DelayUS(130); //wait for the other 24L01 to come from standby to RX
nrf24l01_set_as_tx(); //change the device to a TX to send back from the other 24L01
nrf24l01_write_tx_payload(&data, 1, true); //transmit received char over RF
//wait until the packet has been sent
while(!(nrf24l01_irq_pin_active() && nrf24l01_irq_tx_ds_active()));
nrf24l01_irq_clear_all(); //clear interrupts again
nrf24l01_set_as_rx(true); //resume normal operation as an RX
}
}
//initialize routine
void Initialize(void)
{
InitializeIO(); //set up IO (directions and functions)
OpenSPI(SPI_FOSC_16, MODE_00, SMPMID); //open SPI1
nrf24l01_initialize_debug(true, 1, false); //initialize the 24L01 to the debug configuration as RX, 1 data byte, and auto-ack disabled
DelayUS(200);
ToggleLED(0);
}
//initialize IO pins
void InitializeIO(void)
{
ADCON1 = 0x0F; //disable AD converter functionality on PORTA
CMCON = 0x07; //disable comparators on PORTA
TRISAbits.TRISA0 = 0; //make PORTA.0 an output to control LED
PORTAbits.RA0 = 1; //turn on LED0
TRISAbits.TRISA1 = 0; //make PORTA.1 an output to control LED
PORTAbits.RA1 = 1; //turn on LED1
TRISBbits.TRISB7 = 1; //make sure that PORTB.7 INPUT since it is IRQ pin
TRISBbits.TRISB6 = 0; //make sure that PORTB.6 OUTPUT since it is CSN pin
TRISBbits.TRISB5 = 0; //make sure that PORTB.5 OUTPUT since it is CE pin
PORTBbits.RB6 = 1; //set CSN bit
TRISCbits.TRISC3 = 0; //make sure that PORTC.3 OUTPUT since it is SCK pin
TRISCbits.TRISC4 = 1; //make sure that PORTC.4 INPUT since it is SDI pin
TRISCbits.TRISC5 = 0; //make sure that PORTC.5 OUTPUT since it is SDO pin
TRISCbits.TRISC6 = 0; //make sure that PORTC.6 OUTPUT since it is TX pin UART
TRISCbits.TRISC7 = 1; //make sure that PORTC.7 INPUT since it is RX pin UART
//TRISC = 0x91; //make CSN, CE, SCK, MOSI (SDO), and TX outputs
}
//toggles on-board LED
void ToggleLED(int id)
{
if (id==1)
PORTAbits.RA1 = ~PORTAbits.RA1;
else
PORTAbits.RA0 = ~PORTAbits.RA0;
}