|
|
View previous topic :: View next topic |
Author |
Message |
PannetierJ
Joined: 18 Jun 2017 Posts: 31
|
Setting SPI of 18F2550 for nRF24L01+ full driver by Eduardo |
Posted: Sun Jul 09, 2017 8:30 am |
|
|
Hello,
I'm using a NRF24l01 ( SPI component ) with the driver by Eduardo Guilherme Brandt
https://www.ccsinfo.com/forum/viewtopic.php?t=47351
I have a module transmitter and Receiver.
I don't receive my message.
I'm checking with my oscilloscope. I have data on MOSI bus. The data seems be sent correctly. I send "Hello World "
Code of Transmitter:
Code: |
#include <18F2550.h>
#DEVICE *=16 /*ICD=TRUE*/
#device = PASS_STRINGS=IN_RAM //Admite ponteiros para constantes
#fuses HS,NOWDT,NOLVP,CPUDIV1
#use delay(clock=16000000)
#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)
//INCLUDES_2 - Drivers
#include <nRF24L01P.C> //Driver nRF24L01+ Single Chip 2.4GHz Transceiver Driver
//INCLUDES_3
#include <STDLIB.H>
void main()
{
output_high(Led_Init);
RF24_initPorts();
RF24_default_config();
RF24_TX_SET(); //Transmitter on
output_low(Led_Init);
while(true)
{
output_high(Led_Send);
RF24_TX_putbuffer(false,11,"Hello World");
output_low(Led_Send);
delay_ms(500);
}
}
|
Code of my Receiver
Code: |
#include <18F2550.h>
#DEVICE *=16 /*ICD=TRUE*/
#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,rcv=PIN_C7,ERRORS)
#define RF24_SPI_DISABLE_WARNING //for disabling nRF24 SPI warning message.
//********** DEFINE PORT NAMES
#define SPI_MISO PIN_B0 //SPI(Usar por hardware quando possivel)
#define SPI_MOSI PIN_B3 //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)
//INCLUDES_2 - Drivers
#include <nRF24L01P.C> //Driver nRF24L01+ Single Chip 2.4GHz Transceiver Driver
//INCLUDES_3
#include <STDLIB.H>
void main()
{
int RXbuffer1[11];
int RXdatasize, RXpipe;
printf("Initialisation of system in progress\r\n");
RF24_initPorts();
RF24_default_config();
RF24_RX_SET(); //Transmitter on
printf("Initialisation of system\r\n");
RF24_RX_SET(); //Receiver on
while(true) {
while ( RF24_RX_getbuffer(&RXpipe, &RXdatasize, RXbuffer1)!=true );
printf(RXBuffer1[0]);
}
}
|
I checked the data on my transmitter: MOSI bus:
The data seems be sent correctly. I send Hello World.
Nevertheless, I don't receive my data on my Receiver.
I know that the config of SPI is really important. I tried different config without success.
Thank you |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Sun Jul 09, 2017 9:50 am |
|
|
Basic hardware question.
Are you running a 5 volt PIC and a 3V NRF device ?
'Most' peripherals these days are 3 volt units so unless you've got a 3V PIC, you'll probably need some 'logic level conversion' in between.
You should post what device (or module) you are using. |
|
|
PannetierJ
Joined: 18 Jun 2017 Posts: 31
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jul 09, 2017 10:26 am |
|
|
Your #include line for your PIC shows you are using the 18F2550.
According to the 18F2550 data sheet,
http://ww1.microchip.com/downloads/en/DeviceDoc/39632e.pdf
the 18F2550 will only work reliably at 4.2v or above. See:
Quote: | FIGURE 28-1: PIC18F2455/2550/4455/4550 VOLTAGE-FREQUENCY GRAPH (INDUSTRIAL)
|
It's on page 370 in the Acrobat reader.
To run it reliably at 3.3v, you need to use the "LF" version of the PIC. |
|
|
PannetierJ
Joined: 18 Jun 2017 Posts: 31
|
|
Posted: Sun Jul 09, 2017 10:48 am |
|
|
Hi PCM programmer,
I understand.
I'm reading now the datasheet.
Nervertheless,
I can't explain why my receiver's working on RS232 @ 3,3 V / my transmitter's working -> it seems write on my SPI @ 3,3 V.
It's strange, isn't it ?
If the PIC18F2550's working only @ 4,2 V . I would have no life of the whole: bad data on RS232 ....
I'm using a quartz not internal RC
page 390 of Data sheet.
Your answer is when we using a internal RC oscillator.
I think.
Last edited by PannetierJ on Sun Jul 09, 2017 10:57 am; edited 1 time in total |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1907
|
|
Posted: Sun Jul 09, 2017 10:55 am |
|
|
That's not the point - if you're running a PIC at less than the minimum rated voltage, don't be surprised if it acts strangely. One peripheral operating properly (the UART) does not mean that a different peripheral (the MSSP) will also operate properly.
Replace your processor with an 18LF2550, then see what happens. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19510
|
|
Posted: Sun Jul 09, 2017 11:24 am |
|
|
PannetierJ wrote: | Hi PCM programmer,
I understand.
I'm reading now the datasheet.
Nervertheless,
I can't explain why my receiver's working on RS232 @ 3,3 V / my transmitter's working -> it seems write on my SPI @ 3,3 V.
It's strange, isn't it ?
If the PIC18F2550's working only @ 4,2 V. I would have no life of the whole : bad data on RS232 ....
I'm using a quartz not internal RC
page 390 of Data sheet.
Your answer is when we using a internal RC oscillator .
I think. |
No.
It is not the oscillator that sets the limit. It is the general abilities of the PIC itself.
Many parts of a PIC will operate beyond their specification, but the specified minimum voltage is the limit at which all are guaranteed to work.
It is quite possible that 9 out of ten parts of the PIC will run find, but the sort of things that start happening when you go 'out of spec', are individual peripherals not working quite right. Could well be your problem..... |
|
|
PannetierJ
Joined: 18 Jun 2017 Posts: 31
|
|
Posted: Sun Jul 09, 2017 12:14 pm |
|
|
I ordered 18LF
I hope that it'll resolve this problem |
|
|
PannetierJ
Joined: 18 Jun 2017 Posts: 31
|
|
Posted: Fri Jul 14, 2017 1:50 am |
|
|
Hello guys ,
I received my pics. I replaced my receiver by 18LF2520 and transmitter by 18LF2550.
It's LF now.
I have the same result.
I receive nothing....
Is it a problem of SPI config ? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jul 14, 2017 6:29 am |
|
|
Quote: | void main()
{
int RXbuffer1[11];
int RXdatasize, RXpipe;
printf("Initialisation of system in progress\r\n");
RF24_initPorts();
RF24_default_config();
RF24_RX_SET(); //Transmitter on *** Extra call ***
printf("Initialisation of system\r\n");
RF24_RX_SET(); //Receiver on
while(true) {
while ( RF24_RX_getbuffer(&RXpipe, &RXdatasize, RXbuffer1)!=true );
printf(RXBuffer1[0]);
}
} |
1. You have an extra call to RF24_RX_SET(), shown in bold above.
This extra call is not in Eduardo's sample Rx program. I think you
should remove it.
2. RF24_RX_SET() does have a return code. I realize it's just a power
indication, but you should display it, just to make sure it's correct.
3. You have a printf(RXBuffer1[0]) statement at the end. This won't
printf the received data. Maybe that's your entire problem.
You should use this code to display the received data (if any):
Code: |
printf("Number of bytes received = %u \n\r", RXdatasize);
for(i=0; i < RXdatasize; i++)
printf("%c", RXbuffer1[i]);
printf("\n\r");
|
Also add this declaration at the start of main():
|
|
|
PannetierJ
Joined: 18 Jun 2017 Posts: 31
|
|
Posted: Fri Jul 14, 2017 7:06 am |
|
|
Hi PCM,
You're right.
I had have an extra call to RF24_RX_SET().
I deleted this .
I catch the return of my function RF24_RX_SET() :
And I have an error : number 2
code of main prog :
Code: |
#include <18F2520.h> //18LF2520 is using
#DEVICE *=16 /*ICD=TRUE*/ PASS_STRINGS=IN_RAM /*HIGH_INTS=TRUE*/ //Admite ponteiros para constantes
#fuses HS,NOWDT,NOLVP
#use delay(clock=16000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,ERRORS)
//#use SPI(SPI2,MASTER,BAUD=1000000, MODE=0,BITS=8,MSB_FIRST,STREAM=STREAM_SPI2)
#define RF24_SPI_DISABLE_WARNING //for disabling nRF24 SPI warning message.
//********** DEFINE PORT NAMES
#define SPI_MISO PIN_B0 //SPI(Usar por hardware quando possivel)
#define SPI_MOSI PIN_B3 //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=RF24_SPI)
//#use SPI(MASTER,SPI1, BAUD=1000000,MODE=0,BITS=8,MSB_FIRST,STREAM=RF24_SPI)
#use SPI(MASTER,DI=SPI_MISO,DO=SPI_MOSI,CLK=SPI_CLK,BAUD=1000000,MODE=0,BITS=8,MSB_FIRST,STREAM=STREAM_SPI2)
//INCLUDES_2 - Drivers
#include <nRF24L01P.C> //Driver nRF24L01+ Single Chip 2.4GHz Transceiver Driver
//INCLUDES_3
#include <STDLIB.H>
void main()
{
int RXbuffer1[11];
int RXdatasize, RXpipe;
int i;
int Result;
printf("Initialisation of system in progress\r\n");
RF24_initPorts();
RF24_default_config();
Result=RF24_RX_SET(); //Receiver on
if(Result==1)
printf("Config RX Ok\r\n");
else
{
printf("Config RX KO\r\n");
printf(" Result : %d\r\n",Result);
}
printf("Initialisation of system\r\n");
while(true) {
while( RF24_RX_getbuffer(&RXpipe, &RXdatasize, RXbuffer1)!=true );
printf("Number of bytes received = %u \n\r",RXdatasize);
for(i=0;i<RXdatasize;i++)
printf("%c",RXbuffer1[i]);
printf("\n\r");
}
}
|
And into the function RF24_RX_SET() :
Code: |
int RF24_RX_SET() { //Enhanced ShockBurst receiving payload(return 1 if ok, return other number if error)
int i,data;
i = RF24_comm_in(R_REGISTER|FIFO_STATUS);
if ((i&RX_FULL)==RX_FULL) return 0; //Error: RX FIFO buffer full flag, must be read before receive new packets(REVISION 1.1)
//
data = RF24_comm_in(R_REGISTER|CONFIGURATION);
if ((data&PWR_UP)!=PWR_UP) return 0x02; //Error: Turn PWR_UP on before transmit
data|=PRIM_RX; //1. Select RX by setting the PRIM_RX bit in the CONFIG register to high.
RF24_comm(W_REGISTER|CONFIGURATION, data);
/*
All data pipes that receive
data must be enabled (EN_RXADDR register), enable auto acknowledgement for all pipes running
Enhanced ShockBurst (EN_AA register), and set the correct payload widths (RX_PW_Px registers).
Set up addresses as described in item 2 in the Enhanced ShockBurst transmitting payload
example above.
*/
RF24_enable(); //2. Start Active RX mode by setting CE high.
// //3. After 130µs nRF24L01+ monitors the air for incoming communication.
/*4. When a valid packet is received (matching address and correct CRC), the payload is stored in the
RX-FIFO, and the RX_DR bit in STATUS register is set high. The IRQ pin is active when RX_DR is
high. RX_P_NO in STATUS register indicates what data pipe the payload has been received in.
5. If auto acknowledgement is enabled, an ACK packet is transmitted back, unless the NO_ACK bit
is set in the received packet. If there is a payload in the TX_PLD FIFO, this payload is added to
the ACK packet.*/
//RF24_disable(); //6. MCU sets the CE pin low to enter standby-I mode (low current mode).
// //7. MCU can clock out the payload data at a suitable rate through the SPI.
// //8. nRF24L01+ is now ready for entering TX or RX mode or power down mode.
return true; //Success
}//
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jul 14, 2017 7:49 am |
|
|
What are you using for a power supply ? What capacitors do you have
on the power supply voltage going to the nRF24L01 boards ? |
|
|
PannetierJ
Joined: 18 Jun 2017 Posts: 31
|
|
Posted: Fri Jul 14, 2017 8:02 am |
|
|
I have a power supply with USB -> regulator 3,3V.
I have a capacitor on my regulator of 10uF.
I checked my voltage on NRF24L01.
I have 3,28V. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19510
|
|
Posted: Fri Jul 14, 2017 8:19 am |
|
|
What is on the Vusb pin?.
'A capacitor of 10uF', says very little. Ceramic, or electrolytic?. If electrolytic, it _must_ be paralleled by a small ceramic capacitor (has poor HF perfromance otherwise). There should also be a similar ceramic adjacent to the NRF24L01. The capacitors should be withing a very few mm of the power pins.
Do you have all the power pins connected?. They need to be.
The PIC can oscillate internally if there is not a capacitor on the Vusb connection (even if USB is not being used). |
|
|
PannetierJ
Joined: 18 Jun 2017 Posts: 31
|
|
Posted: Fri Jul 14, 2017 8:52 am |
|
|
Hy Ttelmah,
It's electrolytic capacitor.
I have just seen some forum: Arduino ...
Actually, some adds a tantalum capacitor directly on nrf24l01.
I'll test ... |
|
|
|
|
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
|