FastArduino v1.10
C++ library to build fast but small Arduino/AVR projects
Loading...
Searching...
No Matches
nrf24l01p.h
Go to the documentation of this file.
1// Important copyright notice:
2// Large parts of this file were copied from Mikael Patel's Cosa library, which copyright appears below
3// Content has been adapted to use FastArduino original parts, under Copyright (c) 2016, Jean-Francois Poilpret
4
5/*
6 * Copyright (C) 2013-2015, Mikael Patel
7 * Copyright (C) 2016-2022, Jean-Francois Poilpret
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * This file was originally part of the Arduino Che Cosa project,
20 * it has been adapted and refactored to FastArduino library.
21 */
22
24
32#ifndef NRF24L01_HH
33#define NRF24L01_HH
34
35#include <stddef.h>
36#include "../utilities.h"
37#include "../errors.h"
38#include "../time.h"
39#include "../spi.h"
40#include "../int.h"
41#include "nrf24l01p_internals.h"
42
43namespace devices
44{
52 namespace rf
53 {
54 }
55}
56
57namespace devices::rf
58{
85 template<board::DigitalPin CSN, board::DigitalPin CE> class NRF24L01 : public spi::SPIDevice<CSN>
86 {
87 public:
89 static const uint8_t BROADCAST = 0x00;
90
94 static const size_t DEVICE_PAYLOAD_MAX = 32;
95
100 static const size_t PAYLOAD_MAX = DEVICE_PAYLOAD_MAX - 2;
101
109 NRF24L01(uint16_t net, uint8_t dev);
110
115 uint8_t get_channel() const
116 {
117 return channel_;
118 }
119
124 uint16_t get_network_address() const
125 {
126 return addr_.network;
127 }
128
133 uint8_t get_device_address() const
134 {
135 return addr_.device;
136 }
137
144 void set_address(int16_t net, uint8_t dev)
145 {
146 addr_.network = net;
147 addr_.device = dev;
148 }
149
155 void set_channel(uint8_t channel)
156 {
157 channel_ = channel;
158 }
159
164 void begin();
165
169 void end()
170 {
171 powerdown();
172 }
173
178 void powerup();
179
183 void standby();
184
188 void powerdown();
189
207 template<typename T, typename TREF = const T&>
208 int send(uint8_t dest, uint8_t port, TREF buf)
209 {
210 return send_(dest, port, (const uint8_t*) &buf, sizeof(T));
211 }
212
225 int send(uint8_t dest, uint8_t port)
226 {
227 return send_(dest, port, nullptr, 0);
228 }
229
254 template<typename T, typename TREF = T&>
255 int recv(uint8_t& src, uint8_t& port, TREF buf, uint32_t ms = 0L)
256 {
257 return recv_(src, port, (uint8_t*) &buf, sizeof(T), ms);
258 }
259
277 int recv(uint8_t& src, uint8_t& port, uint32_t ms = 0L)
278 {
279 return recv_(src, port, nullptr, 0, ms);
280 }
281
286 void set_output_power_level(int8_t dBm);
287
292 uint16_t get_trans() const
293 {
294 return trans_;
295 }
296
301 uint16_t get_retrans() const
302 {
303 return retrans_;
304 }
305
310 uint16_t get_drops() const
311 {
312 return drops_;
313 }
314
328 template<typename T, typename TREF = const T&>
329 int broadcast(uint8_t port, TREF buf)
330 {
331 return send(BROADCAST, port, buf);
332 }
333
338 bool is_broadcast() const
339 {
340 return (dest_ == BROADCAST);
341 }
342
343 protected:
345 int send_(uint8_t dest, uint8_t port, const uint8_t* buf, size_t len);
346 int recv_(uint8_t& src, uint8_t& port, uint8_t* buf, size_t size, uint32_t ms);
348
352 enum class Command : uint8_t
353 {
354 R_REGISTER = 0x00,
355 W_REGISTER = 0x20,
356 REG_MASK = 0x1f,
357
358 R_RX_PAYLOAD = 0x61,
359 W_TX_PAYLOAD = 0xa0,
360
361 FLUSH_TX = 0xe1,
362 FLUSH_RX = 0xe2,
363
364 REUSE_TX_PL = 0xe3,
365
366 R_RX_PL_WID = 0x60,
367
368 W_ACK_PAYLOAD = 0xa8,
369 PIPE_MASK = 0x07,
370
371 W_TX_PAYLOAD_NO_ACK = 0xb0,
372 NOP = 0xff
373 };
374
378 enum class Register : uint8_t
379 {
380 CONFIG = 0x00,
381 EN_AA = 0x01,
382 EN_RXADDR = 0x02,
383 SETUP_AW = 0x03,
384 SETUP_RETR = 0x04,
385 RF_CH = 0x05,
386 RF_SETUP = 0x06,
387 STATUS = 0x07,
388 OBSERVE_TX = 0x08,
389 RPD = 0x09,
390 RX_ADDR_P0 = 0x0a,
391 RX_ADDR_P1 = 0x0b,
392 RX_ADDR_P2 = 0x0c,
393 RX_ADDR_P3 = 0x0d,
394 RX_ADDR_P4 = 0x0e,
395 RX_ADDR_P5 = 0x0f,
396 TX_ADDR = 0x10,
397 RX_PW_P0 = 0x11,
398 RX_PW_P1 = 0x12,
399 RX_PW_P2 = 0x13,
400 RX_PW_P3 = 0x14,
401 RX_PW_P4 = 0x15,
402 RX_PW_P5 = 0x16,
403 FIFO_STATUS = 0x17,
404 DYNPD = 0x1c,
405 FEATURE = 0x1d
406 };
407
412 {
413 uint8_t as_byte;
414
415 struct
416 {
417 uint8_t arc_cnt : 4;
418 uint8_t plos_cnt : 4;
419 };
420
426 explicit observe_tx_t(uint8_t value) INLINE : as_byte{value} {}
427 };
428
433 {
434 uint8_t as_byte;
435 struct
436 {
437 bool rx_empty : 1;
438 bool rx_full : 1;
439 uint8_t reserved1 : 2;
440 bool tx_empty : 1;
441 bool tx_full : 1;
442 bool tx_reuse : 1;
443 uint8_t reserved2 : 1;
444 };
445
450 explicit fifo_status_t(uint8_t value) INLINE : as_byte{value} {}
451 };
452
456 struct addr_t
457 {
458 uint8_t device;
459 uint16_t network;
460
466 addr_t(uint16_t net, uint8_t dev) INLINE : device{dev}, network{net} {}
467 };
468
472 enum class State : uint8_t
473 {
474 POWER_DOWN_STATE = 0,
475 STANDBY_STATE,
476 RX_STATE,
477 TX_STATE
478 };
479
484 {
485 uint8_t as_byte;
486 struct
487 {
488 bool tx_full : 1;
489 uint8_t rx_p_no : 3;
490 bool max_rt : 1;
491 bool tx_ds : 1;
492 bool rx_dr : 1;
493 uint8_t reserved : 1;
494 };
495
500 explicit status_t(uint8_t value) INLINE : as_byte{value} {}
501 };
502
504 // Lowest-level methods to access NRF24L01 device
505 uint8_t read(uint8_t cmd)
506 {
507 this->start_transfer();
508 status_ = status_t{this->transfer(cmd)};
509 uint8_t result = this->transfer(uint8_t(Command::NOP));
510 this->end_transfer();
511 return result;
512 }
513 void write(uint8_t cmd)
514 {
515 this->start_transfer();
516 status_ = status_t{this->transfer(cmd)};
517 this->end_transfer();
518 }
519 void write(uint8_t cmd, uint8_t data)
520 {
521 this->start_transfer();
522 status_ = status_t{this->transfer(cmd)};
523 this->transfer(data);
524 this->end_transfer();
525 }
526 void write(uint8_t cmd, const uint8_t* buf, size_t size)
527 {
528 this->start_transfer();
529 status_ = status_t{this->transfer(cmd)};
530 this->transfer((uint8_t*) buf, size);
531 this->end_transfer();
532 }
533
534 // Command-level methods to access NRF24L01 device
535 uint8_t read_command(Command cmd)
536 {
537 return read(uint8_t(cmd));
538 }
539 void write_command(Command cmd)
540 {
541 write(uint8_t(cmd));
542 }
543
544 // Mid-level methods to access NRF24L01 device registers
545 uint8_t read_register(Register reg)
546 {
547 return read(uint8_t(Command::R_REGISTER) | uint8_t(uint8_t(Command::REG_MASK) & uint8_t(reg)));
548 }
549 void write_register(Register reg, uint8_t data)
550 {
551 write(uint8_t(Command::W_REGISTER) | uint8_t(uint8_t(Command::REG_MASK) & uint8_t(reg)), data);
552 }
553 void write_register(Register reg, const uint8_t* buf, size_t size)
554 {
555 write(uint8_t(Command::W_REGISTER) | uint8_t(uint8_t(Command::REG_MASK) & uint8_t(reg)), buf, size);
556 }
557
558 status_t read_status()
559 {
560 this->start_transfer();
561 status_ = status_t{this->transfer(uint8_t(Command::NOP))};
562 this->end_transfer();
563 return status_;
564 }
565
566 void transmit_mode(uint8_t dest);
567 void receive_mode();
568
569 bool available();
570 int read_fifo_payload(uint8_t& src, uint8_t& port, uint8_t* buf, size_t count);
571 fifo_status_t read_fifo_status()
572 {
573 return fifo_status_t{read_register(Register::FIFO_STATUS)};
574 }
575 observe_tx_t read_observe_tx()
576 {
577 return observe_tx_t{read_register(Register::OBSERVE_TX)};
578 }
580
581 private:
582 static const uint8_t DEFAULT_CHANNEL = 64;
583
585
586 addr_t addr_;
587 uint8_t channel_ = DEFAULT_CHANNEL;
588 uint8_t dest_ = 0;
589
590 status_t status_ = status_t{0};
591 State state_ = State::POWER_DOWN_STATE;
592
593 uint16_t trans_ = 0;
594 uint16_t retrans_ = 0;
595 uint16_t drops_ = 0;
596 };
597
629 template<board::DigitalPin CSN, board::DigitalPin CE, board::ExternalInterruptPin IRQ>
630 class IRQ_NRF24L01 : public NRF24L01<CSN, CE>
631 {
632 public:
640 IRQ_NRF24L01(uint16_t net, uint8_t dev) : NRF24L01<CSN, CE>{net, dev}
641 {
643 }
644
649 void begin()
650 {
652 irq_signal_.enable();
653 }
654
658 void end()
659 {
660 irq_signal_.disable();
662 }
663
664 private:
666 };
667
668 template<board::DigitalPin CSN, board::DigitalPin CE>
669 NRF24L01<CSN, CE>::NRF24L01(uint16_t net, uint8_t dev) : addr_{net, dev} {}
670
671 template<board::DigitalPin CSN, board::DigitalPin CE> void NRF24L01<CSN, CE>::begin()
672 {
673 using namespace nrf24l01p_internals;
674 // Setup hardware features, channel, bitrate, retransmission, dynamic payload
675 write_register(Register::FEATURE, (bits::BV8(EN_DPL, EN_ACK_PAY, EN_DYN_ACK)));
676 write_register(Register::RF_CH, channel_);
677 write_register(Register::RF_SETUP, RF_DR_2MBPS | RF_PWR_0DBM);
678 write_register(Register::SETUP_RETR, uint8_t(DEFAULT_ARD << ARD) | uint8_t(DEFAULT_ARC << ARC));
679 write_register(Register::DYNPD, DPL_PA);
680
681 // Setup hardware receive pipes address; network (16-bit), device (8-bit)
682 // P0: auto-acknowledge (see set_transmit_mode)
683 // P1: node address<network:device> with auto-acknowledge
684 // P2: broadcast<network:0>
685 addr_t rx_addr = addr_;
686 write_register(Register::SETUP_AW, AW_3BYTES);
687 write_register(Register::RX_ADDR_P1, (const uint8_t*) &rx_addr, sizeof(rx_addr));
688 write_register(Register::RX_ADDR_P2, BROADCAST);
689 write_register(Register::EN_RXADDR, bits::BV8(ERX_P2, ERX_P1));
690 write_register(Register::EN_AA, bits::BV8(ENAA_P1, ENAA_P0));
691
692 // Ready to go
693 powerup();
694 }
695
696 template<board::DigitalPin CSN, board::DigitalPin CE> void NRF24L01<CSN, CE>::powerup()
697 {
698 using namespace nrf24l01p_internals;
699 if (state_ != State::POWER_DOWN_STATE) return;
700 ce_.clear();
701
702 // Setup configuration for powerup and clear interrupts
703 write_register(Register::CONFIG, bits::BV8(EN_CRC, CRCO, PWR_UP));
704 time::delay_ms(Tpd2stby_ms);
705 state_ = State::STANDBY_STATE;
706
707 // Flush status
708 write_register(Register::STATUS, bits::BV8(RX_DR, TX_DS, MAX_RT));
709 write_command(Command::FLUSH_TX);
710 write_command(Command::FLUSH_RX);
711 }
712
713 template<board::DigitalPin CSN, board::DigitalPin CE> void NRF24L01<CSN, CE>::standby()
714 {
715 if (state_ == State::STANDBY_STATE) return;
716 ce_.clear();
717 state_ = State::STANDBY_STATE;
718 }
719
720 template<board::DigitalPin CSN, board::DigitalPin CE> void NRF24L01<CSN, CE>::powerdown()
721 {
722 using namespace nrf24l01p_internals;
723 if (state_ == State::POWER_DOWN_STATE) return;
724 ce_.clear();
725 write_register(Register::CONFIG, bits::BV8(EN_CRC, CRCO));
726 state_ = State::POWER_DOWN_STATE;
727 }
728
730 template<board::DigitalPin CSN, board::DigitalPin CE>
731 int NRF24L01<CSN, CE>::send_(uint8_t dest, uint8_t port, const uint8_t* buf, size_t len)
732 {
733 using namespace nrf24l01p_internals;
734 // Note buf == 0 and len == 0 is perfectly acceptable
735 if ((buf == nullptr) && (len > 0)) return errors::EINVAL;
736 if (len > PAYLOAD_MAX) return errors::EMSGSIZE;
737
738 // Setting transmit destination first (needs to ensure standby mode)
739 transmit_mode(dest);
740
741 // Write source address and payload to the transmit fifo
742 Command command = ((dest != BROADCAST) ? Command::W_TX_PAYLOAD : Command::W_TX_PAYLOAD_NO_ACK);
743 this->start_transfer();
744 status_ = status_t{this->transfer(uint8_t(command))};
745 this->transfer(addr_.device);
746 this->transfer(port);
747 this->transfer(buf, len);
748 this->end_transfer();
749
750 trans_ += 1;
751
752 // Check for auto-acknowledge pipe(0), and address setup and enable
753 if (dest != BROADCAST)
754 {
755 addr_t tx_addr(addr_.network, dest);
756 write_register(Register::RX_ADDR_P0, (const uint8_t*) &tx_addr, sizeof(tx_addr));
757 write_register(Register::EN_RXADDR, bits::BV8(ERX_P2, ERX_P1, ERX_P0));
758 }
759
760 // Wait for transmission
761 status_t status = status_t{0};
762 while (true)
763 {
764 status = read_status();
765 if (status.tx_ds || status.max_rt) break;
766 time::yield();
767 }
768
769 bool data_sent = status.tx_ds;
770
771 // Check for auto-acknowledge pipe(0) disable
772 if (dest != BROADCAST) write_register(Register::EN_RXADDR, bits::BV8(ERX_P2, ERX_P1));
773
774 // Reset status bits
775 write_register(Register::STATUS, bits::BV8(TX_DS, MAX_RT));
776
777 // Read retransmission counter and update
778 observe_tx_t observe = read_observe_tx();
779 retrans_ += observe.arc_cnt;
780
781 // Check that the message was delivered
782 if (data_sent) return len;
783
784 // Failed to deliver
785 write_command(Command::FLUSH_TX);
786 drops_ += 1;
787
788 return errors::EIO;
789 }
790
791 template<board::DigitalPin CSN, board::DigitalPin CE>
792 int NRF24L01<CSN, CE>::recv_(uint8_t& src, uint8_t& port, uint8_t* buf, size_t size, uint32_t ms)
793 {
794 // Run in receive mode
795 receive_mode();
796
797 // Check if there is data available on any pipe
798 uint32_t start = time::millis();
799 while (!available())
800 {
801 if ((ms != 0) && (time::since(start) > ms)) return errors::ETIME;
802 time::yield();
803 }
804
805 // Try and read payload from FIFO
806 return read_fifo_payload(src, port, buf, size);
807 }
809
810 template<board::DigitalPin CSN, board::DigitalPin CE> void NRF24L01<CSN, CE>::set_output_power_level(int8_t dBm)
811 {
812 using namespace nrf24l01p_internals;
813 uint8_t pwr;
814 if (dBm < -12)
815 pwr = RF_PWR_18DBM;
816 else if (dBm < -6)
817 pwr = RF_PWR_12DBM;
818 else if (dBm < 0)
819 pwr = RF_PWR_6DBM;
820 else
821 pwr = RF_PWR_0DBM;
822 write_register(Register::RF_SETUP, RF_DR_2MBPS | pwr);
823 }
824
826 template<board::DigitalPin CSN, board::DigitalPin CE> void NRF24L01<CSN, CE>::transmit_mode(uint8_t dest)
827 {
828 using namespace nrf24l01p_internals;
829 // Setup primary transmit address
830 addr_t tx_addr(addr_.network, dest);
831 write_register(Register::TX_ADDR, (const uint8_t*) &tx_addr, sizeof(tx_addr));
832
833 // Trigger the transmitter mode
834 if (state_ != State::TX_STATE)
835 {
836 ce_.clear();
837 write_register(Register::CONFIG, bits::BV8(EN_CRC, CRCO, PWR_UP));
838 ce_.set();
839 }
840
841 // Wait for the transmitter to become active
842 if (state_ == State::STANDBY_STATE) time::delay_us(Tstby2a_us);
843 state_ = State::TX_STATE;
844 }
845
846 template<board::DigitalPin CSN, board::DigitalPin CE> void NRF24L01<CSN, CE>::receive_mode()
847 {
848 using namespace nrf24l01p_internals;
849 // Check already in receive mode
850 if (state_ == State::RX_STATE) return;
851
852 // Configure primary receiver mode
853 write_register(Register::CONFIG, bits::BV8(EN_CRC, CRCO, PWR_UP, PRIM_RX));
854 ce_.set();
855 if (state_ == State::STANDBY_STATE) time::delay_us(Tstby2a_us);
856 state_ = State::RX_STATE;
857 }
858
859 template<board::DigitalPin CSN, board::DigitalPin CE> bool NRF24L01<CSN, CE>::available()
860 {
861 // Check the receiver fifo
862 if (read_fifo_status().rx_empty) return false;
863
864 // Sanity check the size of the payload. Might require a flush
865 if (read_command(Command::R_RX_PL_WID) <= DEVICE_PAYLOAD_MAX) return true;
866 write_command(Command::FLUSH_RX);
867 return false;
868 }
869
870 template<board::DigitalPin CSN, board::DigitalPin CE>
871 int NRF24L01<CSN, CE>::read_fifo_payload(uint8_t& src, uint8_t& port, uint8_t* buf, size_t size)
872 {
873 // Check for payload error from device (Tab. 20, pp. 51, R_RX_PL_WID)
874 uint8_t count = read_command(Command::R_RX_PL_WID) - 2;
875 if ((count > PAYLOAD_MAX) || (count > size))
876 {
877 write_command(Command::FLUSH_RX);
878 return errors::EMSGSIZE;
879 }
880
881 // Data is available, check if this a broadcast or not
882 dest_ = (read_status().rx_p_no == 1 ? addr_.device : BROADCAST);
883
884 // Read the source address, port and payload
885 this->start_transfer();
886 status_ = status_t{this->transfer(uint8_t(Command::R_RX_PAYLOAD))};
887 src = this->transfer(0);
888 port = this->transfer(0);
889 this->transfer(buf, count, uint8_t(Command::NOP));
890 this->end_transfer();
891 return count;
892 }
894}
895
896#endif /* NRF24L01_HH */
SPI device driver for Nordic Semiconductor nRF24L01+ support, with IRQ.
Definition: nrf24l01p.h:631
IRQ_NRF24L01(uint16_t net, uint8_t dev)
Construct NRF transceiver with given channel and pin numbers for SPI slave select,...
Definition: nrf24l01p.h:640
void end()
Shut down the device driver.
Definition: nrf24l01p.h:658
void begin()
Start up the device driver.
Definition: nrf24l01p.h:649
SPI device driver for Nordic Semiconductor nRF24L01+ support, without IRQ support.
Definition: nrf24l01p.h:86
void set_output_power_level(int8_t dBm)
Set output power level (-30..10 dBm)
Definition: nrf24l01p.h:810
uint8_t get_device_address() const
Get driver device address.
Definition: nrf24l01p.h:133
uint16_t get_trans() const
Return number of transmitted messages.
Definition: nrf24l01p.h:292
uint16_t get_retrans() const
Return number of retransmissions.
Definition: nrf24l01p.h:301
int send(uint8_t dest, uint8_t port, TREF buf)
Send message with given object reference.
Definition: nrf24l01p.h:208
int send(uint8_t dest, uint8_t port)
Send an empty message.
Definition: nrf24l01p.h:225
void powerdown()
Set power down.
Definition: nrf24l01p.h:720
uint16_t get_drops() const
Return number of dropped messages.
Definition: nrf24l01p.h:310
void set_channel(uint8_t channel)
Set device transmission channel.
Definition: nrf24l01p.h:155
void set_address(int16_t net, uint8_t dev)
Set network and device address.
Definition: nrf24l01p.h:144
void end()
Shut down the device driver.
Definition: nrf24l01p.h:169
static const size_t DEVICE_PAYLOAD_MAX
Maximum size of payload on device.
Definition: nrf24l01p.h:94
static const uint8_t BROADCAST
Broadcast device address.
Definition: nrf24l01p.h:89
NRF24L01(uint16_t net, uint8_t dev)
Construct NRF transceiver with given channel and pin numbers for SPI slave select,...
Definition: nrf24l01p.h:669
int recv(uint8_t &src, uint8_t &port, uint32_t ms=0L)
Receive an empty message.
Definition: nrf24l01p.h:277
int recv(uint8_t &src, uint8_t &port, TREF buf, uint32_t ms=0L)
Receive message and store into given object reference.
Definition: nrf24l01p.h:255
bool is_broadcast() const
Return true if the latest received message was a broadcast otherwise false.
Definition: nrf24l01p.h:338
int broadcast(uint8_t port, TREF buf)
Broadcast message with given object reference.
Definition: nrf24l01p.h:329
void powerup()
Set power up mode.
Definition: nrf24l01p.h:696
uint8_t get_channel() const
Get driver channel.
Definition: nrf24l01p.h:115
State
NRF transceiver states (See chap.
Definition: nrf24l01p.h:473
void standby()
Set standby mode.
Definition: nrf24l01p.h:713
Command
SPI Commands (See chap.
Definition: nrf24l01p.h:353
@ NOP
No operation, return status.
@ R_REGISTER
Read command and status register.
@ R_RX_PAYLOAD
Read RX payload.
@ R_RX_PL_WID
Read RX payload width.
@ W_TX_PAYLOAD_NO_ACK
Disable AUTOACK on this specific packet.
@ W_REGISTER
Write command and status register.
@ W_ACK_PAYLOAD
Write TX payload with ACK (3 bit addr).
@ W_TX_PAYLOAD
Write TX payload.
@ PIPE_MASK
Mask pipe address.
@ REG_MASK
Mask register address (5b).
@ REUSE_TX_PL
Reuse last transmitted payload.
static const size_t PAYLOAD_MAX
Maximum size of payload.
Definition: nrf24l01p.h:100
uint16_t get_network_address() const
Get driver network address.
Definition: nrf24l01p.h:124
Register
NRF transceiver registers map (See chap.
Definition: nrf24l01p.h:379
@ RF_SETUP
RF setup register.
@ SETUP_RETR
Setup of auto retransmission.
@ RX_ADDR_P0
Receive address data pipe 0.
@ SETUP_AW
Setup of address width.
@ EN_AA
Enable auto acknowledgement.
@ FIFO_STATUS
FIFO status register.
@ CONFIG
Configuration register.
@ RX_PW_P0
Number of bytes in RX payload in data pipe 0.
@ DYNPD
Enable dynamic payload length.
@ RPD
Received power detector.
@ EN_RXADDR
Enable rx addresses.
@ OBSERVE_TX
Transmit observe register.
void begin()
Start up the device driver.
Definition: nrf24l01p.h:671
API that manipulates a given digital IO pin of a the target MCU.
Definition: gpio.h:551
Handler of an External Interrupt.
Definition: int.h:132
void disable()
Disable interrupts for this external interrupt pin.
Definition: int.h:195
void enable()
Enable interrupts for this external interrupt pin.
Definition: int.h:183
uint8_t transfer(uint8_t data)
Transfer one byte to the currently selected SPI slave device through MOSI pin, and get the byte retur...
Definition: spi.h:169
Base class for any SPI slave device.
Definition: spi.h:331
void start_transfer()
Start an SPI transfer to this device.
Definition: spi.h:344
void end_transfer() INLINE
End the current SPI ransfer tot hsi device.
Definition: spi.h:362
#define INLINE
Specific GCC attribute to force the compiler to always inline code of a given function.
Definition: defines.h:57
static constexpr uint8_t BV8(uint8_t bit)
Create a uint8_t bitmask for the given bit number.
Definition: bits.h:41
Defines the API for radio-frequency (wireless) communication support.
Definition: nrf24l01p.h:53
Defines all API for all external devices supported by FastArduino.
constexpr const int EINVAL
Invalid argument or invalid Future.
Definition: errors.h:49
constexpr const int EIO
Input/output error.
Definition: errors.h:40
constexpr const int EMSGSIZE
Message too long.
Definition: errors.h:68
constexpr const int ETIME
Timer expired.
Definition: errors.h:52
typename FastPinType< DPIN_ >::TYPE FAST_PIN
Useful alias type to the FastPin type matching a given board::DigitalPin.
Definition: gpio.h:694
@ OUTPUT
Digital pin is configured as output.
@ INPUT_PULLUP
Digital pin is configured as input with an internal pullup resistor.
@ FALLING_EDGE
Interrupt is triggered whenever pin level is falling from high to low.
MILLIS_PTR millis
Count number of milliseconds elapsed since some time base reference (generally since MCU startup).
Definition: time.cpp:20
void delay_us(uint16_t us) INLINE
Delay program execution for the given amount of microseconds.
Definition: time.h:334
void yield()
Utility method used by many FastArduino API in order to "yield" some processor time; concretely it ju...
Definition: time.cpp:22
uint32_t since(uint32_t start_ms)
Compute the time elapsed, in milliseconds, since start_ms.
Definition: time.cpp:41
void delay_ms(uint16_t ms) INLINE
Delay program execution for the given amount of milliseconds.
Definition: time.h:346
Network address together with port.
Definition: nrf24l01p.h:457
uint8_t device
Device address (LSB).
Definition: nrf24l01p.h:458
addr_t(uint16_t net, uint8_t dev) INLINE
Create an addr_t from a netwrok and a device address.
Definition: nrf24l01p.h:466
uint16_t network
Network address.
Definition: nrf24l01p.h:459
Register FIFO_STATUS data type, transmission queue status.
Definition: nrf24l01p.h:433
uint8_t as_byte
Byte representation of fifo status.
Definition: nrf24l01p.h:434
bool rx_empty
RX FIFO empty flag.
Definition: nrf24l01p.h:437
fifo_status_t(uint8_t value) INLINE
Construct transmitter queue status from register reading.
Definition: nrf24l01p.h:450
bool tx_reuse
Reuse last transmitted data packat.
Definition: nrf24l01p.h:442
bool tx_empty
TX FIFO empty flag.
Definition: nrf24l01p.h:440
bool tx_full
TX FIFO full flag.
Definition: nrf24l01p.h:441
bool rx_full
RX FIFO full flag.
Definition: nrf24l01p.h:438
Register OBSERVE_TX data type, performance statistics.
Definition: nrf24l01p.h:412
observe_tx_t(uint8_t value) INLINE
Construct transmitter performance statistics from register reading.
Definition: nrf24l01p.h:426
uint8_t as_byte
Byte representation of performance statistics.
Definition: nrf24l01p.h:413
uint8_t plos_cnt
Count lost packets.
Definition: nrf24l01p.h:418
uint8_t arc_cnt
Count retransmitted packets.
Definition: nrf24l01p.h:417
Register STATUS data type.
Definition: nrf24l01p.h:484
status_t(uint8_t value) INLINE
Construct status from register reading.
Definition: nrf24l01p.h:500
bool tx_ds
Data send TX FIFO interrupt.
Definition: nrf24l01p.h:491
uint8_t rx_p_no
Data pipe number for available payload.
Definition: nrf24l01p.h:489
uint8_t as_byte
Byte representation of status.
Definition: nrf24l01p.h:485
bool tx_full
TX FIFO full.
Definition: nrf24l01p.h:488
bool max_rt
Max number of TX retransmit interrupt.
Definition: nrf24l01p.h:490
bool rx_dr
Data ready RX FIFO interrupt.
Definition: nrf24l01p.h:492