gnulnulf
Posts: 32
Joined: Sat Oct 06, 2012 12:04 pm

Re: NRF24L01 RF Transceiver

Tue Mar 12, 2013 9:21 pm

After changing the CE/CSN and setting the csn to 8 again it's more stable..

Code: Select all

Now sending 380111...ok...Got response 380111, round-trip delay: 32
Now sending 381145...ok...Got response 381145, round-trip delay: 31
Now sending 382177...ok...Got response 382177, round-trip delay: 33
Now sending 383210...ok...Got response 383210, round-trip delay: 37
Now sending 384247...ok...Got response 384247, round-trip delay: 32
I thought the rpi would control the CE0 (gpio8) when accessing the /dev/spidev0.0
maybe a SPI mode option in spi.cpp?

stanley
Posts: 33
Joined: Fri Feb 01, 2013 7:38 pm
Location: Kuala Lumpur, Malaysia
Contact: Website

Re: NRF24L01 RF Transceiver

Tue Mar 12, 2013 9:38 pm

gnulnulf wrote:After changing the CE/CSN and setting the csn to 8 again it's more stable..

I thought the rpi would control the CE0 (gpio8) when accessing the /dev/spidev0.0
maybe a SPI mode option in spi.cpp?
I don't get you... so now which GPIO is CE and which GPIO is CSN ?

Pls post a commit and I will merge it to mine..

I would like to write a more simple functions to just continuous listen (Rx mode) for incoming packets and only switch to Tx mode momentary when there are available bytes to sent... any idea on how to code this ??

At the moment, my RPi trigger the F3 polyfuse near the micro USB and after a few hours, the TP1 & TP2 still reads at around 4.0 to 4.1V... need to wait for it to resets itself before I can do any testing... :x
Stanley
blog :- http://arduino-for-beginners.blogspot.com/
fb group :- https://www.facebook.com/groups/arduino.for.beginners/

gnulnulf
Posts: 32
Joined: Sat Oct 06, 2012 12:04 pm

Re: NRF24L01 RF Transceiver

Tue Mar 12, 2013 10:01 pm

ok, I was wrong about the CE/CSN.
But I don't think it the SPI-chip-enable should be controlled by our code.
The spidev should take care of that..

I pushed my test to git, which uses the GPIO "CE" on any GPIO and the CSN on CE0 or CE1 depending on the device name.

Does anyone knows what's wrong with the spi?

Charly86
Posts: 23
Joined: Wed Mar 06, 2013 9:57 am

Re: NRF24L01 RF Transceiver

Wed Mar 13, 2013 10:00 am

Ok, as far as I know, CE0 and CE1 of the PI are hardware controled by the BCM2835 chipset, so when talking to spi devices, if you open spidev0.0 the chipset will drive the CE0 pin low when talking to SPI device, and if you open spidev0.1 the chipset will drive the CE1 pin low when talking to SPI device.

That is what I do to control the Adafruit SPI OLED from the PI, just connected CE0 to ChipSelect pin of the OLED breakout and I don't care about driving this I/O pin, the PI does the job itself by hardware.

So from my point of view for NRF it should be the same. Just need to drive the CE pin (of the NRF breakboard) into the right value when you need to Transmit or Receive. And to do this, of course you need a GPIO pin.

Does this make sense ?

gnulnulf
Posts: 32
Joined: Sat Oct 06, 2012 12:04 pm

Re: NRF24L01 RF Transceiver

Wed Mar 13, 2013 10:24 am

it makes sense.. but it did not work for me..

stanley
Posts: 33
Joined: Fri Feb 01, 2013 7:38 pm
Location: Kuala Lumpur, Malaysia
Contact: Website

Re: NRF24L01 RF Transceiver

Wed Mar 13, 2013 3:16 pm

gnulnulf wrote:it makes sense.. but it did not work for me..
I'm using yr latest commit with the following WORKING pinout :-

NRF CE is not connected

RPI CE0/GPIO8 = NRF CSN
RPI GPIO25 = Not Connected
( no changes below )
RPI SCLK = NRF SCK
RPI MOSI = NRF MOSI
RPI MISO = NRF MISO

BUT, when I compiled rpi-hub with dev = /dev/spidev0.1 and connected to GPIO7 (CE1) or GPIO8 (CE0), nothing happens...
Stanley
blog :- http://arduino-for-beginners.blogspot.com/
fb group :- https://www.facebook.com/groups/arduino.for.beginners/

Charly86
Posts: 23
Joined: Wed Mar 06, 2013 9:57 am

Re: NRF24L01 RF Transceiver

Wed Mar 13, 2013 3:57 pm

wow wow wow
That is interesting because all my tests are with spi ce1 because ce0 is used by my OLED spi. I took a look onto SPI code and may be the IOCTL can only drive the 1st SPI bus chip Enable.

For my code I am using the bcm2835 Library which provide GPIO control and I2C/SPI management.
take a look at http://www.open.com.au/mikem/bcm2835/ Trust me this Library rocks and provide SPI function that does work fine.

I wrote a librf24-bcm Library (based on your code but changed IO pin control and SPI control to use this library) using this bcm2835.c instead of gpio.cpp and spi.cpp.
I can send you the code if you want to test or integrate it to your github, sample should work same except the declaration that use the bcm2835 pin constant.
So to instantiate following these examples

CE pin is pin 15 of connector so GPIO 22 and CSN is SPI Hardware driven by pi CE0 pin

Code: Select all

RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0 );  
CE pin is pin 22 of connector so GPIO 25 and CSN is SPI Hardware driven by pi CE1 pin

Code: Select all

RF24 radio(RPI_V2_GPIO_P1_22, BCM2835_SPI_CS1 );  
CE pin is pin 22 of connector so GPIO 25 and CSN is software driven by pin 25 of connector so GPIO 22

Code: Select all

RF24 radio(RPI_V2_GPIO_P1_22, RPI_V2_GPIO_P1_15);  

stanley
Posts: 33
Joined: Fri Feb 01, 2013 7:38 pm
Location: Kuala Lumpur, Malaysia
Contact: Website

Re: NRF24L01 RF Transceiver

Wed Mar 13, 2013 5:00 pm

Charly86 wrote: For my code I am using the bcm2835 Library which provide GPIO control and I2C/SPI management.
take a look at http://www.open.com.au/mikem/bcm2835/ Trust me this Library rocks and provide SPI function that does work fine.

I can send you the code if you want to test or integrate it to your github, sample should work same except the declaration that use the bcm2835 pin constant.
Can you fork gnulnulf on github and add the mentioned above changes using the bcm2835 libs and I will help to test all the existing examples ... github is the best method for individual contributors to work together on a project like this to make it better by the day with small improvements and minimum coordinations with each other...

Once everyone test & fixed most of the bugs, we should have a pretty solid RF24 libs for the RPi..
Stanley
blog :- http://arduino-for-beginners.blogspot.com/
fb group :- https://www.facebook.com/groups/arduino.for.beginners/

gnulnulf
Posts: 32
Joined: Sat Oct 06, 2012 12:04 pm

Re: NRF24L01 RF Transceiver

Wed Mar 13, 2013 5:12 pm

I was looking into that library to see the difference from purindas lib. It should not be hard to change the spilib.

Charly86
Posts: 23
Joined: Wed Mar 06, 2013 9:57 am

Re: NRF24L01 RF Transceiver

Wed Mar 13, 2013 6:11 pm

Ok,

Forked Under librf24-rpi/librf24-bcm

I am not sure I forked well, this is my first, so please be cool and tell me if I done it the wrong way

Seriously, quick coding, just need to be tested for now

gnulnulf
Posts: 32
Joined: Sat Oct 06, 2012 12:04 pm

Re: NRF24L01 RF Transceiver

Wed Mar 13, 2013 7:34 pm

I can clone it 8-)
the library compiles with warnings, the examples point to the old librf24.
I got the pongtest running but no communication:
ROLE: Pong back
STATUS = 0x4e RX_DR=1 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1 = 0x4e4e4e4e4e 0x4e4e4e4e4e
RX_ADDR_P2-5 = 0x4e 0x4e 0x4e 0x4e
TX_ADDR = 0x4e4e4e4e4e
RX_PW_P0-6 = 0x4e 0x4e 0x4e 0x4e 0x4e 0x4e
EN_AA = 0x4e
EN_RXADDR = 0x4e
RF_CH = 0x4e
RF_SETUP = 0x4e
CONFIG = 0x4e
DYNPD/FEATURE = 0x4e 0x4e
Data Rate = 2MBPS
Model = nRF24L01
CRC Length = 16 bits
PA Power = PA_MAX
Got payload 1313754702...Got payload 1313754702...Got payload 1313754702...Got payload 1313754702...Got payload 1313754702...Got payload 1313754702...Got payload 1313754702...Got payload 1313754702...Got payload 1313754702...Got payload 1313754702...Got payload 1313754702...Got payload 1313754702...Got payload 1313754702...Got payload 1313754702...Got payload 1313754702...Got payload 1313754702...Got payload 1313754702...G

gnulnulf
Posts: 32
Joined: Sat Oct 06, 2012 12:04 pm

Re: NRF24L01 RF Transceiver

Wed Mar 13, 2013 8:07 pm

I created a bcm branch, my module reacts the same as the spi lib without the manual SPI-CE .
Do you have pongtest running with the librf24-bcm?

stanley
Posts: 33
Joined: Fri Feb 01, 2013 7:38 pm
Location: Kuala Lumpur, Malaysia
Contact: Website

Re: NRF24L01 RF Transceiver

Wed Mar 13, 2013 8:48 pm

Now, I m totally confused with these CE/CSN pins!!!! :shock:

Is this the correct format ?
RF24 radio(8,25) // CE, CSN

Is the RPI CE connects to nRF CE or CSN ?
Is the RPI CSN connects to nRF CE or CSN ?

In my SPI understanding, to select the slave, SPI pulls the CS LOW..

So is the CE0 equals to CS (Chip Select) or SS ( Slave Select in other docs ) connects to CSN ( Chip Select Not ) on the NRF ???

From the Nordic datasheet, the CE is used to enable RX or TX mode ( nothing to do with SPI )
Stanley
blog :- http://arduino-for-beginners.blogspot.com/
fb group :- https://www.facebook.com/groups/arduino.for.beginners/

Charly86
Posts: 23
Joined: Wed Mar 06, 2013 9:57 am

Re: NRF24L01 RF Transceiver

Wed Mar 13, 2013 11:12 pm

CSN is chip select not, the equivalent to SPI control SS, from the Pi the CE0 or CE1 depends on spi 0 or spi 1 hardware control, but can be manualy driven by another gpio port if you prefer

CE is to control the RX or TX (receive or transmit mode) of the NRF

the libnrf24-bcm should be the same than libnrf24 but driven buy another way for the GPIO and SPI (and CE0 or CE1 should work correctly with this lib)

Unfortunatly I can't have my NRF module working even from arduino, tried with mirf lib, nrf24 lib and rf24 lib, I don't understand and suspect I have bad modules so I can not test anything. That is why I can't test my libnrf24-bmc. Once I will have correct module I could try all of this and correct the code for the libnrf24-bcm lib.

stanley
Posts: 33
Joined: Fri Feb 01, 2013 7:38 pm
Location: Kuala Lumpur, Malaysia
Contact: Website

Re: NRF24L01 RF Transceiver

Fri Mar 15, 2013 6:12 am

As per gnulnulf, the compile is ok but totally no comms to the SPI, perhaps wrong speed / DIVIDER ??

Code: Select all

[email protected] ~/nrf24/RF24/librf24-rpi/examples $ sudo ./pingtest

RF24/examples/pingpair/
ROLE: Ping out
STATUS           = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1     = 0x0e0e0e0e0e 0x0e0e0e0e0e
RX_ADDR_P2-5     = 0x0e 0x0e 0x0e 0x0e
TX_ADDR          = 0x0e0e0e0e0e
RX_PW_P0-6       = 0x0e 0x0e 0x0e 0x0e 0x0e 0x0e
EN_AA            = 0x0e
EN_RXADDR        = 0x0e
RF_CH            = 0x0e
RF_SETUP         = 0x0e
CONFIG           = 0x0e
DYNPD/FEATURE    = 0x0e 0x0e
Data Rate        = 2MBPS
Model            = nRF24L01
CRC Length       = 16 bits
PA Power         = PA_MAX
Now sending 1823278927...failed.
Failed, response timed out.
Now sending 1823280634...failed.
Failed, response timed out.
Last edited by stanley on Fri Mar 15, 2013 10:47 am, edited 1 time in total.
Stanley
blog :- http://arduino-for-beginners.blogspot.com/
fb group :- https://www.facebook.com/groups/arduino.for.beginners/

gnulnulf
Posts: 32
Joined: Sat Oct 06, 2012 12:04 pm

Re: NRF24L01 RF Transceiver

Fri Mar 15, 2013 7:25 am

I was now trying to use the same code to a mcp23s17 to see if the spi comms work. But work and sleep kept me from completing that test :D

stanley
Posts: 33
Joined: Fri Feb 01, 2013 7:38 pm
Location: Kuala Lumpur, Malaysia
Contact: Website

Re: NRF24L01 RF Transceiver

Fri Mar 15, 2013 10:47 am

I scope both the GPIO8 and GPIO25 and confirm the following... ( ignore my previous posting )

RPi CE to NRF CE ( GPIO25 for this example )
RPi SS(CE0/CE1) to NRF CSN ( or called SS )

*** The CE0/CE1 connects to nRF CSN and NOT CE pin ( this part is confusing )
Last edited by stanley on Sat Mar 16, 2013 3:39 am, edited 1 time in total.
Stanley
blog :- http://arduino-for-beginners.blogspot.com/
fb group :- https://www.facebook.com/groups/arduino.for.beginners/

gnulnulf
Posts: 32
Joined: Sat Oct 06, 2012 12:04 pm

Re: NRF24L01 RF Transceiver

Fri Mar 15, 2013 8:19 pm

could it be the difference between SPI-CE per byte or per command?
should the commands like

Code: Select all

void bcm2835_spi_transfern 	( 	char *  	buf,
		uint32_t  	len 
	) 	
be used in

Code: Select all

uint8_t RF24::read_register(uint8_t reg, uint8_t* buf, uint8_t len)
{
  uint8_t status;
  status = bcm2835_spi_transfer( R_REGISTER | ( REGISTER_MASK & reg ) );
  while ( len-- )
    *buf++ = bcm2835_spi_transfer(0xff);
  return status;
}
As far I can see that's the difference between the libraries. The datasheet quotes "The SPI commands are shown in Table 16.. Every new command must be started by a high to low transition
on CSN."
edit: https://forum.sparkfun.com/viewtopic.php?f=13&t=33149 seems to confirm

stanley
Posts: 33
Joined: Fri Feb 01, 2013 7:38 pm
Location: Kuala Lumpur, Malaysia
Contact: Website

Re: NRF24L01 RF Transceiver

Fri Mar 15, 2013 10:56 pm

gnulnulf wrote:
The datasheet quotes "The SPI commands are shown in Table 16.. Every new command must be started by a high to low transition on CSN."
I did a diff on both the RF24.cpp and found that all the ce() and csn() lines was removed from the bcm branch...

Let me put back the csn() & ce() into the bcm branch and see if I can get the printDetails() details out...

Will post the results after my tests here the soonest possible...
Stanley
blog :- http://arduino-for-beginners.blogspot.com/
fb group :- https://www.facebook.com/groups/arduino.for.beginners/

stanley
Posts: 33
Joined: Fri Feb 01, 2013 7:38 pm
Location: Kuala Lumpur, Malaysia
Contact: Website

Re: NRF24L01 RF Transceiver

Sat Mar 16, 2013 1:41 am

I managed to trace the issue to the ce/csn pins but have NOT been able to solve it yet..
Look at line 243 of RF24.cpp
Both the ce_pin and csn_pin was parsed to a function that I've removed..

csn(LOW) or csn(HIGH) in the code was not used as during the SPI session, all GPIO_WRITE is disabled..
Stanley
blog :- http://arduino-for-beginners.blogspot.com/
fb group :- https://www.facebook.com/groups/arduino.for.beginners/

Charly86
Posts: 23
Joined: Wed Mar 06, 2013 9:57 am

Re: NRF24L01 RF Transceiver

Sun Mar 17, 2013 10:52 pm

Ok guys, I found the problem with the libnrf24-bcm BCM library and the CE0/CE1 (or custom GPIO pin)pin access using a logic analyser

In fact during function to read / write the NRF device with the BCM library the read/write is done in 2 time, one send to to tell the NRF the command we want (read, write, ..) and then a 2nd call to read the results from SPI. Unfortunatly when we do this, the CSx pin is set back from Low to High between the commands, this reset the NRF spi transmission and this is not working.
So now I changed the BCM library and RF24 library to prepare a buffer for sending/receving and burst the command on SPI bus in one time with one call. This is done every time a talk is needed to SPI. Now then the CSx pin stay low during all the transmission (as custom GPIO)
I will put back the new code on github as soon as possible, I need to do 2/3 more tests before.

Charly86
Posts: 23
Joined: Wed Mar 06, 2013 9:57 am

Re: NRF24L01 RF Transceiver

Mon Mar 18, 2013 5:50 pm

Just Updated the Github Repo, cleaned some not needed files

this lib now refer to only 2 source code files; RF24.cpp and bcm2835.c (and include files)

things seems to work fine now

Code: Select all

[email protected]:~/github/RF24/librf24-rpi/librf24-bcm# ./examples/scanner
RF24/examples/scanner/
================ SPI Configuration ================
CSN Pin          = Custom GPIO7 (CE1) Software Driven
CE Pin           = Custom GPIO22
Clock Speed      = 8 Mhz
================ NRF Configuration ================
STATUS           = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1     = 0xf0f0f0f0d2 0xf0f0f0f0e1
RX_ADDR_P2-5     = 0xe2 0xe3 0xf1 0xf2
TX_ADDR          = 0xf0f0f0f0d2
RX_PW_P0-6       = 0x20 0x20 0x20 0x20 0x20 0x20
EN_AA            = 0x00
EN_RXADDR        = 0x3f
RF_CH            = 0x4c
RF_SETUP         = 0x07
CONFIG           = 0x0f
DYNPD/FEATURE    = 0x00 0x04
Data Rate        = 1MBPS
Model            = nRF24L01+
CRC Length       = 16 bits
PA Power         = PA_MAX
000000000000000011111111111111112222222222222222333333333333333344444444444444445555555555555555666666666666666677777777
0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef01234567
000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000001000000111100000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000001000000111100000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000001000000111100000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000001000000111100000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000001000000111100000000000000000000000000000000000000000000000000000000000000000000000000000000
If you want to test, do not hesistate

stanley
Posts: 33
Joined: Fri Feb 01, 2013 7:38 pm
Location: Kuala Lumpur, Malaysia
Contact: Website

Re: NRF24L01 RF Transceiver

Mon Mar 18, 2013 7:50 pm

Glad that you got it working... nice work!!!

I changed mine to CE0=CSN and GPIO25=CE and got comms to the NRF as below..

For the pingtest & pongtest, it runs fine without getting reply and once it got one reply, it exited immediately..

Let me do more tests on the rpi-hub to get it working with this libs..

Code: Select all

[email protected] ~/nrf24/RF24/librf24-rpi/librf24-bcm/examples $ sudo ./pingtest

RF24/examples/pingpair/
ROLE: Ping out
================ SPI Configuration ================
CSN Pin          = Custom GPIO8
CE Pin           = Custom GPIO25
Clock Speed      = 8 Mhz
================ NRF Configuration ================
STATUS           = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1     = 0xf0f0f0f0e1 0xf0f0f0f0d2
RX_ADDR_P2-5     = 0xe2 0xe3 0xf1 0xf2
TX_ADDR          = 0xf0f0f0f0e1
RX_PW_P0-6       = 0x20 0x20 0x20 0x20 0x20 0x20
EN_AA            = 0x3f
EN_RXADDR        = 0x3f
RF_CH            = 0x4c
RF_SETUP         = 0x07
CONFIG           = 0x0f
DYNPD/FEATURE    = 0x00 0x04
Data Rate        = 1MBPS
Model            = nRF24L01+
CRC Length       = 16 bits
PA Power         = PA_MAX
Now sending 122...millis()=122
millis(out)=123
ok...Got response 0, round-trip delay: 145
[email protected] ~/nrf24/RF24/librf24-rpi/librf24-bcm/examples $

Stanley
blog :- http://arduino-for-beginners.blogspot.com/
fb group :- https://www.facebook.com/groups/arduino.for.beginners/

Charly86
Posts: 23
Joined: Wed Mar 06, 2013 9:57 am

Re: NRF24L01 RF Transceiver

Mon Mar 18, 2013 9:55 pm

Stanley

Could you just try not using CS0 as custom GPIO because SPI Hardware will also drive this pin and could conflict (not sure of this)
If you want to use CE0 please in init use line as follow, this will use CE0 driven by hardware SPI

RF24 radio(RPI_V2_GPIO_P1_22, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_8MHZ);


Just tell me if it works

Charly86
Posts: 23
Joined: Wed Mar 06, 2013 9:57 am

Re: NRF24L01 RF Transceiver

Tue Mar 19, 2013 10:37 am

Hi guys,

I corrected a bug I introduced in read_payload that caused a segmentation fault.
Now everything is working fine, I updated the repo. I arranged the sample with only main function needed on RPI.

Thanks to all for driving me on the right direction, we have now a really simple NRF24 lib for RPI, just 2 sources files for the library.

Here example of working pong back

Code: Select all

[email protected]:~/github/RF24/librf24-rpi/librf24-bcm# ./examples/pongtest
RF24/examples/pongtest/
ROLE: Pong back
================ SPI Configuration ================
CSN Pin          = Custom GPIO7 (CE1) Software Driven
CE Pin           = Custom GPIO22
Clock Speed      = 8 Mhz
================ NRF Configuration ================
STATUS           = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1     = 0xf0f0f0f0d2 0xf0f0f0f0e1
RX_ADDR_P2-5     = 0xe2 0xe3 0xf1 0xf2
TX_ADDR          = 0xf0f0f0f0d2
RX_PW_P0-6       = 0x20 0x20 0x20 0x20 0x20 0x20  
EN_AA            = 0x3f  
EN_RXADDR        = 0x3f  
RF_CH            = 0x4c  
RF_SETUP         = 0x03  
CONFIG           = 0x0f  
DYNPD/FEATURE    = 0x00 0x04  
Data Rate        = 1MBPS  
Model            = nRF24L01+  
CRC Length       = 16 bits  
PA Power         = PA_LOW  
Got payload(4) 43506520...  
Got payload(4) 43507553...  
Got payload(4) 43508578...  
^C  
[email protected]:~/github/RF24/librf24-rpi/librf24-bcm#  
Have fun

Return to “HATs and other add-ons”