Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ce(LOW) in startWrite #11

Closed
jbliesener opened this issue Jul 11, 2014 · 5 comments
Closed

ce(LOW) in startWrite #11

jbliesener opened this issue Jul 11, 2014 · 5 comments
Labels

Comments

@jbliesener
Copy link

I have a question about that ce(LOW) in line 689 of RF24.cpp. What is it for?

The state diagram on page 21 of the NRF24L01 datasheet tells us that CE needs to be high to remain in transmit mode. My version of the GettingStarted example freezes in the write method, as neither TX_DS nor MAX_RT come up in the status register, as long as CE is low.

The code works as soon as I comment out line 689.

@TMRh20
Copy link
Member

TMRh20 commented Jul 15, 2014

Per the datasheet, the CE pin is used to control transmission, and whether or not the radio stays in Standby-II or returns to Standby-I mode:

See section 6.1.5
"The TX mode is an active mode for transmitting packets. To enter this mode, the nRF24L01+ must have
the PWR_UP bit set high, PRIM_RX bit set low, a payload in the TX FIFO and a high pulse on the
CE for more than 10μs.
The nRF24L01+ stays in TX mode until it finishes transmitting a packet. If CE = 0, nRF24L01+ returns to standby-I mode. If CE = 1, the status of the TX FIFO determines the next action."

I would be interested to know whether adding delayMicroseconds(15); before ce(LOW); would make a difference, as well as what board you are using etc., especially if it does make a difference.

@jbliesener
Copy link
Author

Yes, your're right. It was the pulse length. On a Teensy 3.0 with 96 MHz and Paul Stoffregen's optimized digitalWrite function, the sequence ce(HIGH); ce(LOW); gives me an 800 ns pulse. A delayMicroseconds(10); before ce(LOW) sorts this out.

However, in my project I have a requirement that effectively prohibits me to use delay() or delayMicroseconds(). My loop() function needs to terminate in less than 100 microseconds, so, anything that might block needs to implement as a state machine. For RF24, this includes SPI data transfers.

There is a terrific library for handling SPI transfers through DMA on the Teensy3 at https://github.com/crteensy/DmaSpi. I will try to integrate it into your code and I'll let you know about the results.

@luizrrocha
Copy link

Hi. I am adapting your library to work with Chipkit's Uno32 and only could make it work by adding the delayMicroseconds(10) to the same spot, as the Chipkit gives a shorter than 10uS pulse with only the ce(HIGH); ce(LOW); pair.

As soon as I finish basic tests how can I send you my modified code ?

@TMRh20
Copy link
Member

TMRh20 commented Jul 25, 2014

Thanks for the extra info. I believe the issue and fix is similar to what I have done on the RPi, being converting the radio.write() to use writeFast, then toggle the CE pin LOW after sending is completed or failed. This should work around the need for a delay. Haven't been able to do much lately, but I will be taking a quick look at it soon. Also code changes can always be submitted via GitHub forks/pull requests.

TMRh20 added a commit that referenced this issue Jul 29, 2014
Modified write() to use startFastWrite, then toggle CE after completion
to remove need for a delay on some boards.
Added delay to startWrite for non-Arduino boards.
Removed receive buffer flushes. This prevents an issue in the
RF24Network library, where payloads would be received, but flushed when
a transmission takes place prior to reading.
Should address issues #7 and #11
@TMRh20
Copy link
Member

TMRh20 commented Jul 29, 2014

Ok, I think commit 1d18015 will address the issue.

I've added a delay to startWrite for non-Arduino and Teensy boards, and have modified the standard radio.write() to remove the need for a delay on all boards. It passes all my tests, so hopefully this will do the trick.

*Edit to add: jbliesener You may be best off using startFastWrite(); and just leaving the radio in standby-II mode.

@TMRh20 TMRh20 added the bug label Jul 30, 2014
@TMRh20 TMRh20 closed this as completed Sep 7, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants