Maniacbug's nRF24L01 arduino library ported to mbed. Functional with minor issues.
Fork of nRF24L01P_Maniacbug by
nRF24L01P_Maniacbug.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 RF_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 RF_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 RF_HIGH 1 00128 #define RF_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 00190 protected: 00191 /** 00192 * @name Low-level internal interface. 00193 * 00194 * Protected methods that address the chip directly. Regular users cannot 00195 * ever call these. They are documented for completeness and for developers who 00196 * may want to extend this class. 00197 */ 00198 /**@{*/ 00199 00200 /** 00201 * Set chip select pin 00202 * 00203 * Running SPI bus at PI_CLOCK_DIV2 so we don't waste time transferring data 00204 * and best of all, we make use of the radio's FIFO buffers. A lower speed 00205 * means we're less likely to effectively leverage our FIFOs and pay a higher 00206 * AVR runtime cost as toll. 00207 * 00208 * @param mode HIGH to take this unit off the SPI bus, LOW to put it on 00209 */ 00210 void csn(int mode); 00211 00212 /** 00213 * Set chip enable 00214 * 00215 * @param level HIGH to actively begin transmission or LOW to put in standby. Please see data sheet 00216 * for a much more detailed description of this pin. 00217 */ 00218 void ce(int level); 00219 00220 00221 /** 00222 * Read a chunk of data in from a register 00223 * 00224 * @param reg Which register. Use constants from nRF24L01.h 00225 * @param buf Where to put the data 00226 * @param len How many bytes of data to transfer 00227 * @return Current value of status register 00228 */ 00229 uint8_t read_register(uint8_t reg, uint8_t* buf, uint8_t len); 00230 00231 /** 00232 * Read single byte from a register 00233 * 00234 * @param reg Which register. Use constants from nRF24L01.h 00235 * @return Current value of register @p reg 00236 */ 00237 uint8_t read_register(uint8_t reg); 00238 00239 /** 00240 * Write a chunk of data to a register 00241 * 00242 * @param reg Which register. Use constants from nRF24L01.h 00243 * @param buf Where to get the data 00244 * @param len How many bytes of data to transfer 00245 * @return Current value of status register 00246 */ 00247 uint8_t write_register(uint8_t reg, const uint8_t* buf, uint8_t len); 00248 00249 /** 00250 * Write a single byte to a register 00251 * 00252 * @param reg Which register. Use constants from nRF24L01.h 00253 * @param value The new value to write 00254 * @return Current value of status register 00255 */ 00256 uint8_t write_register(uint8_t reg, uint8_t value); 00257 00258 /** 00259 * Write the transmit payload 00260 * 00261 * The size of data written is the fixed payload size, see getPayloadSize() 00262 * 00263 * @param buf Where to get the data 00264 * @param len Number of bytes to be sent 00265 * @return Current value of status register 00266 */ 00267 uint8_t write_payload(const void* buf, uint8_t len); 00268 00269 /** 00270 * Read the receive payload 00271 * 00272 * The size of data read is the fixed payload size, see getPayloadSize() 00273 * 00274 * @param buf Where to put the data 00275 * @param len Maximum number of bytes to read 00276 * @return Current value of status register 00277 */ 00278 uint8_t read_payload(void* buf, uint8_t len); 00279 00280 00281 /** 00282 * Decode and print the given status to stdout 00283 * 00284 * @param status Status value to print 00285 * 00286 * @warning Does nothing if stdout is not defined. See fdevopen in stdio.h 00287 */ 00288 void print_status(uint8_t status); 00289 00290 /** 00291 * Decode and print the given 'observe_tx' value to stdout 00292 * 00293 * @param value The observe_tx value to print 00294 * 00295 * @warning Does nothing if stdout is not defined. See fdevopen in stdio.h 00296 */ 00297 void print_observe_tx(uint8_t value); 00298 00299 /** 00300 * Print the name and value of an 8-bit register to stdout 00301 * 00302 * Optionally it can print some quantity of successive 00303 * registers on the same line. This is useful for printing a group 00304 * of related registers on one line. 00305 * 00306 * @param name Name of the register 00307 * @param reg Which register. Use constants from nRF24L01.h 00308 * @param qty How many successive registers to print 00309 */ 00310 void print_byte_register(const char* name, uint8_t reg, uint8_t qty = 1); 00311 00312 /** 00313 * Print the name and value of a 40-bit address register to stdout 00314 * 00315 * Optionally it can print some quantity of successive 00316 * registers on the same line. This is useful for printing a group 00317 * of related registers on one line. 00318 * 00319 * @param name Name of the register 00320 * @param reg Which register. Use constants from nRF24L01.h 00321 * @param qty How many successive registers to print 00322 */ 00323 void print_address_register(const char* name, uint8_t reg, uint8_t qty = 1); 00324 00325 /** 00326 * Turn on or off the special features of the chip 00327 * 00328 * The chip has certain 'features' which are only available when the 'features' 00329 * are enabled. See the datasheet for details. 00330 */ 00331 void toggle_features(void); 00332 /**@}*/ 00333 00334 public: 00335 /** 00336 * @name Primary public interface 00337 * 00338 * These are the main methods you need to operate the chip 00339 */ 00340 /**@{*/ 00341 00342 /** 00343 * Constructor 00344 * 00345 * Creates a new instance of this driver. Before using, you create an instance 00346 * and send in the unique pins that this chip is connected to. 00347 * 00348 * @param _cepin The pin attached to Chip Enable on the RF module 00349 * @param _cspin The pin attached to Chip Select 00350 */ 00351 RF24(PinName mosi, PinName miso, PinName sck, PinName _csnpin, PinName _cepin); 00352 00353 /** 00354 * Begin operation of the chip 00355 * 00356 * Call this in setup(), before calling any other methods. 00357 */ 00358 void begin(void); 00359 00360 /** 00361 * Retrieve the current status of the chip 00362 * 00363 * @return Current value of status register 00364 */ 00365 uint8_t get_status(void); 00366 00367 /** 00368 * Empty the receive buffer 00369 * 00370 * @return Current value of status register 00371 */ 00372 uint8_t flush_rx(void); 00373 00374 /** 00375 * Empty the transmit buffer 00376 * 00377 * @return Current value of status register 00378 */ 00379 uint8_t flush_tx(void); 00380 00381 /** 00382 * Start listening on the pipes opened for reading. 00383 * 00384 * Be sure to call openReadingPipe() first. Do not call write() while 00385 * in this mode, without first calling stopListening(). Call 00386 * isAvailable() to check for incoming traffic, and read() to get it. 00387 */ 00388 void startListening(void); 00389 00390 /** 00391 * Stop listening for incoming messages 00392 * 00393 * Do this before calling write(). 00394 */ 00395 void stopListening(void); 00396 00397 /** 00398 * Write to the open writing pipe 00399 * 00400 * Be sure to call openWritingPipe() first to set the destination 00401 * of where to write to. 00402 * 00403 * This blocks until the message is successfully acknowledged by 00404 * the receiver or the timeout/retransmit maxima are reached. In 00405 * the current configuration, the max delay here is 60ms. 00406 * 00407 * The maximum size of data written is the fixed payload size, see 00408 * getPayloadSize(). However, you can write less, and the remainder 00409 * will just be filled with zeroes. 00410 * 00411 * @param buf Pointer to the data to be sent 00412 * @param len Number of bytes to be sent 00413 * @return True if the payload was delivered successfully false if not 00414 */ 00415 bool write( const void* buf, uint8_t len ); 00416 00417 /** 00418 * Test whether there are bytes available to be read 00419 * 00420 * @return True if there is a payload available, false if none is 00421 */ 00422 bool available(void); 00423 00424 /** 00425 * Read the payload 00426 * 00427 * Return the last payload received 00428 * 00429 * The size of data read is the fixed payload size, see getPayloadSize() 00430 * 00431 * @note I specifically chose 'void*' as a data type to make it easier 00432 * for beginners to use. No casting needed. 00433 * 00434 * @param buf Pointer to a buffer where the data should be written 00435 * @param len Maximum number of bytes to read into the buffer 00436 * @return True if the payload was delivered successfully false if not 00437 */ 00438 bool read( void* buf, uint8_t len ); 00439 00440 /** 00441 * Open a pipe for writing 00442 * 00443 * Only one pipe can be open at once, but you can change the pipe 00444 * you'll listen to. Do not call this while actively listening. 00445 * Remember to stopListening() first. 00446 * 00447 * Addresses are 40-bit hex values, e.g.: 00448 * 00449 * @code 00450 * openWritingPipe(0xF0F0F0F0F0); 00451 * @endcode 00452 * 00453 * @param address The 40-bit address of the pipe to open. This can be 00454 * any value whatsoever, as long as you are the only one writing to it 00455 * and only one other radio is listening to it. Coordinate these pipe 00456 * addresses amongst nodes on the network. 00457 */ 00458 void openWritingPipe(uint64_t address); 00459 00460 /** 00461 * Open a pipe for reading 00462 * 00463 * Up to 6 pipes can be open for reading at once. Open all the 00464 * reading pipes, and then call startListening(). 00465 * 00466 * @see openWritingPipe 00467 * 00468 * @warning Pipes 1-5 should share the first 32 bits. 00469 * Only the least significant byte should be unique, e.g. 00470 * @code 00471 * openReadingPipe(1,0xF0F0F0F0AA); 00472 * openReadingPipe(2,0xF0F0F0F066); 00473 * @endcode 00474 * 00475 * @warning Pipe 0 is also used by the writing pipe. So if you open 00476 * pipe 0 for reading, and then startListening(), it will overwrite the 00477 * writing pipe. Ergo, do an openWritingPipe() again before write(). 00478 * 00479 * @todo Enforce the restriction that pipes 1-5 must share the top 32 bits 00480 * 00481 * @param number Which pipe# to open, 0-5. 00482 * @param address The 40-bit address of the pipe to open. 00483 */ 00484 void openReadingPipe(uint8_t number, uint64_t address); 00485 00486 /**@}*/ 00487 /** 00488 * @name Optional Configurators 00489 * 00490 * Methods you can use to get or set the configuration of the chip. 00491 * None are required. Calling begin() sets up a reasonable set of 00492 * defaults. 00493 */ 00494 /**@{*/ 00495 /** 00496 * Set the number and delay of retries upon failed submit 00497 * 00498 * @param delay How long to wait between each retry, in multiples of 250us, 00499 * max is 15. 0 means 250us, 15 means 4000us. 00500 * @param count How many retries before giving up, max 15 00501 */ 00502 void setRetries(uint8_t delay, uint8_t count); 00503 00504 /** 00505 * Set RF communication channel 00506 * 00507 * @param channel Which RF channel to communicate on, 0-127 00508 */ 00509 void setChannel(uint8_t channel); 00510 00511 /** 00512 * Set Static Payload Size 00513 * 00514 * This implementation uses a pre-stablished fixed payload size for all 00515 * transmissions. If this method is never called, the driver will always 00516 * transmit the maximum payload size (32 bytes), no matter how much 00517 * was sent to write(). 00518 * 00519 * @todo Implement variable-sized payloads feature 00520 * 00521 * @param size The number of bytes in the payload 00522 */ 00523 void setPayloadSize(uint8_t size); 00524 00525 /** 00526 * Get Static Payload Size 00527 * 00528 * @see setPayloadSize() 00529 * 00530 * @return The number of bytes in the payload 00531 */ 00532 uint8_t getPayloadSize(void); 00533 00534 /** 00535 * Get Dynamic Payload Size 00536 * 00537 * For dynamic payloads, this pulls the size of the payload off 00538 * the chip 00539 * 00540 * @return Payload length of last-received dynamic payload 00541 */ 00542 uint8_t getDynamicPayloadSize(void); 00543 00544 /** 00545 * Enable custom payloads on the acknowledge packets 00546 * 00547 * Ack payloads are a handy way to return data back to senders without 00548 * manually changing the radio modes on both units. 00549 * 00550 * @see examples/pingpair_pl/pingpair_pl.pde 00551 */ 00552 void enableAckPayload(void); 00553 00554 /** 00555 * Enable dynamically-sized payloads 00556 * 00557 * This way you don't always have to send large packets just to send them 00558 * once in a while. This enables dynamic payloads on ALL pipes. 00559 * 00560 * @see examples/pingpair_pl/pingpair_dyn.pde 00561 */ 00562 void enableDynamicPayloads(void); 00563 00564 /** 00565 * Determine whether the hardware is an nRF24L01+ or not. 00566 * 00567 * @return true if the hardware is nRF24L01+ (or compatible) and false 00568 * if its not. 00569 */ 00570 bool isPVariant(void) ; 00571 00572 /** 00573 * Enable or disable auto-acknowlede packets 00574 * 00575 * This is enabled by default, so it's only needed if you want to turn 00576 * it off for some reason. 00577 * 00578 * @param enable Whether to enable (true) or disable (false) auto-acks 00579 */ 00580 void setAutoAck(bool enable); 00581 00582 /** 00583 * Enable or disable auto-acknowlede packets on a per pipeline basis. 00584 * 00585 * AA is enabled by default, so it's only needed if you want to turn 00586 * it off/on for some reason on a per pipeline basis. 00587 * 00588 * @param pipe Which pipeline to modify 00589 * @param enable Whether to enable (true) or disable (false) auto-acks 00590 */ 00591 void setAutoAck( uint8_t pipe, bool enable ) ; 00592 00593 /** 00594 * Set Power Amplifier (PA) level to one of four levels. 00595 * Relative mnemonics have been used to allow for future PA level 00596 * changes. According to 6.5 of the nRF24L01+ specification sheet, 00597 * they translate to: RF24_PA_MIN=-18dBm, RF24_PA_LOW=-12dBm, 00598 * RF24_PA_MED=-6dBM, and RF24_PA_HIGH=0dBm. 00599 * 00600 * @param level Desired PA level. 00601 */ 00602 void setPALevel( rf24_pa_dbm_e level ) ; 00603 00604 /** 00605 * Fetches the current PA level. 00606 * 00607 * @return Returns a value from the rf24_pa_dbm_e enum describing 00608 * the current PA setting. Please remember, all values represented 00609 * by the enum mnemonics are negative dBm. See setPALevel for 00610 * return value descriptions. 00611 */ 00612 rf24_pa_dbm_e getPALevel( void ) ; 00613 00614 /** 00615 * Set the transmission data rate 00616 * 00617 * @warning setting RF24_250KBPS will fail for non-plus units 00618 * 00619 * @param speed RF24_250KBPS for 250kbs, RF24_1MBPS for 1Mbps, or RF24_2MBPS for 2Mbps 00620 * @return true if the change was successful 00621 */ 00622 bool setDataRate(rf24_datarate_e speed); 00623 00624 /** 00625 * Fetches the transmission data rate 00626 * 00627 * @return Returns the hardware's currently configured datarate. The value 00628 * is one of 250kbs, RF24_1MBPS for 1Mbps, or RF24_2MBPS, as defined in the 00629 * rf24_datarate_e enum. 00630 */ 00631 rf24_datarate_e getDataRate( void ) ; 00632 00633 /** 00634 * Set the CRC length 00635 * 00636 * @param length RF24_CRC_8 for 8-bit or RF24_CRC_16 for 16-bit 00637 */ 00638 void setCRCLength(rf24_crclength_e length); 00639 00640 /** 00641 * Get the CRC length 00642 * 00643 * @return RF24_DISABLED if disabled or RF24_CRC_8 for 8-bit or RF24_CRC_16 for 16-bit 00644 */ 00645 rf24_crclength_e getCRCLength(void); 00646 00647 /** 00648 * Disable CRC validation 00649 * 00650 */ 00651 void disableCRC( void ) ; 00652 00653 /**@}*/ 00654 /** 00655 * @name Advanced Operation 00656 * 00657 * Methods you can use to drive the chip in more advanced ways 00658 */ 00659 /**@{*/ 00660 00661 /** 00662 * Print a giant block of debugging information to stdout 00663 * 00664 * @warning Does nothing if stdout is not defined. See fdevopen in stdio.h 00665 */ 00666 void printDetails(void); 00667 00668 /** 00669 * Enter low-power mode 00670 * 00671 * To return to normal power mode, either write() some data or 00672 * startListening, or powerUp(). 00673 */ 00674 void powerDown(void); 00675 00676 /** 00677 * Leave low-power mode - making radio more responsive 00678 * 00679 * To return to low power mode, call powerDown(). 00680 */ 00681 void powerUp(void) ; 00682 00683 /** 00684 * Test whether there are bytes available to be read 00685 * 00686 * Use this version to discover on which pipe the message 00687 * arrived. 00688 * 00689 * @param[out] pipe_num Which pipe has the payload available 00690 * @return True if there is a payload available, false if none is 00691 */ 00692 bool available(uint8_t* pipe_num); 00693 00694 /** 00695 * Non-blocking write to the open writing pipe 00696 * 00697 * Just like write(), but it returns immediately. To find out what happened 00698 * to the send, catch the IRQ and then call whatHappened(). 00699 * 00700 * @see write() 00701 * @see whatHappened() 00702 * 00703 * @param buf Pointer to the data to be sent 00704 * @param len Number of bytes to be sent 00705 * @return True if the payload was delivered successfully false if not 00706 */ 00707 void startWrite( const void* buf, uint8_t len ); 00708 00709 /** 00710 * Write an ack payload for the specified pipe 00711 * 00712 * The next time a message is received on @p pipe, the data in @p buf will 00713 * be sent back in the acknowledgement. 00714 * 00715 * @warning According to the data sheet, only three of these can be pending 00716 * at any time. I have not tested this. 00717 * 00718 * @param pipe Which pipe# (typically 1-5) will get this response. 00719 * @param buf Pointer to data that is sent 00720 * @param len Length of the data to send, up to 32 bytes max. Not affected 00721 * by the static payload set by setPayloadSize(). 00722 */ 00723 void writeAckPayload(uint8_t pipe, const void* buf, uint8_t len); 00724 00725 /** 00726 * Determine if an ack payload was received in the most recent call to 00727 * write(). 00728 * 00729 * Call read() to retrieve the ack payload. 00730 * 00731 * @warning Calling this function clears the internal flag which indicates 00732 * a payload is available. If it returns true, you must read the packet 00733 * out as the very next interaction with the radio, or the results are 00734 * undefined. 00735 * 00736 * @return True if an ack payload is available. 00737 */ 00738 bool isAckPayloadAvailable(void); 00739 00740 /** 00741 * Call this when you get an interrupt to find out why 00742 * 00743 * Tells you what caused the interrupt, and clears the state of 00744 * interrupts. 00745 * 00746 * @param[out] tx_ok The send was successful (TX_DS) 00747 * @param[out] tx_fail The send failed, too many retries (MAX_RT) 00748 * @param[out] rx_ready There is a message waiting to be read (RX_DS) 00749 */ 00750 void whatHappened(bool& tx_ok,bool& tx_fail,bool& rx_ready); 00751 00752 /** 00753 * Test whether there was a carrier on the line for the 00754 * previous listening period. 00755 * 00756 * Useful to check for interference on the current channel. 00757 * 00758 * @return true if was carrier, false if not 00759 */ 00760 bool testCarrier(void); 00761 00762 /** 00763 * Test whether a signal (carrier or otherwise) greater than 00764 * or equal to -64dBm is present on the channel. Valid only 00765 * on nRF24L01P (+) hardware. On nRF24L01, use testCarrier(). 00766 * 00767 * Useful to check for interference on the current channel and 00768 * channel hopping strategies. 00769 * 00770 * @return true if signal => -64dBm, false if not 00771 */ 00772 bool testRPD(void) ; 00773 00774 uint8_t min(uint8_t, uint8_t); 00775 }; 00776 00777 00778 #endif // __RF24_H__ 00779 // vim:ai:cin:sts=2 sw=2 ft=cpp
Generated on Thu Jul 14 2022 21:20:38 by 1.7.2