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

Made RF24::available() report whether there are bytes available to be read #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

FesterBesterTester
Copy link

RF24::available() is intended to test whether there are bytes available to be read. The current implementation instead tests whether a packet has been received since the last time RF24::available() was called.

The RX FIFO can hold three packets. If there are multiple packets in the RX FIFO at the start of the loop below but no packets arrive during the loop, then only the first packet will be retrieved.

while (radio.available())
    radio.read(buf, len);

RF24::available() checks and then clears the RX_DR IRQ, returning true if and only if RX_DR was set. According to the nrf24l01+ spec, the RX_DR IRQ is asserted when a new packet arrives. Clearing RX_DR in RF24::available() will cause subsequent calls to RF24::available() to return false until another packet arrives, even though there may still be unread data available in the RX FIFO.

This patch makes RF24::available() correctly report whether there are bytes available to be read by checking the RX_EMPTY bit of the FIFO_STATUS register instead of relying on the state of RX_DR. It clears the RX_DR bit after the payload has been read as suggested by the nrf24l01+ spec:

The RX_DR IRQ is asserted by a new packet arrival event. The procedure for handling this interrupt should be: 1) read payload through SPI, 2) clear RX_DR IRQ, 3) read FIFO_STATUS to check if there are more payloads available in RX FIFO, 4) if there are more data in RX FIFO, repeat from step 1).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant