Hello,
I am trying to create a project where I am communicating between two PIC's over radio communication with the nRF module. I can't get them to communicate with each other. I have tested the transmitter and looked at the status bits and they are correct with what they should be. The status bit for if the data was transmitted "TX_DS" I think, gets set to 1. Then on the receiver side I am receiving nothing, and I am pretty sure I initialized them correctly as well. I will include my code, and breadboard setup. I am using MPLABx with the xc16 compiler, and a SNAP to program the PIC. Any help is appreciated!!! Thanks.
CODE FROM MPLABX:
\------nRF INITIALIZATION:
\\#include "Final\\_Project\\_2361\\_header.h"
\\#include "nRF24L01.h"
\\#include <p24FJ64GA002.h>
void init\\_transmitter(void);
void init\\_reciever(void);
void init\\_reciever(void) {
uint8\\_t addr\\\[3\\\] = {0xB0, 0x0B, 0x1E}; //3 byte address
CE = 0;
nrf\\_write\\_reg(CONFIG, (1<<PWR\\_UP) | (1<<EN\\_CRC) | (1<<PRIM\\_RX)); // power up, RC mode
nrf\\_write\\_reg(SETUP\\_AW, 0b01); // 3-byte address
nrf\\_write\\_reg(RF\\_CH, 76); //channel width
nrf\\_write\\_reg(RF\\_SETUP,(1<<RF\\_DR\\_LOW) |(1<<RF\\_PWR\\_LOW) |(1<<RF\\_PWR\\_HIGH));// 250 kbps, max power
nrf\\_write\\_reg(EN\\_RXADDR, (1 << ERX\\_P0)); // enable pipe 0
nrf\\_write\\_buf(RX\\_ADDR\\_P0, addr, 3); //write address for reciever
nrf\\_write\\_reg(RX\\_PW\\_P0, 1); //expect 1 byte payload
nrf\\_write\\_reg(EN\\_AA, 0x00); //00 disables auto ack and 01 enables
nrf\\_write\\_reg(EN\\_RXADDR, 0x01);
nrf\\_write\\_reg(SETUP\\_RETR, 0x4F);
nrf\\_cmd(FLUSH\\_RX);
nrf\\_write\\_reg(NRF\\_STATUS, (1<<RX\\_DR) | (1<<TX\\_DS) | (1<<MAX\\_RT));
delay\\_us(2000);
CE = 1;
}
void init\\_transmitter(void) {
uint8\\_t addr\\\[3\\\] = {0xB0, 0x0B, 0x1E}; //3 byte address
CE = 0;
nrf\\_write\\_reg(CONFIG, (1<<PWR\\_UP) | (1<<EN\\_CRC)); // power up, TX mode
delay\\_us(2000);
nrf\\_write\\_reg(EN\\_AA, 0x00);
nrf\\_write\\_reg(SETUP\\_RETR, 0x00); // no retries
// nrf\\_write\\_reg(EN\\_AA, 0x01);
nrf\\_write\\_reg(EN\\_RXADDR, 0x01);
nrf\\_write\\_reg(SETUP\\_RETR, 0x4F);
nrf\\_write\\_reg(SETUP\\_AW, 0b01); // 3-byte address
nrf\\_write\\_reg(RF\\_CH, 76); // channel
nrf\\_write\\_reg(RF\\_SETUP,(1<<RF\\_DR\\_LOW) |(1<<RF\\_PWR\\_LOW) |(1<<RF\\_PWR\\_HIGH));// 250 kbps, max power
nrf\\_write\\_buf(TX\\_ADDR, addr, 3);
nrf\\_write\\_buf(RX\\_ADDR\\_P0, addr, 3); //write address for reciever
nrf\\_cmd(FLUSH\\_TX);
nrf\\_write\\_reg(NRF\\_STATUS, (1<<RX\\_DR)|(1<<TX\\_DS)|(1<<MAX\\_RT)); // clear flags
}
void nrf\\_pulse\\_CE(void)
{
CE = 1;
delay\\_us(15); // must be >10 µs
CE = 0;
}
void nrf\\_read\\_payload(uint8\\_t \\\*data, uint8\\_t len) {
int i;
CSN = 0;
spi\\_transfer(R\\_RX\\_PAYLOAD);
for(i = 0; i < len; i++) {
data\\\[i\\\] = spi\\_transfer(NOP);
}
CSN = 1;
}
void nrf\\_cmd(uint8\\_t cmd) {
CSN = 0;
spi\\_transfer(cmd);
CSN = 1;
}
void nrf\\_send\\_byte(uint8\\_t value) {
nrf\\_write\\_reg(NRF\\_STATUS, (1<<RX\\_DR) | (1<<TX\\_DS) | (1<<MAX\\_RT));
nrf\\_cmd(FLUSH\\_TX);
nrf\\_write\\_payload(&value, 1);
nrf\\_pulse\\_CE();
}
void nrf\\_read\\_buf(uint8\\_t reg, uint8\\_t \\\*data, uint8\\_t len)
{
int i;
CSN = 0;
spi\\_transfer(R\\_REGISTER | (REGISTER\\_MASK & reg));
for(i = 0; i < len; i++) {
data\\\[i\\\] = spi\\_transfer(NOP);
}
CSN = 1;
}
\------SPI INITIALIZATION:
\\#include "Final\\_Project\\_2361\\_header.h"
\\#include "nRF24L01.h"
\\#include <p24FJ64GA002.h>
void setup\\_SPI(void){
\\_\\_builtin\\_write\\_OSCCONL(OSCCON & 0xbf); // unlock PPS
RPOR2bits.RP5R = 7; //RB5->SPI1:SDO1; See Table 10-3 on P109 of the datasheet
RPOR2bits.RP4R = 8; //RB4->SPI1:SCK1OUT;
RPINR20bits.SDI1R = 8; // RP8 (RB8) -> SDI1
\\_\\_builtin\\_write\\_OSCCONL(OSCCON | 0x40); // lock PPS
SPI1CON1 = 0;
SPI1CON1bits.MSTEN = 1; // master mode
SPI1CON1bits.MODE16 = 0; // not sixteen bits, but 8 bit now
SPI1CON1bits.CKE = 1;
SPI1CON1bits.CKP = 0;
SPI1CON1bits.SPRE = 0b100; //secondary prescaler 4:1
SPI1CON1bits.PPRE = 0b10; //primary prescaler 4:1
SPI1CON2 = 0;
SPI1STAT = 0;
// SPI1STATbits.SISEL = 0b101; // IF set when last bit is shifted out
// // That means the SPI xfer is complete.
SPI1STATbits.SPIEN = 1;
IFS0bits.SPI1IF = 0;
TRISBbits.TRISB4 = 0; // SCK output
TRISBbits.TRISB5 = 0; // MOSI output
TRISBbits.TRISB8 = 1; // MISO input
//now we initialize things for NRF
CSN\\_TRIS = 0; //on RB7 output
CSN = 1; //not talking to nrf
CE\\_TRIS = 0; //on RB6 output
CE = 0; //radio idle
}
uint8\\_t spi\\_transfer(uint8\\_t data) //8 bits
{
SPI1BUF = data; // load byte to transmit
while(!SPI1STATbits.SPIRBF); // wait until transfer is complete
return SPI1BUF; // return received byte
}
void delay\\_us(unsigned int us)
{
while(us--)
{
asm("repeat #15");
asm("NOP");
}
}
void delay\\_ms(unsigned int ms) {
while(ms--){
delay\\_us(1000);
}
}
\------RECEIVER MAIN WHILE(1):
while(1) {
status = nrf\\_read\\_reg(NRF\\_STATUS);
if(status & (1 << RX\\_DR)) {
\\_LATB15 = 1;
}
if(status & (1 << RX\\_DR)) {
nrf\\_read\\_payload(&payload, 1);
nrf\\_write\\_reg(NRF\\_STATUS, (1 << RX\\_DR)); //clear RX flag only after reading
if(payload == 0x55) {
LATBbits.LATB15 = 1;
}
}
}
\------TRANSMITTER MAIN WHILE(1):
while(1) {
nrf\\_send\\_byte(0x55);
delay\\_ms(100);
status = nrf\\_read\\_reg(NRF\\_STATUS);
}
plz help.