Author Topic: NRF24L01 with PIC32MX unresponsive  (Read 4090 times)

0 Members and 1 Guest are viewing this topic.

Offline VoltaTopic starter

  • Newbie
  • Posts: 5
NRF24L01 with PIC32MX unresponsive
« on: January 18, 2015, 10:28:49 pm »
Hello,

I have been pulling my hair out the last couple of days trying to get a nrf24L01+ connected to a PIC32MX270F256B to just set and get the config and status register.

No matter what I do, i just read 0 from both config and status registers. Exactly the same as if the NRF is not connected at all!
I Triple-quadruple checked all of the pin connections, power supply, spi config, tried other nrf modules, with and without a breakout board all no luck.
The spi loopback test succeeds.
If I probe the spi pins with my scope i get:
SCK: a about 610kHz 8 bit clock pulse as expected
SDO: spi output data
CSN: starts low, gets high during transmission
SDI: NOTHING  :(

The delay routines are tested and pretty accurate.

Could someone point me in the right direction? I am absolutely out of ideas and going slightly crazy  |O

Here are the hardware connections:


main code:
Code: [Select]
/*
 */



//#include "HardwareProfile.h"
#include <xc.h>
#include <plib.h>

#include "nrf24l01.h"

#include "system.h"

void SpiInitDevice(int,int,int,int);
unsigned char spi_send_read_byte(unsigned char byte);
char RS232_Out_Buffer[64]; // buffer for printing data to the screen via UART

#define BYTETOBINARYPATTERN "%d%d%d%d%d%d%d%d \r\n"
#define BYTETOBINARY(byte)  \
  (byte & 0x80 ? 1 : 0), \
  (byte & 0x40 ? 1 : 0), \
  (byte & 0x20 ? 1 : 0), \
  (byte & 0x10 ? 1 : 0), \
  (byte & 0x08 ? 1 : 0), \
  (byte & 0x04 ? 1 : 0), \
  (byte & 0x02 ? 1 : 0), \
  (byte & 0x01 ? 1 : 0)

int main(void){

        SYSTEMConfig(GetSystemClock(), SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);

int width=32;
char data[width]; //register to hold letter sent and received
int i=0;

        delayMs(10);
       
        mPORTASetPinsDigitalOut(BIT_0); //led
        mPORTASetPinsDigitalOut(BIT_1); //led2
        mPORTASetPinsDigitalOut(BIT_2); //NRF CE
        mPORTASetPinsDigitalOut(BIT_3); //NRF CSN
        mPORTBSetPinsDigitalIn(BIT_4); // NRF IRQ



        initSYS();
InitApp();
        INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);
        SpiInitDevice(1,1,0,0);
nrf24l01_initialize_debug(true, width, false); //initialize the 24L01 to the debug configuration as RX, 1 data byte, and auto-ack disabled
 
sprintf(RS232_Out_Buffer,"*** Reciever Intialized (%i)*** \r\n", width);
putsUART2(RS232_Out_Buffer);
           

while(1)
{
nrf24l01_initialize_debug(true, width, false);
                //delayMs(10);
//while(!(nrf24l01_irq_pin_active() && nrf24l01_irq_rx_dr_active()));//has to be &&!

                //while(!nrf24l01_irq_pin_active());
mPORTAToggleBits(BIT_0);

//nrf24l01_read_rx_payload(data, width); //get the payload into data
//nrf24l01_irq_clear_all(); //clear interrupts again

//for (i=0; i<width; i++){
//sprintf(RS232_Out_Buffer,"%c",data[i]);
                //    putsUART2(RS232_Out_Buffer);
//}
//putsUART2("\r\n");

                //printf("lbt: %c\r\n", spi_send_read_byte('a'));
               
                printf("Nrf_Conf: "BYTETOBINARYPATTERN, BYTETOBINARY(nrf24l01_get_config()));
                printf("Nrf_Stat: "BYTETOBINARYPATTERN, BYTETOBINARY(nrf24l01_nop()));

//delayUs(100); //wait for receiver to come from standby to RX
                delayMs(1000);
}
}


 unsigned char spi_send_read_byte(unsigned char byte) {
  unsigned short txData, rxData; // transmit, receive characters
    int chn = 1; // SPI channel to use (1 or 2)
 
    txData = byte; // take inputted byte and store into txData   
    SpiChnPutC(chn, txData); // send data
  rxData = SpiChnGetC(chn); // retreive over channel chn the received data into rxData
   
  return rxData;
 }

 void SpiInitDevice(int chn, int isMaster, int frmEn, int frmMaster) {

   //mPORTASetPinsDigitalOut(BIT_4);      // Set PA4(SDO) as output
   ///mPORTBSetPinsDigitalIn (BIT_5);      // Set PB5(SDI) as input
   //mPORTBSetPinsDigitalOut(BIT_14);      // Set PA4(SCL) as output


    PPSUnLock;                    // Allow PIN Mapping
      PPSOutput(3, RPA4, SDO1);  // MAP SDO to PA4
      PPSInput (2, SDI1, RPB5);  // MAP SDI to RPB5
    PPSLock;                      // Prevent Accidental Mapping

     unsigned int config = SPI_CON_MODE8|SPI_CON_SMP|SPI_CON_ON|SPI_CON_CKE; // SPI configuration word
     if(isMaster){
             config|=SPI_CON_MSTEN;
     }
     if(frmEn){
             config|=SPI_CON_FRMEN;
             if(!frmMaster) {
                     config|=SPI_CON_FRMSYNC;
            }
     }
     SpiChnOpen(chn, config, 8);  // divide fpb by 2, configure the I/O ports. Not using SS
 }
 
removing/adding SPI_CON_CKE does not help.
NRF source and header attathed, as they are quite large
« Last Edit: January 18, 2015, 10:31:35 pm by Volta »
 

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5313
  • Country: gb
Re: NRF24L01 with PIC32MX unresponsive
« Reply #1 on: January 18, 2015, 10:37:35 pm »
Have you switched off the PIC's JTAG port? By default, it's on. RB5/SDI will remain low if not.

From memory:

#pragma config JTAGEN=OFF
 

Offline VoltaTopic starter

  • Newbie
  • Posts: 5
Re: NRF24L01 with PIC32MX unresponsive
« Reply #2 on: January 18, 2015, 11:19:01 pm »
Yes, its off.
If it wasnt, the loopback test would probably fail.
Here are the config switches:
Code: [Select]
[// DEVCFG3
// USERID = No Setting
#pragma config PMDL1WAY = OFF           // Peripheral Module Disable Configuration (Allow multiple reconfigurations)
#pragma config IOL1WAY = OFF            // Peripheral Pin Select Configuration (Allow multiple reconfigurations)

// DEVCFG1
#pragma config FNOSC = FRCPLL           // Oscillator Selection Bits
#pragma config FSOSCEN = OFF             // Secondary Oscillator Enable (Enabled)
#pragma config IESO = OFF                // Internal/External Switch Over (Enabled)
#pragma config OSCIOFNC = OFF           // CLKO Output Signal Active on the OSCO Pin (Disabled)
#pragma config FPBDIV = DIV_8           // Peripheral Clock Divisor (Pb_Clk is Sys_Clk/1) FULL POWAH
#pragma config FCKSM = CSECME           // Clock Switching and Monitor Selection (Clock Switch Enable, FSCM Enabled)
#pragma config WDTPS = PS1048576        // Watchdog Timer Postscaler (1:1048576)
#pragma config WINDIS = OFF             // Watchdog Timer Window Enable (Watchdog Timer is in Non-Window Mode)
#pragma config FWDTEN = OFF             // Watchdog Timer Enable (WDT Disabled (SWDTEN Bit Controls))
//IESO Test

#pragma config   FPLLIDIV = DIV_2
#pragma config   FPLLMUL = MUL_20
#pragma config   FPLLODIV = DIV_2

// DEVCFG0
#pragma config JTAGEN = OFF             // JTAG Enable (JTAG Disabled)
#pragma config ICESEL = ICS_PGx1        // ICE/ICD Comm Channel Select (Communicate on PGEC1/PGED1)
/*
#pragma config PWP = OFF                // Program Flash Write Protect (Disable)
#pragma config BWP = OFF                // Boot Flash Write Protect bit (Protection Disabled)
#pragma config CP = OFF                 // Code Protect (Protection Disabled)
*/

#pragma config DEBUG = ON[

Tomorrow I will try to write the registers directly without the library and see what that does
« Last Edit: January 18, 2015, 11:26:59 pm by Volta »
 

Offline VoltaTopic starter

  • Newbie
  • Posts: 5
Re: NRF24L01 with PIC32MX unresponsive
« Reply #3 on: January 19, 2015, 12:21:39 pm »
DOH! How could I have missed that!  :palm:
I know what CSN is, have used SPI many times before, even written a software SPI in assembly for a tiny 6-pin SOT-23 PIC10
Well, that are the kind of mistakes you make when you're still coding at 3AM

But many thanks for pointing it out!
 

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5313
  • Country: gb
Re: NRF24L01 with PIC32MX unresponsive
« Reply #4 on: January 19, 2015, 12:38:42 pm »
CSN: starts low, gets high during transmission

CSN is supposed to be normally high, then low during SPI comms. CSN stands for "Chip Select Negative", as in it is a chip select line that is active low. It's a common convention.

Nice spot, MC.

Does this work now? I have a breadboard setup with a PIC32MX270F256B on it ready to go if not. I don't have an nrf device, but I could check the SPI for you without that.
 

Offline VoltaTopic starter

  • Newbie
  • Posts: 5
Re: NRF24L01 with PIC32MX unresponsive
« Reply #5 on: January 19, 2015, 01:05:47 pm »
Yes, as far as I can test now it works
I need to build a transmitter before the reciever is of any use, obviously, but at least the NRF's registers appear to get set and read properly and the MISO line is transmitting data!
Tomorrow the mailman should come in with a nice big box of parts and I can continue testing.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf