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
Here are the hardware connections:
main 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[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