I am using CCS compiler integrated in MPLAB software and MPLAB ICD2 to debug the software and I am not atall able to communicate to nrf24L01…
This is the code I am trying… In this code I am writing to write in TX_ADDRESS and then read from it thro’ spi… But I am not getting the results… Please any help!!!
/*
** test.c
** SPI test program for PIC18F4520 and nRF24L01
*/
#include “18F452.h”
#fuses H4, NOBROWNOUT, NOWDT, NOLVP, NOPUT
#ignore_warnings 201, 204, 205
#ignore_warnings NONE
//function prototypes
unsigned char spi_Send_Read(unsigned char);
// Defines
#define SPI_SCK pin_C3 // Clock pin, PORTC pin 3
#define SPI_S0 pin_C5 // Serial output pin, PORTC pin 5
#define SPI_SI pin_C4 // Serial input pin, PORTC pin 4
#define SPI_CSN pin_B2 // CSN output pin, PORTC pin 2
#define SPI_CE pin_B3 // CE output pin, PORTC pin 1
#define SPI_IRQ pin_C6 // IRQ input pin, PORTB pin 0
#define SPI_SCALE 4 // postscaling of signal
// Macros
#define nop() _asm nop _endasm
void main(void)
{
unsigned char status = 0;
unsigned char data[5];
#asm
movlw 0x0f
movwf 0xfc1
movlw 0x10
movwf 0xf94
movlw 0xf3
movwf 0xf93
#endasm
setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_16);
//write TX_ADDRESS register
output_bit(SPI_CSN,0); //CSN low
spi_write(0x30);
spi_write(0x11);
spi_write(0x22);
spi_write(0x33);
spi_write(0x44);
spi_write(0x55);
output_bit(SPI_CSN,1); //CSN high
//read TX_ADDRESS register
output_bit(SPI_CSN,0); //CSN low
status = spi_read(0x10);
data[0] = spi_read(0x00);
data[1] = spi_read(0x00);
data[2] = spi_read(0x00);
data[3] = spi_read(0x00);
data[4] = read(0x00);
output_bit(SPI_CSN,1); //CSN high
while (1)
{
}
}