NRF24L01 with PIC32MX unresponsive - Page 1
Forum section: electronics / general

author: Volta
author_rank: Newbie
timestamp: January 18, 2015, 10:28:49 pm
content: 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 expectedSDO: spi output dataCSN: starts low, gets high during transmissionSDI: NOTHINGThe delay routines are tested and pretty accurate.Could someone point me in the right direction? I am absolutely out of ideas and going slightly crazyHere are the hardware connections:main code:Code:/**///#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; // 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; //register to hold letter sent and receivedint i=0;delayMs(10);mPORTASetPinsDigitalOut(BIT_0); //ledmPORTASetPinsDigitalOut(BIT_1); //led2mPORTASetPinsDigitalOut(BIT_2); //NRF CEmPORTASetPinsDigitalOut(BIT_3); //NRF CSNmPORTBSetPinsDigitalIn(BIT_4); // NRF IRQinitSYS();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 disabledsprintf(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);// 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 RXdelayMs(1000);}}unsigned char spi_send_read_byte(unsigned char byte) {unsigned shorttxData, rxData; // transmit, receive charactersint chn = 1; // SPI channel to use (1 or 2)txData = byte; // take inputted byte and store into txDataSpiChnPutC(chn, txData);// send datarxData = SpiChnGetC(chn);// retreive over channel chn the received data into rxDatareturn 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 outputPPSUnLock; // Allow PIN MappingPPSOutput(3, RPA4, SDO1); // MAP SDO to PA4PPSInput (2, SDI1, RPB5); // MAP SDI to RPB5PPSLock; // Prevent Accidental Mappingunsigned int config = SPI_CON_MODE8|SPI_CON_SMP|SPI_CON_ON|SPI_CON_CKE;// SPI configuration wordif(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

author: Howardlong
author_rank: Super Contributor
timestamp: January 18, 2015, 10:37:35 pm
content: 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

author: Volta
author_rank: Newbie
timestamp: January 18, 2015, 11:19:01 pm
content: Yes, its off.If it wasnt, the loopback test would probably fail.Here are the config switches:Code:[// 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

author: Volta
author_rank: Newbie
timestamp: January 19, 2015, 12:21:39 pm
content: DOH! How could I have missed that!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 PIC10Well, that are the kind of mistakes you make when you're still coding at 3AMBut many thanks for pointing it out!

author: Howardlong
author_rank: Super Contributor
timestamp: January 19, 2015, 12:38:42 pm
content: Quote from: mojo-chan on January 19, 2015, 11:05:40 amNice 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.

author: Volta
author_rank: Newbie
timestamp: January 19, 2015, 01:05:47 pm
content: Yes, as far as I can test now it worksI 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.