Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: STM32F407VET6_nRF24L01_Master STM32F407VET6_nRF24L01_Slave Main_ntp_sd_nrf IRC_MASTER
RF24.h
00001 /* 00002 Copyright (c) 2007 Stefan Engelke <mbox@stefanengelke.de> 00003 00004 Permission is hereby granted, free of charge, to any person 00005 obtaining a copy of this software and associated documentation 00006 files (the "Software"), to deal in the Software without 00007 restriction, including without limitation the rights to use, copy, 00008 modify, merge, publish, distribute, sublicense, and/or sell copies 00009 of the Software, and to permit persons to whom the Software is 00010 furnished to do so, subject to the following conditions: 00011 00012 The above copyright notice and this permission notice shall be 00013 included in all copies or substantial portions of the Software. 00014 00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00016 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00017 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00018 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 00019 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 00020 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00021 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 00022 DEALINGS IN THE SOFTWARE. 00023 */ 00024 00025 /* Memory Map */ 00026 #define CONFIG 0x00 00027 #define EN_AA 0x01 00028 #define EN_RXADDR 0x02 00029 #define SETUP_AW 0x03 00030 #define SETUP_RETR 0x04 00031 #define RF_CH 0x05 00032 #define RF_SETUP 0x06 00033 #define STATUS 0x07 00034 #define OBSERVE_TX 0x08 00035 #define CD 0x09 00036 #define RX_ADDR_P0 0x0A 00037 #define RX_ADDR_P1 0x0B 00038 #define RX_ADDR_P2 0x0C 00039 #define RX_ADDR_P3 0x0D 00040 #define RX_ADDR_P4 0x0E 00041 #define RX_ADDR_P5 0x0F 00042 #define TX_ADDR 0x10 00043 #define RX_PW_P0 0x11 00044 #define RX_PW_P1 0x12 00045 #define RX_PW_P2 0x13 00046 #define RX_PW_P3 0x14 00047 #define RX_PW_P4 0x15 00048 #define RX_PW_P5 0x16 00049 #define FIFO_STATUS 0x17 00050 #define DYNPD 0x1C 00051 #define FEATURE 0x1D 00052 00053 /* Bit Mnemonics */ 00054 #define MASK_RX_DR 6 00055 #define MASK_TX_DS 5 00056 #define MASK_MAX_RT 4 00057 #define EN_CRC 3 00058 #define CRCO 2 00059 #define PWR_UP 1 00060 #define PRIM_RX 0 00061 #define ENAA_P5 5 00062 #define ENAA_P4 4 00063 #define ENAA_P3 3 00064 #define ENAA_P2 2 00065 #define ENAA_P1 1 00066 #define ENAA_P0 0 00067 #define ERX_P5 5 00068 #define ERX_P4 4 00069 #define ERX_P3 3 00070 #define ERX_P2 2 00071 #define ERX_P1 1 00072 #define ERX_P0 0 00073 #define AW 0 00074 #define ARD 4 00075 #define ARC 0 00076 #define PLL_LOCK 4 00077 #define RF_DR 3 00078 #define RF_PWR 6 00079 #define RX_DR 6 00080 #define TX_DS 5 00081 #define MAX_RT 4 00082 #define RX_P_NO 1 00083 #define TX_FULL 0 00084 #define PLOS_CNT 4 00085 #define ARC_CNT 0 00086 #define TX_REUSE 6 00087 #define FIFO_FULL 5 00088 #define TX_EMPTY 4 00089 #define RX_FULL 1 00090 #define RX_EMPTY 0 00091 #define DPL_P5 5 00092 #define DPL_P4 4 00093 #define DPL_P3 3 00094 #define DPL_P2 2 00095 #define DPL_P1 1 00096 #define DPL_P0 0 00097 #define EN_DPL 2 00098 #define EN_ACK_PAY 1 00099 #define EN_DYN_ACK 0 00100 00101 /* Instruction Mnemonics */ 00102 #define R_REGISTER 0x00 00103 #define W_REGISTER 0x20 00104 #define REGISTER_MASK 0x1F 00105 #define ACTIVATE 0x50 00106 #define R_RX_PL_WID 0x60 00107 #define R_RX_PAYLOAD 0x61 00108 #define W_TX_PAYLOAD 0xA0 00109 #define W_ACK_PAYLOAD 0xA8 00110 #define FLUSH_TX 0xE1 00111 #define FLUSH_RX 0xE2 00112 #define REUSE_TX_PL 0xE3 00113 #define NOP 0xFF 00114 00115 /* Non-P omissions */ 00116 #define LNA_HCURR 0 00117 00118 /* P model memory Map */ 00119 #define RPD 0x09 00120 00121 /* P model bit Mnemonics */ 00122 #define RF_DR_LOW 5 00123 #define RF_DR_HIGH 3 00124 #define RF_PWR_LOW 1 00125 #define RF_PWR_HIGH 2 00126 00127 #define HIGH 1 00128 #define LOW 0 00129 #define _BV(n) (1 << n) 00130 00131 /* 00132 Copyright (C) 2011 J. Coliz <maniacbug@ymail.com> 00133 00134 This program is free software; you can redistribute it and/or 00135 modify it under the terms of the GNU General Public License 00136 version 2 as published by the Free Software Foundation. 00137 */ 00138 00139 /** 00140 * @file RF24.h 00141 * 00142 * Class declaration for RF24 and helper enums 00143 */ 00144 00145 #ifndef __RF24_H__ 00146 #define __RF24_H__ 00147 00148 #include <mbed.h> 00149 00150 /** 00151 * Power Amplifier level. 00152 * 00153 * For use with setPALevel() 00154 */ 00155 typedef enum { RF24_PA_MIN = 0, RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX, RF24_PA_ERROR } rf24_pa_dbm_e ; 00156 00157 /** 00158 * Data rate. How fast data moves through the air. 00159 * 00160 * For use with setDataRate() 00161 */ 00162 typedef enum { RF24_1MBPS = 0, RF24_2MBPS, RF24_250KBPS } rf24_datarate_e; 00163 00164 /** 00165 * CRC Length. How big (if any) of a CRC is included. 00166 * 00167 * For use with setCRCLength() 00168 */ 00169 typedef enum { RF24_CRC_DISABLED = 0, RF24_CRC_8, RF24_CRC_16 } rf24_crclength_e; 00170 00171 /** 00172 * Driver for nRF24L01(+) 2.4GHz Wireless Transceiver 00173 */ 00174 00175 class RF24 00176 { 00177 private: 00178 DigitalOut ce_pin; /**< "Chip Enable" pin, activates the RX or TX role */ 00179 DigitalOut csn_pin; /**< SPI Chip select */ 00180 bool wide_band; /* 2Mbs data rate in use? */ 00181 bool p_variant; /* False for RF24L01 and true for RF24L01P */ 00182 uint8_t payload_size; /**< Fixed size of payloads */ 00183 bool ack_payload_available; /**< Whether there is an ack payload waiting */ 00184 bool dynamic_payloads_enabled; /**< Whether dynamic payloads are enabled. */ 00185 uint8_t ack_payload_length; /**< Dynamic size of pending ack payload. */ 00186 uint64_t pipe0_reading_address; /**< Last address set on pipe 0 for reading. */ 00187 SPI spi; 00188 Timer mainTimer; 00189 uint32_t txRxDelay; /**< Var for adjusting delays depending on datarate */ 00190 00191 protected: 00192 /** 00193 * @name Low-level internal interface. 00194 * 00195 * Protected methods that address the chip directly. Regular users cannot 00196 * ever call these. They are documented for completeness and for developers who 00197 * may want to extend this class. 00198 */ 00199 /**@{*/ 00200 00201 /** 00202 * Set chip select pin 00203 * 00204 * Running SPI bus at PI_CLOCK_DIV2 so we don't waste time transferring data 00205 * and best of all, we make use of the radio's FIFO buffers. A lower speed 00206 * means we're less likely to effectively leverage our FIFOs and pay a higher 00207 * AVR runtime cost as toll. 00208 * 00209 * @param mode HIGH to take this unit off the SPI bus, LOW to put it on 00210 */ 00211 void csn(int mode); 00212 00213 /** 00214 * Set chip enable 00215 * 00216 * @param level HIGH to actively begin transmission or LOW to put in standby. Please see data sheet 00217 * for a much more detailed description of this pin. 00218 */ 00219 void ce(int level); 00220 00221 00222 /** 00223 * Read a chunk of data in from a register 00224 * 00225 * @param reg Which register. Use constants from nRF24L01.h 00226 * @param buf Where to put the data 00227 * @param len How many bytes of data to transfer 00228 * @return Current value of status register 00229 */ 00230 uint8_t read_register(uint8_t reg, uint8_t* buf, uint8_t len); 00231 00232 /** 00233 * Read single byte from a register 00234 * 00235 * @param reg Which register. Use constants from nRF24L01.h 00236 * @return Current value of register @p reg 00237 */ 00238 uint8_t read_register(uint8_t reg); 00239 00240 /** 00241 * Write a chunk of data to a register 00242 * 00243 * @param reg Which register. Use constants from nRF24L01.h 00244 * @param buf Where to get the data 00245 * @param len How many bytes of data to transfer 00246 * @return Current value of status register 00247 */ 00248 uint8_t write_register(uint8_t reg, const uint8_t* buf, uint8_t len); 00249 00250 /** 00251 * Write a single byte to a register 00252 * 00253 * @param reg Which register. Use constants from nRF24L01.h 00254 * @param value The new value to write 00255 * @return Current value of status register 00256 */ 00257 uint8_t write_register(uint8_t reg, uint8_t value); 00258 00259 /** 00260 * Write the transmit payload 00261 * 00262 * The size of data written is the fixed payload size, see getPayloadSize() 00263 * 00264 * @param buf Where to get the data 00265 * @param len Number of bytes to be sent 00266 * @return Current value of status register 00267 */ 00268 uint8_t write_payload(const void* buf, uint8_t len); 00269 00270 /** 00271 * Read the receive payload 00272 * 00273 * The size of data read is the fixed payload size, see getPayloadSize() 00274 * 00275 * @param buf Where to put the data 00276 * @param len Maximum number of bytes to read 00277 * @return Current value of status register 00278 */ 00279 uint8_t read_payload(void* buf, uint8_t len); 00280 00281 00282 /** 00283 * Decode and print the given status to stdout 00284 * 00285 * @param status Status value to print 00286 * 00287 * @warning Does nothing if stdout is not defined. See fdevopen in stdio.h 00288 */ 00289 void print_status(uint8_t status); 00290 00291 /** 00292 * Decode and print the given 'observe_tx' value to stdout 00293 * 00294 * @param value The observe_tx value to print 00295 * 00296 * @warning Does nothing if stdout is not defined. See fdevopen in stdio.h 00297 */ 00298 void print_observe_tx(uint8_t value); 00299 00300 /** 00301 * Print the name and value of an 8-bit register to stdout 00302 * 00303 * Optionally it can print some quantity of successive 00304 * registers on the same line. This is useful for printing a group 00305 * of related registers on one line. 00306 * 00307 * @param name Name of the register 00308 * @param reg Which register. Use constants from nRF24L01.h 00309 * @param qty How many successive registers to print 00310 */ 00311 void print_byte_register(const char* name, uint8_t reg, uint8_t qty = 1); 00312 00313 /** 00314 * Print the name and value of a 40-bit address register to stdout 00315 * 00316 * Optionally it can print some quantity of successive 00317 * registers on the same line. This is useful for printing a group 00318 * of related registers on one line. 00319 * 00320 * @param name Name of the register 00321 * @param reg Which register. Use constants from nRF24L01.h 00322 * @param qty How many successive registers to print 00323 */ 00324 void print_address_register(const char* name, uint8_t reg, uint8_t qty = 1); 00325 00326 /** 00327 * Turn on or off the special features of the chip 00328 * 00329 * The chip has certain 'features' which are only available when the 'features' 00330 * are enabled. See the datasheet for details. 00331 */ 00332 void toggle_features(void); 00333 /**@}*/ 00334 00335 public: 00336 /** 00337 * @name Primary public interface 00338 * 00339 * These are the main methods you need to operate the chip 00340 */ 00341 /**@{*/ 00342 00343 /** 00344 * Constructor 00345 * 00346 * Creates a new instance of this driver. Before using, you create an instance 00347 * and send in the unique pins that this chip is connected to. 00348 * 00349 * @param _cepin The pin attached to Chip Enable on the RF module 00350 * @param _cspin The pin attached to Chip Select 00351 */ 00352 RF24(PinName mosi, PinName miso, PinName sck, PinName _csnpin, PinName _cepin); 00353 00354 /** 00355 * Begin operation of the chip 00356 * 00357 * Call this in setup(), before calling any other methods. 00358 * 00359 * @return True on success. False otherwise. 00360 */ 00361 bool begin(void); 00362 00363 /** 00364 * Retrieve the current status of the chip 00365 * 00366 * @return Current value of status register 00367 */ 00368 uint8_t get_status(void); 00369 00370 /** 00371 * Empty the receive buffer 00372 * 00373 * @return Current value of status register 00374 */ 00375 uint8_t flush_rx(void); 00376 00377 /** 00378 * Empty the transmit buffer 00379 * 00380 * @return Current value of status register 00381 */ 00382 uint8_t flush_tx(void); 00383 00384 /** 00385 * Start listening on the pipes opened for reading. 00386 * 00387 * Be sure to call openReadingPipe() first. Do not call write() while 00388 * in this mode, without first calling stopListening(). Call 00389 * isAvailable() to check for incoming traffic, and read() to get it. 00390 */ 00391 void startListening(void); 00392 00393 /** 00394 * Stop listening for incoming messages 00395 * 00396 * Do this before calling write(). 00397 */ 00398 void stopListening(void); 00399 00400 /** 00401 * Write to the open writing pipe 00402 * 00403 * Be sure to call openWritingPipe() first to set the destination 00404 * of where to write to. 00405 * 00406 * This blocks until the message is successfully acknowledged by 00407 * the receiver or the timeout/retransmit maxima are reached. In 00408 * the current configuration, the max delay here is 60ms. 00409 * 00410 * The maximum size of data written is the fixed payload size, see 00411 * getPayloadSize(). However, you can write less, and the remainder 00412 * will just be filled with zeroes. 00413 * 00414 * @param buf Pointer to the data to be sent 00415 * @param len Number of bytes to be sent 00416 * @return True if the payload was delivered successfully false if not 00417 */ 00418 bool write( const void* buf, uint8_t len ); 00419 00420 /** 00421 * Test whether there are bytes available to be read 00422 * 00423 * @return True if there is a payload available, false if none is 00424 */ 00425 bool available(void); 00426 00427 /** 00428 * Read the payload 00429 * 00430 * Return the last payload received 00431 * 00432 * The size of data read is the fixed payload size, see getPayloadSize() 00433 * 00434 * @note I specifically chose 'void*' as a data type to make it easier 00435 * for beginners to use. No casting needed. 00436 * 00437 * @param buf Pointer to a buffer where the data should be written 00438 * @param len Maximum number of bytes to read into the buffer 00439 * @return True if the payload was delivered successfully false if not 00440 */ 00441 bool read( void* buf, uint8_t len ); 00442 00443 /** 00444 * Open a pipe for writing 00445 * 00446 * Only one pipe can be open at once, but you can change the pipe 00447 * you'll listen to. Do not call this while actively listening. 00448 * Remember to stopListening() first. 00449 * 00450 * Addresses are 40-bit hex values, e.g.: 00451 * 00452 * @code 00453 * openWritingPipe(0xF0F0F0F0F0); 00454 * @endcode 00455 * 00456 * @param address The 40-bit address of the pipe to open. This can be 00457 * any value whatsoever, as long as you are the only one writing to it 00458 * and only one other radio is listening to it. Coordinate these pipe 00459 * addresses amongst nodes on the network. 00460 */ 00461 void openWritingPipe(uint64_t address); 00462 00463 /** 00464 * Open a pipe for reading 00465 * 00466 * Up to 6 pipes can be open for reading at once. Open all the 00467 * reading pipes, and then call startListening(). 00468 * 00469 * @see openWritingPipe 00470 * 00471 * @warning Pipes 1-5 should share the first 32 bits. 00472 * Only the least significant byte should be unique, e.g. 00473 * @code 00474 * openReadingPipe(1,0xF0F0F0F0AA); 00475 * openReadingPipe(2,0xF0F0F0F066); 00476 * @endcode 00477 * 00478 * @warning Pipe 0 is also used by the writing pipe. So if you open 00479 * pipe 0 for reading, and then startListening(), it will overwrite the 00480 * writing pipe. Ergo, do an openWritingPipe() again before write(). 00481 * 00482 * @todo Enforce the restriction that pipes 1-5 must share the top 32 bits 00483 * 00484 * @param number Which pipe# to open, 0-5. 00485 * @param address The 40-bit address of the pipe to open. 00486 */ 00487 void openReadingPipe(uint8_t number, uint64_t address); 00488 00489 /**@}*/ 00490 /** 00491 * @name Optional Configurators 00492 * 00493 * Methods you can use to get or set the configuration of the chip. 00494 * None are required. Calling begin() sets up a reasonable set of 00495 * defaults. 00496 */ 00497 /**@{*/ 00498 /** 00499 * Set the number and delay of retries upon failed submit 00500 * 00501 * @param delay How long to wait between each retry, in multiples of 250us, 00502 * max is 15. 0 means 250us, 15 means 4000us. 00503 * @param count How many retries before giving up, max 15 00504 */ 00505 void setRetries(uint8_t delay, uint8_t count); 00506 00507 /** 00508 * Set RF communication channel 00509 * 00510 * @param channel Which RF channel to communicate on, 0-127 00511 */ 00512 void setChannel(uint8_t channel); 00513 00514 /** 00515 * Set Static Payload Size 00516 * 00517 * This implementation uses a pre-stablished fixed payload size for all 00518 * transmissions. If this method is never called, the driver will always 00519 * transmit the maximum payload size (32 bytes), no matter how much 00520 * was sent to write(). 00521 * 00522 * @todo Implement variable-sized payloads feature 00523 * 00524 * @param size The number of bytes in the payload 00525 */ 00526 void setPayloadSize(uint8_t size); 00527 00528 /** 00529 * Get Static Payload Size 00530 * 00531 * @see setPayloadSize() 00532 * 00533 * @return The number of bytes in the payload 00534 */ 00535 uint8_t getPayloadSize(void); 00536 00537 /** 00538 * Get Dynamic Payload Size 00539 * 00540 * For dynamic payloads, this pulls the size of the payload off 00541 * the chip 00542 * 00543 * @return Payload length of last-received dynamic payload 00544 */ 00545 uint8_t getDynamicPayloadSize(void); 00546 00547 /** 00548 * Enable custom payloads on the acknowledge packets 00549 * 00550 * Ack payloads are a handy way to return data back to senders without 00551 * manually changing the radio modes on both units. 00552 * 00553 * @see examples/pingpair_pl/pingpair_pl.pde 00554 */ 00555 void enableAckPayload(void); 00556 00557 /** 00558 * Enable dynamically-sized payloads 00559 * 00560 * This way you don't always have to send large packets just to send them 00561 * once in a while. This enables dynamic payloads on ALL pipes. 00562 * 00563 * @see examples/pingpair_pl/pingpair_dyn.pde 00564 */ 00565 void enableDynamicPayloads(void); 00566 00567 /** 00568 * Determine whether the hardware is an nRF24L01+ or not. 00569 * 00570 * @return true if the hardware is nRF24L01+ (or compatible) and false 00571 * if its not. 00572 */ 00573 bool isPVariant(void) ; 00574 00575 /** 00576 * Enable or disable auto-acknowlede packets 00577 * 00578 * This is enabled by default, so it's only needed if you want to turn 00579 * it off for some reason. 00580 * 00581 * @param enable Whether to enable (true) or disable (false) auto-acks 00582 */ 00583 void setAutoAck(bool enable); 00584 00585 /** 00586 * Enable or disable auto-acknowlede packets on a per pipeline basis. 00587 * 00588 * AA is enabled by default, so it's only needed if you want to turn 00589 * it off/on for some reason on a per pipeline basis. 00590 * 00591 * @param pipe Which pipeline to modify 00592 * @param enable Whether to enable (true) or disable (false) auto-acks 00593 */ 00594 void setAutoAck( uint8_t pipe, bool enable ) ; 00595 00596 /** 00597 * Set Power Amplifier (PA) level to one of four levels. 00598 * Relative mnemonics have been used to allow for future PA level 00599 * changes. According to 6.5 of the nRF24L01+ specification sheet, 00600 * they translate to: RF24_PA_MIN=-18dBm, RF24_PA_LOW=-12dBm, 00601 * RF24_PA_MED=-6dBM, and RF24_PA_HIGH=0dBm. 00602 * 00603 * @param level Desired PA level. 00604 */ 00605 void setPALevel( rf24_pa_dbm_e level ) ; 00606 00607 /** 00608 * Fetches the current PA level. 00609 * 00610 * @return Returns a value from the rf24_pa_dbm_e enum describing 00611 * the current PA setting. Please remember, all values represented 00612 * by the enum mnemonics are negative dBm. See setPALevel for 00613 * return value descriptions. 00614 */ 00615 rf24_pa_dbm_e getPALevel( void ) ; 00616 00617 /** 00618 * Set the transmission data rate 00619 * 00620 * @warning setting RF24_250KBPS will fail for non-plus units 00621 * 00622 * @param speed RF24_250KBPS for 250kbs, RF24_1MBPS for 1Mbps, or RF24_2MBPS for 2Mbps 00623 * @return true if the change was successful 00624 */ 00625 bool setDataRate(rf24_datarate_e speed); 00626 00627 /** 00628 * Fetches the transmission data rate 00629 * 00630 * @return Returns the hardware's currently configured datarate. The value 00631 * is one of 250kbs, RF24_1MBPS for 1Mbps, or RF24_2MBPS, as defined in the 00632 * rf24_datarate_e enum. 00633 */ 00634 rf24_datarate_e getDataRate( void ) ; 00635 00636 /** 00637 * Set the CRC length 00638 * 00639 * @param length RF24_CRC_8 for 8-bit or RF24_CRC_16 for 16-bit 00640 */ 00641 void setCRCLength(rf24_crclength_e length); 00642 00643 /** 00644 * Get the CRC length 00645 * 00646 * @return RF24_DISABLED if disabled or RF24_CRC_8 for 8-bit or RF24_CRC_16 for 16-bit 00647 */ 00648 rf24_crclength_e getCRCLength(void); 00649 00650 /** 00651 * Disable CRC validation 00652 * 00653 */ 00654 void disableCRC( void ) ; 00655 00656 /**@}*/ 00657 /** 00658 * @name Advanced Operation 00659 * 00660 * Methods you can use to drive the chip in more advanced ways 00661 */ 00662 /**@{*/ 00663 00664 /** 00665 * Print a giant block of debugging information to stdout 00666 * 00667 * @warning Does nothing if stdout is not defined. See fdevopen in stdio.h 00668 */ 00669 void printDetails(void); 00670 00671 /** 00672 * Enter low-power mode 00673 * 00674 * To return to normal power mode, either write() some data or 00675 * startListening, or powerUp(). 00676 */ 00677 void powerDown(void); 00678 00679 /** 00680 * Leave low-power mode - making radio more responsive 00681 * 00682 * To return to low power mode, call powerDown(). 00683 */ 00684 void powerUp(void) ; 00685 00686 /** 00687 * Test whether there are bytes available to be read 00688 * 00689 * Use this version to discover on which pipe the message 00690 * arrived. 00691 * 00692 * @param[out] pipe_num Which pipe has the payload available 00693 * @return True if there is a payload available, false if none is 00694 */ 00695 bool available(uint8_t* pipe_num); 00696 00697 /** 00698 * Non-blocking write to the open writing pipe 00699 * 00700 * Just like write(), but it returns immediately. To find out what happened 00701 * to the send, catch the IRQ and then call whatHappened(). 00702 * 00703 * @see write() 00704 * @see whatHappened() 00705 * 00706 * @param buf Pointer to the data to be sent 00707 * @param len Number of bytes to be sent 00708 * @return True if the payload was delivered successfully false if not 00709 */ 00710 void startWrite( const void* buf, uint8_t len ); 00711 00712 /** 00713 * Write an ack payload for the specified pipe 00714 * 00715 * The next time a message is received on @p pipe, the data in @p buf will 00716 * be sent back in the acknowledgement. 00717 * 00718 * @warning According to the data sheet, only three of these can be pending 00719 * at any time. I have not tested this. 00720 * 00721 * @param pipe Which pipe# (typically 1-5) will get this response. 00722 * @param buf Pointer to data that is sent 00723 * @param len Length of the data to send, up to 32 bytes max. Not affected 00724 * by the static payload set by setPayloadSize(). 00725 */ 00726 void writeAckPayload(uint8_t pipe, const void* buf, uint8_t len); 00727 00728 /** 00729 * Determine if an ack payload was received in the most recent call to 00730 * write(). 00731 * 00732 * Call read() to retrieve the ack payload. 00733 * 00734 * @warning Calling this function clears the internal flag which indicates 00735 * a payload is available. If it returns true, you must read the packet 00736 * out as the very next interaction with the radio, or the results are 00737 * undefined. 00738 * 00739 * @return True if an ack payload is available. 00740 */ 00741 bool isAckPayloadAvailable(void); 00742 00743 /** 00744 * Call this when you get an interrupt to find out why 00745 * 00746 * Tells you what caused the interrupt, and clears the state of 00747 * interrupts. 00748 * 00749 * @param[out] tx_ok The send was successful (TX_DS) 00750 * @param[out] tx_fail The send failed, too many retries (MAX_RT) 00751 * @param[out] rx_ready There is a message waiting to be read (RX_DS) 00752 */ 00753 void whatHappened(bool& tx_ok,bool& tx_fail,bool& rx_ready); 00754 00755 /** 00756 * Test whether there was a carrier on the line for the 00757 * previous listening period. 00758 * 00759 * Useful to check for interference on the current channel. 00760 * 00761 * @return true if was carrier, false if not 00762 */ 00763 bool testCarrier(void); 00764 00765 /** 00766 * Test whether a signal (carrier or otherwise) greater than 00767 * or equal to -64dBm is present on the channel. Valid only 00768 * on nRF24L01P (+) hardware. On nRF24L01, use testCarrier(). 00769 * 00770 * Useful to check for interference on the current channel and 00771 * channel hopping strategies. 00772 * 00773 * @return true if signal => -64dBm, false if not 00774 */ 00775 bool testRPD(void) ; 00776 00777 uint8_t min (uint8_t, uint8_t); 00778 }; 00779 00780 00781 #endif // __RF24_H__
Generated on Wed Jul 13 2022 10:10:40 by
