CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Setting SPI of 18F2550 for nRF24L01+ full driver by Eduardo
Goto page Previous  1, 2, 3, 4  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PannetierJ



Joined: 18 Jun 2017
Posts: 31

View user's profile Send private message

PostPosted: Sun Jul 16, 2017 2:05 pm     Reply with quote

I join you the schematic :

PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jul 16, 2017 3:52 pm     Reply with quote

The schematic looks OK.

While reviewing the schematic, I noticed that I made a mistake in the
program. I had the Rx pin for the hardware UART enabled, when pin C7
is used for the MOSI pin. I have modified the #use rs232() line below
to use only pin C6, as a soft UART for Tx only. Try this program on
the Transmit board:
Code:

// Register r/w test for the Transmitter board

#include <18F2550.h>
#device = PASS_STRINGS=IN_RAM    //Admite ponteiros para constantes
#fuses HS,NOWDT,NOLVP,CPUDIV1
#use delay(clock=16000000)
#use rs232(baud=9600,xmit=PIN_C6)  // *** Software i2c for Tx only

#define RF24_SPI_DISABLE_WARNING  //for disabling nRF24 SPI warning message.

#define Led_Send PIN_A3
#define Led_Init PIN_A4
//********** DEFINE PORT NAMES
#define  SPI_MISO       PIN_B0   //SPI(Usar por hardware quando possivel)
#define  SPI_MOSI       PIN_C7   //SPI(Usar por hardware quando possivel)
#define  SPI_CLK        PIN_B1   //SPI(Usar por hardware quando possivel)

//Driver nRF24L01P.C
#define  RF24_IRQ       PIN_B2   //interrupcao nRF24L01+
#define  RF24_CS        PIN_C1   //chipselect nRF24L01+
#define  RF24_CE        PIN_C2   //chipEnable nRF24L01+
#define  RF24_PERFORMANCE_MODE   //performance mode ON
#define  RF24_SPI       STREAM_SPI2//Redirects SPI2 port to RS24_SPI stream

#use SPI(MASTER,DI=SPI_MISO,DO=SPI_MOSI,CLK=SPI_CLK,BAUD=1000000,MODE=0,BITS=8,MSB_FIRST,STREAM=STREAM_SPI2)

#include <nRF24L01P.C>   

//==============================
void main()
{
int8 result;

printf("Start\n\r");
   
RF24_initPorts();

RF24_disable();     

RF24_comm(W_REGISTER|SETUP_AUTORETRANSMISSION, 0x55); // Write 0x55 to Retry reg
result = RF24_comm_in(R_REGISTER|SETUP_AUTORETRANSMISSION);  // Read it back
printf("Wrote: 0x55, Read: %x \n\r", result);   // Display it

RF24_comm(W_REGISTER|SETUP_AUTORETRANSMISSION, 0xAA); // Write 0xAA to Retry reg
result = RF24_comm_in(R_REGISTER|SETUP_AUTORETRANSMISSION);  // Read it back
printf("Wrote: 0xAA, Read: %x \n\r", result);   // Display it
printf("\n\rTest done \n\r");
 
while(TRUE);
Ttelmah



Joined: 11 Mar 2010
Posts: 19244

View user's profile Send private message

PostPosted: Mon Jul 17, 2017 1:17 am     Reply with quote

Just a quick update/suggestion to this.
I don't see anywhere what compiler version is being used?. Probably just missed it. However there was a problem some time ago, that if the fuse NOPBADEN wasn't selected, on a few compiler versions you got problems with using the portB pins for digital I/O unless you explicitly disabled the analog on these pins.
So I'd suggest adding this fuse to PCM_programmers code.
temtronic



Joined: 01 Jul 2010
Posts: 9124
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Jul 17, 2017 4:51 am     Reply with quote

One item I didn't see on the schematic is a pullup resistor for the IRQ line of the nRF module.
Historically any I/O pin that can be 'multisourced' like I2C bus and interrupts were 'open collector' and so need a pullup. I do recall that the nRF module I used 3-4 years ago did not have a pullup(saved mfr 1 cent ?),so I'd check yours just to confirm/deny one exists.
Also the module does draw a lot of power during transmit so I'd have 1000mfd on the output of the regulator( 2 x 500mfd). Without a real good energy reserve( big caps ) ,VDD can 'dip', maybe not enough to trigger brownout but could cause weird,random problems.

just food for thought...

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19244

View user's profile Send private message

PostPosted: Mon Jul 17, 2017 6:33 am     Reply with quote

I wondered about this, but a search found:

<https://electronics.stackexchange.com/questions/149110/is-the-nrf24l01-irq-line-open-collector>

However the supply is definitely worth looking at. Another poster having a similar problem online found the chip was getting reset during TX.
The consumption is not high (only a few mA), but the rate of change of demand is very high, so a good ceramic 22uF close to the pins feeding the module, is a very good idea.

Look at the final result of this thread:

<https://forum.sparkfun.com/viewtopic.php?f=13&t=8062>
Ttelmah



Joined: 11 Mar 2010
Posts: 19244

View user's profile Send private message

PostPosted: Mon Jul 17, 2017 9:24 am     Reply with quote

and another thing.

Add a 100mSec delay before calling the initialisation.

If you look at the chip state machine, it takes 100mSec to go from power being applied to being in the undefined 'ready to wake' state. Wonder if other users have all been using something like an LCD, where you typically have to wait for a good fraction of a second for it to be ready, before starting the operational code.
PannetierJ



Joined: 18 Jun 2017
Posts: 31

View user's profile Send private message

PostPosted: Mon Jul 17, 2017 10:47 am     Reply with quote

I'll test your suggestions in the week.

If I understand temtronic, I must add a pull-up on IRQ Line ?
And add 100ms before init.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 18, 2017 8:36 pm     Reply with quote

I ordered an nRF24L01P+ board, hooked it up and it works. It passed
the register read/write test. I ordered the Longruner NRF24L01+ boards
from Amazon, simply because they were cheap ($6.99 USD for three)
and the reviews said they worked. Their image shows a silkscreen, but
the delivered boards are missing the silkscreen. But it didn't matter.

Here are the results from TeraTerm:
Quote:

Start
Wrote: 0x55, Read: 55
Wrote: 0xAA, Read: aa

Test done

Here's a photo of my test setup. This board is running at +3.3v and
has a 16LF1847 on it. I compiled it with CCS vs. 5.071. I used the
16LF1847 because that was an LF PIC that I had in stock.


Code:
// Register r/w test for the Transmitter board

#include <16F1847.h>
#device PASS_STRINGS=IN_RAM     
#fuses INTRC_IO,NOWDT,NOLVP
#use delay(internal=16M)
#use rs232(baud=9600,xmit=PIN_A0)  // Use soft UART for Tx to PC

#define RF24_SPI_DISABLE_WARNING   

// These are the connections I used with a 16LF1847:
#define  SPI_MISO       PIN_B1   
#define  SPI_MOSI       PIN_B2   
#define  SPI_CLK        PIN_B4   

#define  RF24_IRQ       PIN_B0   
#define  RF24_CS        PIN_B5   
#define  RF24_CE        PIN_B3   

#define  RF24_PERFORMANCE_MODE   
#define  RF24_SPI       STREAM_SPI2

#use SPI(MASTER,DI=SPI_MISO,DO=SPI_MOSI,CLK=SPI_CLK,BAUD=1000000,MODE=0,BITS=8,MSB_FIRST,STREAM=STREAM_SPI2)

#include <nRF24L01P.C>    // From CCS Code Library forum

//==============================
void main()
{
int8 result;

delay_ms(100);

printf("Start\n\r");
   
RF24_initPorts();

RF24_disable();     

RF24_comm(W_REGISTER|SETUP_AUTORETRANSMISSION, 0x55); // Write 0x55 to Retry reg
result = RF24_comm_in(R_REGISTER|SETUP_AUTORETRANSMISSION);  // Read it back
printf("Wrote: 0x55, Read: %x \n\r", result);   // Display it

RF24_comm(W_REGISTER|SETUP_AUTORETRANSMISSION, 0xAA); // Write 0xAA to Retry reg
result = RF24_comm_in(R_REGISTER|SETUP_AUTORETRANSMISSION);  // Read it back
printf("Wrote: 0xAA, Read: %x \n\r", result);   // Display it
printf("\n\rTest done \n\r");
 
while(TRUE);
PannetierJ



Joined: 18 Jun 2017
Posts: 31

View user's profile Send private message

PostPosted: Wed Jul 19, 2017 1:46 am     Reply with quote

Hi PCM Programmer,

I like this sound.
I have a question about your schematic.
I noticed that you add a resistor, in the left on Pic.
It's a pull-up for IRQ Line ?

I'll do others tests this weekend.

Thank you for your time.
Ttelmah



Joined: 11 Mar 2010
Posts: 19244

View user's profile Send private message

PostPosted: Wed Jul 19, 2017 3:03 am     Reply with quote

As another comment, I still note you are showing Vusb left floating (PCM_programmer is using a PIC without this). Look at this thread:

<https://electronics.stackexchange.com/questions/27093/seemingly-unstable-basic-pic18f2550-circuit>

It is really silly to be using a USB PIC if you are not using it's USB abilities. Wastes pins. If you are running at 3.3v, then Vusb can be tied to the 3.3v rail. If not it really must have the capacitor.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 19, 2017 8:45 am     Reply with quote

There is no IRQ resistor. I'm doing an SPI r/w test. I don't even have
IRQ connected. The nRF24L01+ data sheet doesn't say that IRQ is
an open-drain pin. None of the schematics out there show a pull-up
on that pin. It's not required.

The resistor in my photo is the MCLR pull-up resistor. The capacitor is
the bypass cap for the PIC's Vdd pin.

I really suspect you have a connection problem. It will be that you have:
1. Swapped two signals, such as MISO and MOSI or CE and CSN.
-or-
2. You have misinterpreted the connector pin numbering, such as
swapping the two columns.

Either of those is equally likely. I will bet you did one of them.

You must get the SPI communication working before you can do anything
else. So find the bug.
PannetierJ



Joined: 18 Jun 2017
Posts: 31

View user's profile Send private message

PostPosted: Wed Jul 19, 2017 9:33 am     Reply with quote

Hy,

Good news.
I'll test this quickly (Without IRQ, if i understand, connected), same version of CCS.
PannetierJ



Joined: 18 Jun 2017
Posts: 31

View user's profile Send private message

PostPosted: Wed Jul 19, 2017 11:01 am     Reply with quote

PCM Programmer,
Did you take the driver of nRF24L01P.C on page #1 ? of this subject.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 19, 2017 11:58 am     Reply with quote

You mean the link to the Code Library ? Yes. I had to do a small number
of edits to get it to compile. But I'm sure you have already done those.
The edits are given in various posts starting on this page:
http://www.ccsinfo.com/forum/viewtopic.php?t=47351&start=268
PannetierJ



Joined: 18 Jun 2017
Posts: 31

View user's profile Send private message

PostPosted: Sat Jul 22, 2017 2:48 am     Reply with quote

Hi PCM Programmer,

Now I have CCS 5.008.

I tried to import the driver nRF24L01P.h and nRF24L01P.c.
I modified this driver the last commands into the forum.
Nevertheless, it seems to have some errors into my modification.

Could you post your nRF24L01P.h and nRF24L01P.c which you use ?
To be ok on the version.

Best regard
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3, 4  Next
Page 3 of 4

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group