Basic port of the gcopeland nRF24L01 library

Dependencies:   mbed

Committer:
iforce2d
Date:
Mon Mar 25 07:35:02 2019 +0000
Revision:
2:75a5b58b2338
Basic port of gcopeland nRF24L01 library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
iforce2d 2:75a5b58b2338 1 /*
iforce2d 2:75a5b58b2338 2 Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
iforce2d 2:75a5b58b2338 3
iforce2d 2:75a5b58b2338 4 This program is free software; you can redistribute it and/or
iforce2d 2:75a5b58b2338 5 modify it under the terms of the GNU General Public License
iforce2d 2:75a5b58b2338 6 version 2 as published by the Free Software Foundation.
iforce2d 2:75a5b58b2338 7 */
iforce2d 2:75a5b58b2338 8
iforce2d 2:75a5b58b2338 9 /**
iforce2d 2:75a5b58b2338 10 * @file RF24.h
iforce2d 2:75a5b58b2338 11 *
iforce2d 2:75a5b58b2338 12 * Class declaration for RF24 and helper enums
iforce2d 2:75a5b58b2338 13 */
iforce2d 2:75a5b58b2338 14
iforce2d 2:75a5b58b2338 15 #ifndef __RF24_H__
iforce2d 2:75a5b58b2338 16 #define __RF24_H__
iforce2d 2:75a5b58b2338 17
iforce2d 2:75a5b58b2338 18 #include "mbed.h"
iforce2d 2:75a5b58b2338 19 #include <RF24_config.h>
iforce2d 2:75a5b58b2338 20
iforce2d 2:75a5b58b2338 21 /**
iforce2d 2:75a5b58b2338 22 * Power Amplifier level.
iforce2d 2:75a5b58b2338 23 *
iforce2d 2:75a5b58b2338 24 * For use with setPALevel()
iforce2d 2:75a5b58b2338 25 */
iforce2d 2:75a5b58b2338 26 typedef enum { RF24_PA_MIN = 0,RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX, RF24_PA_ERROR } rf24_pa_dbm_e ;
iforce2d 2:75a5b58b2338 27
iforce2d 2:75a5b58b2338 28 /**
iforce2d 2:75a5b58b2338 29 * Data rate. How fast data moves through the air.
iforce2d 2:75a5b58b2338 30 *
iforce2d 2:75a5b58b2338 31 * For use with setDataRate()
iforce2d 2:75a5b58b2338 32 */
iforce2d 2:75a5b58b2338 33 typedef enum { RF24_1MBPS = 0, RF24_2MBPS, RF24_250KBPS } rf24_datarate_e;
iforce2d 2:75a5b58b2338 34
iforce2d 2:75a5b58b2338 35 /**
iforce2d 2:75a5b58b2338 36 * CRC Length. How big (if any) of a CRC is included.
iforce2d 2:75a5b58b2338 37 *
iforce2d 2:75a5b58b2338 38 * For use with setCRCLength()
iforce2d 2:75a5b58b2338 39 */
iforce2d 2:75a5b58b2338 40 typedef enum { RF24_CRC_DISABLED = 0, RF24_CRC_8, RF24_CRC_16 } rf24_crclength_e;
iforce2d 2:75a5b58b2338 41
iforce2d 2:75a5b58b2338 42 /**
iforce2d 2:75a5b58b2338 43 * Driver for nRF24L01(+) 2.4GHz Wireless Transceiver
iforce2d 2:75a5b58b2338 44 */
iforce2d 2:75a5b58b2338 45
iforce2d 2:75a5b58b2338 46 class RF24
iforce2d 2:75a5b58b2338 47 {
iforce2d 2:75a5b58b2338 48 private:
iforce2d 2:75a5b58b2338 49 uint8_t ce_pin; /**< "Chip Enable" pin, activates the RX or TX role */
iforce2d 2:75a5b58b2338 50 uint8_t csn_pin; /**< SPI Chip select */
iforce2d 2:75a5b58b2338 51 bool wide_band; /* 2Mbs data rate in use? */
iforce2d 2:75a5b58b2338 52 bool p_variant; /* False for RF24L01 and true for RF24L01P */
iforce2d 2:75a5b58b2338 53 uint8_t payload_size; /**< Fixed size of payloads */
iforce2d 2:75a5b58b2338 54 bool ack_payload_available; /**< Whether there is an ack payload waiting */
iforce2d 2:75a5b58b2338 55 bool dynamic_payloads_enabled; /**< Whether dynamic payloads are enabled. */
iforce2d 2:75a5b58b2338 56 uint8_t ack_payload_length; /**< Dynamic size of pending ack payload. */
iforce2d 2:75a5b58b2338 57 uint64_t pipe0_reading_address; /**< Last address set on pipe 0 for reading. */
iforce2d 2:75a5b58b2338 58
iforce2d 2:75a5b58b2338 59 DigitalOut do_csn;
iforce2d 2:75a5b58b2338 60 DigitalOut do_ce;
iforce2d 2:75a5b58b2338 61 SPI spi;
iforce2d 2:75a5b58b2338 62 Timer timer;
iforce2d 2:75a5b58b2338 63
iforce2d 2:75a5b58b2338 64 protected:
iforce2d 2:75a5b58b2338 65 /**
iforce2d 2:75a5b58b2338 66 * @name Low-level internal interface.
iforce2d 2:75a5b58b2338 67 *
iforce2d 2:75a5b58b2338 68 * Protected methods that address the chip directly. Regular users cannot
iforce2d 2:75a5b58b2338 69 * ever call these. They are documented for completeness and for developers who
iforce2d 2:75a5b58b2338 70 * may want to extend this class.
iforce2d 2:75a5b58b2338 71 */
iforce2d 2:75a5b58b2338 72 /**@{*/
iforce2d 2:75a5b58b2338 73
iforce2d 2:75a5b58b2338 74 /**
iforce2d 2:75a5b58b2338 75 * Set chip select pin
iforce2d 2:75a5b58b2338 76 *
iforce2d 2:75a5b58b2338 77 * Running SPI bus at PI_CLOCK_DIV2 so we don't waste time transferring data
iforce2d 2:75a5b58b2338 78 * and best of all, we make use of the radio's FIFO buffers. A lower speed
iforce2d 2:75a5b58b2338 79 * means we're less likely to effectively leverage our FIFOs and pay a higher
iforce2d 2:75a5b58b2338 80 * AVR runtime cost as toll.
iforce2d 2:75a5b58b2338 81 *
iforce2d 2:75a5b58b2338 82 * @param mode HIGH to take this unit off the SPI bus, LOW to put it on
iforce2d 2:75a5b58b2338 83 */
iforce2d 2:75a5b58b2338 84 void csn(int mode);
iforce2d 2:75a5b58b2338 85
iforce2d 2:75a5b58b2338 86 /**
iforce2d 2:75a5b58b2338 87 * Set chip enable
iforce2d 2:75a5b58b2338 88 *
iforce2d 2:75a5b58b2338 89 * @param level HIGH to actively begin transmission or LOW to put in standby. Please see data sheet
iforce2d 2:75a5b58b2338 90 * for a much more detailed description of this pin.
iforce2d 2:75a5b58b2338 91 */
iforce2d 2:75a5b58b2338 92 void ce(int level);
iforce2d 2:75a5b58b2338 93
iforce2d 2:75a5b58b2338 94 /**
iforce2d 2:75a5b58b2338 95 * Read a chunk of data in from a register
iforce2d 2:75a5b58b2338 96 *
iforce2d 2:75a5b58b2338 97 * @param reg Which register. Use constants from nRF24L01.h
iforce2d 2:75a5b58b2338 98 * @param buf Where to put the data
iforce2d 2:75a5b58b2338 99 * @param len How many bytes of data to transfer
iforce2d 2:75a5b58b2338 100 * @return Current value of status register
iforce2d 2:75a5b58b2338 101 */
iforce2d 2:75a5b58b2338 102 uint8_t read_register(uint8_t reg, uint8_t* buf, uint8_t len);
iforce2d 2:75a5b58b2338 103
iforce2d 2:75a5b58b2338 104 /**
iforce2d 2:75a5b58b2338 105 * Read single byte from a register
iforce2d 2:75a5b58b2338 106 *
iforce2d 2:75a5b58b2338 107 * @param reg Which register. Use constants from nRF24L01.h
iforce2d 2:75a5b58b2338 108 * @return Current value of register @p reg
iforce2d 2:75a5b58b2338 109 */
iforce2d 2:75a5b58b2338 110 uint8_t read_register(uint8_t reg);
iforce2d 2:75a5b58b2338 111
iforce2d 2:75a5b58b2338 112 /**
iforce2d 2:75a5b58b2338 113 * Write a chunk of data to a register
iforce2d 2:75a5b58b2338 114 *
iforce2d 2:75a5b58b2338 115 * @param reg Which register. Use constants from nRF24L01.h
iforce2d 2:75a5b58b2338 116 * @param buf Where to get the data
iforce2d 2:75a5b58b2338 117 * @param len How many bytes of data to transfer
iforce2d 2:75a5b58b2338 118 * @return Current value of status register
iforce2d 2:75a5b58b2338 119 */
iforce2d 2:75a5b58b2338 120 uint8_t write_register(uint8_t reg, const uint8_t* buf, uint8_t len);
iforce2d 2:75a5b58b2338 121
iforce2d 2:75a5b58b2338 122 /**
iforce2d 2:75a5b58b2338 123 * Write a single byte to a register
iforce2d 2:75a5b58b2338 124 *
iforce2d 2:75a5b58b2338 125 * @param reg Which register. Use constants from nRF24L01.h
iforce2d 2:75a5b58b2338 126 * @param value The new value to write
iforce2d 2:75a5b58b2338 127 * @return Current value of status register
iforce2d 2:75a5b58b2338 128 */
iforce2d 2:75a5b58b2338 129 uint8_t write_register(uint8_t reg, uint8_t value);
iforce2d 2:75a5b58b2338 130
iforce2d 2:75a5b58b2338 131 /**
iforce2d 2:75a5b58b2338 132 * Write the transmit payload
iforce2d 2:75a5b58b2338 133 *
iforce2d 2:75a5b58b2338 134 * The size of data written is the fixed payload size, see getPayloadSize()
iforce2d 2:75a5b58b2338 135 *
iforce2d 2:75a5b58b2338 136 * @param buf Where to get the data
iforce2d 2:75a5b58b2338 137 * @param len Number of bytes to be sent
iforce2d 2:75a5b58b2338 138 * @return Current value of status register
iforce2d 2:75a5b58b2338 139 */
iforce2d 2:75a5b58b2338 140 uint8_t write_payload(const void* buf, uint8_t len);
iforce2d 2:75a5b58b2338 141
iforce2d 2:75a5b58b2338 142 /**
iforce2d 2:75a5b58b2338 143 * Read the receive payload
iforce2d 2:75a5b58b2338 144 *
iforce2d 2:75a5b58b2338 145 * The size of data read is the fixed payload size, see getPayloadSize()
iforce2d 2:75a5b58b2338 146 *
iforce2d 2:75a5b58b2338 147 * @param buf Where to put the data
iforce2d 2:75a5b58b2338 148 * @param len Maximum number of bytes to read
iforce2d 2:75a5b58b2338 149 * @return Current value of status register
iforce2d 2:75a5b58b2338 150 */
iforce2d 2:75a5b58b2338 151 uint8_t read_payload(void* buf, uint8_t len);
iforce2d 2:75a5b58b2338 152
iforce2d 2:75a5b58b2338 153 /**
iforce2d 2:75a5b58b2338 154 * Empty the receive buffer
iforce2d 2:75a5b58b2338 155 *
iforce2d 2:75a5b58b2338 156 * @return Current value of status register
iforce2d 2:75a5b58b2338 157 */
iforce2d 2:75a5b58b2338 158 uint8_t flush_rx(void);
iforce2d 2:75a5b58b2338 159
iforce2d 2:75a5b58b2338 160 /**
iforce2d 2:75a5b58b2338 161 * Empty the transmit buffer
iforce2d 2:75a5b58b2338 162 *
iforce2d 2:75a5b58b2338 163 * @return Current value of status register
iforce2d 2:75a5b58b2338 164 */
iforce2d 2:75a5b58b2338 165 uint8_t flush_tx(void);
iforce2d 2:75a5b58b2338 166
iforce2d 2:75a5b58b2338 167 /**
iforce2d 2:75a5b58b2338 168 * Retrieve the current status of the chip
iforce2d 2:75a5b58b2338 169 *
iforce2d 2:75a5b58b2338 170 * @return Current value of status register
iforce2d 2:75a5b58b2338 171 */
iforce2d 2:75a5b58b2338 172 uint8_t get_status(void);
iforce2d 2:75a5b58b2338 173
iforce2d 2:75a5b58b2338 174 /**
iforce2d 2:75a5b58b2338 175 * Decode and print the given status to stdout
iforce2d 2:75a5b58b2338 176 *
iforce2d 2:75a5b58b2338 177 * @param status Status value to print
iforce2d 2:75a5b58b2338 178 *
iforce2d 2:75a5b58b2338 179 * @warning Does nothing if stdout is not defined. See fdevopen in stdio.h
iforce2d 2:75a5b58b2338 180 */
iforce2d 2:75a5b58b2338 181 void print_status(Serial& serial, uint8_t status);
iforce2d 2:75a5b58b2338 182
iforce2d 2:75a5b58b2338 183 /**
iforce2d 2:75a5b58b2338 184 * Decode and print the given 'observe_tx' value to stdout
iforce2d 2:75a5b58b2338 185 *
iforce2d 2:75a5b58b2338 186 * @param value The observe_tx value to print
iforce2d 2:75a5b58b2338 187 *
iforce2d 2:75a5b58b2338 188 * @warning Does nothing if stdout is not defined. See fdevopen in stdio.h
iforce2d 2:75a5b58b2338 189 */
iforce2d 2:75a5b58b2338 190 void print_observe_tx(Serial& serial, uint8_t value);
iforce2d 2:75a5b58b2338 191
iforce2d 2:75a5b58b2338 192 /**
iforce2d 2:75a5b58b2338 193 * Print the name and value of an 8-bit register to stdout
iforce2d 2:75a5b58b2338 194 *
iforce2d 2:75a5b58b2338 195 * Optionally it can print some quantity of successive
iforce2d 2:75a5b58b2338 196 * registers on the same line. This is useful for printing a group
iforce2d 2:75a5b58b2338 197 * of related registers on one line.
iforce2d 2:75a5b58b2338 198 *
iforce2d 2:75a5b58b2338 199 * @param name Name of the register
iforce2d 2:75a5b58b2338 200 * @param reg Which register. Use constants from nRF24L01.h
iforce2d 2:75a5b58b2338 201 * @param qty How many successive registers to print
iforce2d 2:75a5b58b2338 202 */
iforce2d 2:75a5b58b2338 203 void print_byte_register(Serial& serial, const char* name, uint8_t reg, uint8_t qty = 1);
iforce2d 2:75a5b58b2338 204
iforce2d 2:75a5b58b2338 205 /**
iforce2d 2:75a5b58b2338 206 * Print the name and value of a 40-bit address register to stdout
iforce2d 2:75a5b58b2338 207 *
iforce2d 2:75a5b58b2338 208 * Optionally it can print some quantity of successive
iforce2d 2:75a5b58b2338 209 * registers on the same line. This is useful for printing a group
iforce2d 2:75a5b58b2338 210 * of related registers on one line.
iforce2d 2:75a5b58b2338 211 *
iforce2d 2:75a5b58b2338 212 * @param name Name of the register
iforce2d 2:75a5b58b2338 213 * @param reg Which register. Use constants from nRF24L01.h
iforce2d 2:75a5b58b2338 214 * @param qty How many successive registers to print
iforce2d 2:75a5b58b2338 215 */
iforce2d 2:75a5b58b2338 216 void print_address_register(Serial& serial, const char* name, uint8_t reg, uint8_t qty = 1);
iforce2d 2:75a5b58b2338 217
iforce2d 2:75a5b58b2338 218 /**
iforce2d 2:75a5b58b2338 219 * Turn on or off the special features of the chip
iforce2d 2:75a5b58b2338 220 *
iforce2d 2:75a5b58b2338 221 * The chip has certain 'features' which are only available when the 'features'
iforce2d 2:75a5b58b2338 222 * are enabled. See the datasheet for details.
iforce2d 2:75a5b58b2338 223 */
iforce2d 2:75a5b58b2338 224 void toggle_features(void);
iforce2d 2:75a5b58b2338 225 /**@}*/
iforce2d 2:75a5b58b2338 226
iforce2d 2:75a5b58b2338 227 public:
iforce2d 2:75a5b58b2338 228 /**
iforce2d 2:75a5b58b2338 229 * @name Primary public interface
iforce2d 2:75a5b58b2338 230 *
iforce2d 2:75a5b58b2338 231 * These are the main methods you need to operate the chip
iforce2d 2:75a5b58b2338 232 */
iforce2d 2:75a5b58b2338 233 /**@{*/
iforce2d 2:75a5b58b2338 234
iforce2d 2:75a5b58b2338 235 /**
iforce2d 2:75a5b58b2338 236 * Constructor
iforce2d 2:75a5b58b2338 237 *
iforce2d 2:75a5b58b2338 238 * Creates a new instance of this driver. Before using, you create an instance
iforce2d 2:75a5b58b2338 239 * and send in the unique pins that this chip is connected to.
iforce2d 2:75a5b58b2338 240 *
iforce2d 2:75a5b58b2338 241 * @param _cepin The pin attached to Chip Enable on the RF module
iforce2d 2:75a5b58b2338 242 * @param _cspin The pin attached to Chip Select
iforce2d 2:75a5b58b2338 243 */
iforce2d 2:75a5b58b2338 244 RF24(PinName mosi,
iforce2d 2:75a5b58b2338 245 PinName miso,
iforce2d 2:75a5b58b2338 246 PinName sck,
iforce2d 2:75a5b58b2338 247 PinName csn,
iforce2d 2:75a5b58b2338 248 PinName ce);
iforce2d 2:75a5b58b2338 249
iforce2d 2:75a5b58b2338 250 /**
iforce2d 2:75a5b58b2338 251 * Begin operation of the chip
iforce2d 2:75a5b58b2338 252 *
iforce2d 2:75a5b58b2338 253 * Call this in setup(), before calling any other methods.
iforce2d 2:75a5b58b2338 254 */
iforce2d 2:75a5b58b2338 255 void begin(void);
iforce2d 2:75a5b58b2338 256
iforce2d 2:75a5b58b2338 257 /**
iforce2d 2:75a5b58b2338 258 * Start listening on the pipes opened for reading.
iforce2d 2:75a5b58b2338 259 *
iforce2d 2:75a5b58b2338 260 * Be sure to call openReadingPipe() first. Do not call write() while
iforce2d 2:75a5b58b2338 261 * in this mode, without first calling stopListening(). Call
iforce2d 2:75a5b58b2338 262 * isAvailable() to check for incoming traffic, and read() to get it.
iforce2d 2:75a5b58b2338 263 */
iforce2d 2:75a5b58b2338 264 void startListening(void);
iforce2d 2:75a5b58b2338 265
iforce2d 2:75a5b58b2338 266 /**
iforce2d 2:75a5b58b2338 267 * Stop listening for incoming messages
iforce2d 2:75a5b58b2338 268 *
iforce2d 2:75a5b58b2338 269 * Do this before calling write().
iforce2d 2:75a5b58b2338 270 */
iforce2d 2:75a5b58b2338 271 void stopListening(void);
iforce2d 2:75a5b58b2338 272
iforce2d 2:75a5b58b2338 273 /**
iforce2d 2:75a5b58b2338 274 * Write to the open writing pipe
iforce2d 2:75a5b58b2338 275 *
iforce2d 2:75a5b58b2338 276 * Be sure to call openWritingPipe() first to set the destination
iforce2d 2:75a5b58b2338 277 * of where to write to.
iforce2d 2:75a5b58b2338 278 *
iforce2d 2:75a5b58b2338 279 * This blocks until the message is successfully acknowledged by
iforce2d 2:75a5b58b2338 280 * the receiver or the timeout/retransmit maxima are reached. In
iforce2d 2:75a5b58b2338 281 * the current configuration, the max delay here is 60ms.
iforce2d 2:75a5b58b2338 282 *
iforce2d 2:75a5b58b2338 283 * The maximum size of data written is the fixed payload size, see
iforce2d 2:75a5b58b2338 284 * getPayloadSize(). However, you can write less, and the remainder
iforce2d 2:75a5b58b2338 285 * will just be filled with zeroes.
iforce2d 2:75a5b58b2338 286 *
iforce2d 2:75a5b58b2338 287 * @param buf Pointer to the data to be sent
iforce2d 2:75a5b58b2338 288 * @param len Number of bytes to be sent
iforce2d 2:75a5b58b2338 289 * @return True if the payload was delivered successfully false if not
iforce2d 2:75a5b58b2338 290 */
iforce2d 2:75a5b58b2338 291 bool write( const void* buf, uint8_t len );
iforce2d 2:75a5b58b2338 292
iforce2d 2:75a5b58b2338 293 /**
iforce2d 2:75a5b58b2338 294 * Test whether there are bytes available to be read
iforce2d 2:75a5b58b2338 295 *
iforce2d 2:75a5b58b2338 296 * @return True if there is a payload available, false if none is
iforce2d 2:75a5b58b2338 297 */
iforce2d 2:75a5b58b2338 298 bool available(void);
iforce2d 2:75a5b58b2338 299
iforce2d 2:75a5b58b2338 300 /**
iforce2d 2:75a5b58b2338 301 * Read the payload
iforce2d 2:75a5b58b2338 302 *
iforce2d 2:75a5b58b2338 303 * Return the last payload received
iforce2d 2:75a5b58b2338 304 *
iforce2d 2:75a5b58b2338 305 * The size of data read is the fixed payload size, see getPayloadSize()
iforce2d 2:75a5b58b2338 306 *
iforce2d 2:75a5b58b2338 307 * @note I specifically chose 'void*' as a data type to make it easier
iforce2d 2:75a5b58b2338 308 * for beginners to use. No casting needed.
iforce2d 2:75a5b58b2338 309 *
iforce2d 2:75a5b58b2338 310 * @param buf Pointer to a buffer where the data should be written
iforce2d 2:75a5b58b2338 311 * @param len Maximum number of bytes to read into the buffer
iforce2d 2:75a5b58b2338 312 * @return True if the payload was delivered successfully false if not
iforce2d 2:75a5b58b2338 313 */
iforce2d 2:75a5b58b2338 314 bool read( void* buf, uint8_t len );
iforce2d 2:75a5b58b2338 315
iforce2d 2:75a5b58b2338 316 /**
iforce2d 2:75a5b58b2338 317 * Open a pipe for writing
iforce2d 2:75a5b58b2338 318 *
iforce2d 2:75a5b58b2338 319 * Only one pipe can be open at once, but you can change the pipe
iforce2d 2:75a5b58b2338 320 * you'll listen to. Do not call this while actively listening.
iforce2d 2:75a5b58b2338 321 * Remember to stopListening() first.
iforce2d 2:75a5b58b2338 322 *
iforce2d 2:75a5b58b2338 323 * Addresses are 40-bit hex values, e.g.:
iforce2d 2:75a5b58b2338 324 *
iforce2d 2:75a5b58b2338 325 * @code
iforce2d 2:75a5b58b2338 326 * openWritingPipe(0xF0F0F0F0F0);
iforce2d 2:75a5b58b2338 327 * @endcode
iforce2d 2:75a5b58b2338 328 *
iforce2d 2:75a5b58b2338 329 * @param address The 40-bit address of the pipe to open. This can be
iforce2d 2:75a5b58b2338 330 * any value whatsoever, as long as you are the only one writing to it
iforce2d 2:75a5b58b2338 331 * and only one other radio is listening to it. Coordinate these pipe
iforce2d 2:75a5b58b2338 332 * addresses amongst nodes on the network.
iforce2d 2:75a5b58b2338 333 */
iforce2d 2:75a5b58b2338 334 void openWritingPipe(uint64_t address);
iforce2d 2:75a5b58b2338 335
iforce2d 2:75a5b58b2338 336 /**
iforce2d 2:75a5b58b2338 337 * Open a pipe for reading
iforce2d 2:75a5b58b2338 338 *
iforce2d 2:75a5b58b2338 339 * Up to 6 pipes can be open for reading at once. Open all the
iforce2d 2:75a5b58b2338 340 * reading pipes, and then call startListening().
iforce2d 2:75a5b58b2338 341 *
iforce2d 2:75a5b58b2338 342 * @see openWritingPipe
iforce2d 2:75a5b58b2338 343 *
iforce2d 2:75a5b58b2338 344 * @warning Pipes 1-5 should share the first 32 bits.
iforce2d 2:75a5b58b2338 345 * Only the least significant byte should be unique, e.g.
iforce2d 2:75a5b58b2338 346 * @code
iforce2d 2:75a5b58b2338 347 * openReadingPipe(1,0xF0F0F0F0AA);
iforce2d 2:75a5b58b2338 348 * openReadingPipe(2,0xF0F0F0F066);
iforce2d 2:75a5b58b2338 349 * @endcode
iforce2d 2:75a5b58b2338 350 *
iforce2d 2:75a5b58b2338 351 * @warning Pipe 0 is also used by the writing pipe. So if you open
iforce2d 2:75a5b58b2338 352 * pipe 0 for reading, and then startListening(), it will overwrite the
iforce2d 2:75a5b58b2338 353 * writing pipe. Ergo, do an openWritingPipe() again before write().
iforce2d 2:75a5b58b2338 354 *
iforce2d 2:75a5b58b2338 355 * @todo Enforce the restriction that pipes 1-5 must share the top 32 bits
iforce2d 2:75a5b58b2338 356 *
iforce2d 2:75a5b58b2338 357 * @param number Which pipe# to open, 0-5.
iforce2d 2:75a5b58b2338 358 * @param address The 40-bit address of the pipe to open.
iforce2d 2:75a5b58b2338 359 */
iforce2d 2:75a5b58b2338 360 void openReadingPipe(uint8_t number, uint64_t address);
iforce2d 2:75a5b58b2338 361
iforce2d 2:75a5b58b2338 362 /**@}*/
iforce2d 2:75a5b58b2338 363 /**
iforce2d 2:75a5b58b2338 364 * @name Optional Configurators
iforce2d 2:75a5b58b2338 365 *
iforce2d 2:75a5b58b2338 366 * Methods you can use to get or set the configuration of the chip.
iforce2d 2:75a5b58b2338 367 * None are required. Calling begin() sets up a reasonable set of
iforce2d 2:75a5b58b2338 368 * defaults.
iforce2d 2:75a5b58b2338 369 */
iforce2d 2:75a5b58b2338 370 /**@{*/
iforce2d 2:75a5b58b2338 371 /**
iforce2d 2:75a5b58b2338 372 * Set the number and delay of retries upon failed submit
iforce2d 2:75a5b58b2338 373 *
iforce2d 2:75a5b58b2338 374 * @param delay How long to wait between each retry, in multiples of 250us,
iforce2d 2:75a5b58b2338 375 * max is 15. 0 means 250us, 15 means 4000us.
iforce2d 2:75a5b58b2338 376 * @param count How many retries before giving up, max 15
iforce2d 2:75a5b58b2338 377 */
iforce2d 2:75a5b58b2338 378 void setRetries(uint8_t delay, uint8_t count);
iforce2d 2:75a5b58b2338 379
iforce2d 2:75a5b58b2338 380 /**
iforce2d 2:75a5b58b2338 381 * Set RF communication channel
iforce2d 2:75a5b58b2338 382 *
iforce2d 2:75a5b58b2338 383 * @param channel Which RF channel to communicate on, 0-127
iforce2d 2:75a5b58b2338 384 */
iforce2d 2:75a5b58b2338 385 void setChannel(uint8_t channel);
iforce2d 2:75a5b58b2338 386
iforce2d 2:75a5b58b2338 387 /**
iforce2d 2:75a5b58b2338 388 * Set Static Payload Size
iforce2d 2:75a5b58b2338 389 *
iforce2d 2:75a5b58b2338 390 * This implementation uses a pre-stablished fixed payload size for all
iforce2d 2:75a5b58b2338 391 * transmissions. If this method is never called, the driver will always
iforce2d 2:75a5b58b2338 392 * transmit the maximum payload size (32 bytes), no matter how much
iforce2d 2:75a5b58b2338 393 * was sent to write().
iforce2d 2:75a5b58b2338 394 *
iforce2d 2:75a5b58b2338 395 * @todo Implement variable-sized payloads feature
iforce2d 2:75a5b58b2338 396 *
iforce2d 2:75a5b58b2338 397 * @param size The number of bytes in the payload
iforce2d 2:75a5b58b2338 398 */
iforce2d 2:75a5b58b2338 399 void setPayloadSize(uint8_t size);
iforce2d 2:75a5b58b2338 400
iforce2d 2:75a5b58b2338 401 /**
iforce2d 2:75a5b58b2338 402 * Get Static Payload Size
iforce2d 2:75a5b58b2338 403 *
iforce2d 2:75a5b58b2338 404 * @see setPayloadSize()
iforce2d 2:75a5b58b2338 405 *
iforce2d 2:75a5b58b2338 406 * @return The number of bytes in the payload
iforce2d 2:75a5b58b2338 407 */
iforce2d 2:75a5b58b2338 408 uint8_t getPayloadSize(void);
iforce2d 2:75a5b58b2338 409
iforce2d 2:75a5b58b2338 410 /**
iforce2d 2:75a5b58b2338 411 * Get Dynamic Payload Size
iforce2d 2:75a5b58b2338 412 *
iforce2d 2:75a5b58b2338 413 * For dynamic payloads, this pulls the size of the payload off
iforce2d 2:75a5b58b2338 414 * the chip
iforce2d 2:75a5b58b2338 415 *
iforce2d 2:75a5b58b2338 416 * @return Payload length of last-received dynamic payload
iforce2d 2:75a5b58b2338 417 */
iforce2d 2:75a5b58b2338 418 uint8_t getDynamicPayloadSize(void);
iforce2d 2:75a5b58b2338 419
iforce2d 2:75a5b58b2338 420 /**
iforce2d 2:75a5b58b2338 421 * Enable custom payloads on the acknowledge packets
iforce2d 2:75a5b58b2338 422 *
iforce2d 2:75a5b58b2338 423 * Ack payloads are a handy way to return data back to senders without
iforce2d 2:75a5b58b2338 424 * manually changing the radio modes on both units.
iforce2d 2:75a5b58b2338 425 *
iforce2d 2:75a5b58b2338 426 * @see examples/pingpair_pl/pingpair_pl.pde
iforce2d 2:75a5b58b2338 427 */
iforce2d 2:75a5b58b2338 428 void enableAckPayload(void);
iforce2d 2:75a5b58b2338 429
iforce2d 2:75a5b58b2338 430 /**
iforce2d 2:75a5b58b2338 431 * Enable dynamically-sized payloads
iforce2d 2:75a5b58b2338 432 *
iforce2d 2:75a5b58b2338 433 * This way you don't always have to send large packets just to send them
iforce2d 2:75a5b58b2338 434 * once in a while. This enables dynamic payloads on ALL pipes.
iforce2d 2:75a5b58b2338 435 *
iforce2d 2:75a5b58b2338 436 * @see examples/pingpair_pl/pingpair_dyn.pde
iforce2d 2:75a5b58b2338 437 */
iforce2d 2:75a5b58b2338 438 void enableDynamicPayloads(void);
iforce2d 2:75a5b58b2338 439
iforce2d 2:75a5b58b2338 440 /**
iforce2d 2:75a5b58b2338 441 * Determine whether the hardware is an nRF24L01+ or not.
iforce2d 2:75a5b58b2338 442 *
iforce2d 2:75a5b58b2338 443 * @return true if the hardware is nRF24L01+ (or compatible) and false
iforce2d 2:75a5b58b2338 444 * if its not.
iforce2d 2:75a5b58b2338 445 */
iforce2d 2:75a5b58b2338 446 bool isPVariant(void) ;
iforce2d 2:75a5b58b2338 447
iforce2d 2:75a5b58b2338 448 /**
iforce2d 2:75a5b58b2338 449 * Enable or disable auto-acknowlede packets
iforce2d 2:75a5b58b2338 450 *
iforce2d 2:75a5b58b2338 451 * This is enabled by default, so it's only needed if you want to turn
iforce2d 2:75a5b58b2338 452 * it off for some reason.
iforce2d 2:75a5b58b2338 453 *
iforce2d 2:75a5b58b2338 454 * @param enable Whether to enable (true) or disable (false) auto-acks
iforce2d 2:75a5b58b2338 455 */
iforce2d 2:75a5b58b2338 456 void setAutoAck(bool enable);
iforce2d 2:75a5b58b2338 457
iforce2d 2:75a5b58b2338 458 /**
iforce2d 2:75a5b58b2338 459 * Enable or disable auto-acknowlede packets on a per pipeline basis.
iforce2d 2:75a5b58b2338 460 *
iforce2d 2:75a5b58b2338 461 * AA is enabled by default, so it's only needed if you want to turn
iforce2d 2:75a5b58b2338 462 * it off/on for some reason on a per pipeline basis.
iforce2d 2:75a5b58b2338 463 *
iforce2d 2:75a5b58b2338 464 * @param pipe Which pipeline to modify
iforce2d 2:75a5b58b2338 465 * @param enable Whether to enable (true) or disable (false) auto-acks
iforce2d 2:75a5b58b2338 466 */
iforce2d 2:75a5b58b2338 467 void setAutoAck( uint8_t pipe, bool enable ) ;
iforce2d 2:75a5b58b2338 468
iforce2d 2:75a5b58b2338 469 /**
iforce2d 2:75a5b58b2338 470 * Set Power Amplifier (PA) level to one of four levels.
iforce2d 2:75a5b58b2338 471 * Relative mnemonics have been used to allow for future PA level
iforce2d 2:75a5b58b2338 472 * changes. According to 6.5 of the nRF24L01+ specification sheet,
iforce2d 2:75a5b58b2338 473 * they translate to: RF24_PA_MIN=-18dBm, RF24_PA_LOW=-12dBm,
iforce2d 2:75a5b58b2338 474 * RF24_PA_MED=-6dBM, and RF24_PA_HIGH=0dBm.
iforce2d 2:75a5b58b2338 475 *
iforce2d 2:75a5b58b2338 476 * @param level Desired PA level.
iforce2d 2:75a5b58b2338 477 */
iforce2d 2:75a5b58b2338 478 void setPALevel( rf24_pa_dbm_e level ) ;
iforce2d 2:75a5b58b2338 479
iforce2d 2:75a5b58b2338 480 /**
iforce2d 2:75a5b58b2338 481 * Fetches the current PA level.
iforce2d 2:75a5b58b2338 482 *
iforce2d 2:75a5b58b2338 483 * @return Returns a value from the rf24_pa_dbm_e enum describing
iforce2d 2:75a5b58b2338 484 * the current PA setting. Please remember, all values represented
iforce2d 2:75a5b58b2338 485 * by the enum mnemonics are negative dBm. See setPALevel for
iforce2d 2:75a5b58b2338 486 * return value descriptions.
iforce2d 2:75a5b58b2338 487 */
iforce2d 2:75a5b58b2338 488 rf24_pa_dbm_e getPALevel( void ) ;
iforce2d 2:75a5b58b2338 489
iforce2d 2:75a5b58b2338 490 /**
iforce2d 2:75a5b58b2338 491 * Set the transmission data rate
iforce2d 2:75a5b58b2338 492 *
iforce2d 2:75a5b58b2338 493 * @warning setting RF24_250KBPS will fail for non-plus units
iforce2d 2:75a5b58b2338 494 *
iforce2d 2:75a5b58b2338 495 * @param speed RF24_250KBPS for 250kbs, RF24_1MBPS for 1Mbps, or RF24_2MBPS for 2Mbps
iforce2d 2:75a5b58b2338 496 * @return true if the change was successful
iforce2d 2:75a5b58b2338 497 */
iforce2d 2:75a5b58b2338 498 bool setDataRate(rf24_datarate_e speed);
iforce2d 2:75a5b58b2338 499
iforce2d 2:75a5b58b2338 500 /**
iforce2d 2:75a5b58b2338 501 * Fetches the transmission data rate
iforce2d 2:75a5b58b2338 502 *
iforce2d 2:75a5b58b2338 503 * @return Returns the hardware's currently configured datarate. The value
iforce2d 2:75a5b58b2338 504 * is one of 250kbs, RF24_1MBPS for 1Mbps, or RF24_2MBPS, as defined in the
iforce2d 2:75a5b58b2338 505 * rf24_datarate_e enum.
iforce2d 2:75a5b58b2338 506 */
iforce2d 2:75a5b58b2338 507 rf24_datarate_e getDataRate( void ) ;
iforce2d 2:75a5b58b2338 508
iforce2d 2:75a5b58b2338 509 /**
iforce2d 2:75a5b58b2338 510 * Set the CRC length
iforce2d 2:75a5b58b2338 511 *
iforce2d 2:75a5b58b2338 512 * @param length RF24_CRC_8 for 8-bit or RF24_CRC_16 for 16-bit
iforce2d 2:75a5b58b2338 513 */
iforce2d 2:75a5b58b2338 514 void setCRCLength(rf24_crclength_e length);
iforce2d 2:75a5b58b2338 515
iforce2d 2:75a5b58b2338 516 /**
iforce2d 2:75a5b58b2338 517 * Get the CRC length
iforce2d 2:75a5b58b2338 518 *
iforce2d 2:75a5b58b2338 519 * @return RF24_DISABLED if disabled or RF24_CRC_8 for 8-bit or RF24_CRC_16 for 16-bit
iforce2d 2:75a5b58b2338 520 */
iforce2d 2:75a5b58b2338 521 rf24_crclength_e getCRCLength(void);
iforce2d 2:75a5b58b2338 522
iforce2d 2:75a5b58b2338 523 /**
iforce2d 2:75a5b58b2338 524 * Disable CRC validation
iforce2d 2:75a5b58b2338 525 *
iforce2d 2:75a5b58b2338 526 */
iforce2d 2:75a5b58b2338 527 void disableCRC( void ) ;
iforce2d 2:75a5b58b2338 528
iforce2d 2:75a5b58b2338 529 /**@}*/
iforce2d 2:75a5b58b2338 530 /**
iforce2d 2:75a5b58b2338 531 * @name Advanced Operation
iforce2d 2:75a5b58b2338 532 *
iforce2d 2:75a5b58b2338 533 * Methods you can use to drive the chip in more advanced ways
iforce2d 2:75a5b58b2338 534 */
iforce2d 2:75a5b58b2338 535 /**@{*/
iforce2d 2:75a5b58b2338 536
iforce2d 2:75a5b58b2338 537 /**
iforce2d 2:75a5b58b2338 538 * Print a giant block of debugging information to stdout
iforce2d 2:75a5b58b2338 539 *
iforce2d 2:75a5b58b2338 540 * @warning Does nothing if stdout is not defined. See fdevopen in stdio.h
iforce2d 2:75a5b58b2338 541 */
iforce2d 2:75a5b58b2338 542 void printDetails(Serial& serial);
iforce2d 2:75a5b58b2338 543
iforce2d 2:75a5b58b2338 544 /**
iforce2d 2:75a5b58b2338 545 * Enter low-power mode
iforce2d 2:75a5b58b2338 546 *
iforce2d 2:75a5b58b2338 547 * To return to normal power mode, either write() some data or
iforce2d 2:75a5b58b2338 548 * startListening, or powerUp().
iforce2d 2:75a5b58b2338 549 */
iforce2d 2:75a5b58b2338 550 void powerDown(void);
iforce2d 2:75a5b58b2338 551
iforce2d 2:75a5b58b2338 552 /**
iforce2d 2:75a5b58b2338 553 * Leave low-power mode - making radio more responsive
iforce2d 2:75a5b58b2338 554 *
iforce2d 2:75a5b58b2338 555 * To return to low power mode, call powerDown().
iforce2d 2:75a5b58b2338 556 */
iforce2d 2:75a5b58b2338 557 void powerUp(void) ;
iforce2d 2:75a5b58b2338 558
iforce2d 2:75a5b58b2338 559 /**
iforce2d 2:75a5b58b2338 560 * Test whether there are bytes available to be read
iforce2d 2:75a5b58b2338 561 *
iforce2d 2:75a5b58b2338 562 * Use this version to discover on which pipe the message
iforce2d 2:75a5b58b2338 563 * arrived.
iforce2d 2:75a5b58b2338 564 *
iforce2d 2:75a5b58b2338 565 * @param[out] pipe_num Which pipe has the payload available
iforce2d 2:75a5b58b2338 566 * @return True if there is a payload available, false if none is
iforce2d 2:75a5b58b2338 567 */
iforce2d 2:75a5b58b2338 568 bool available(uint8_t* pipe_num);
iforce2d 2:75a5b58b2338 569
iforce2d 2:75a5b58b2338 570 /**
iforce2d 2:75a5b58b2338 571 * Non-blocking write to the open writing pipe
iforce2d 2:75a5b58b2338 572 *
iforce2d 2:75a5b58b2338 573 * Just like write(), but it returns immediately. To find out what happened
iforce2d 2:75a5b58b2338 574 * to the send, catch the IRQ and then call whatHappened().
iforce2d 2:75a5b58b2338 575 *
iforce2d 2:75a5b58b2338 576 * @see write()
iforce2d 2:75a5b58b2338 577 * @see whatHappened()
iforce2d 2:75a5b58b2338 578 *
iforce2d 2:75a5b58b2338 579 * @param buf Pointer to the data to be sent
iforce2d 2:75a5b58b2338 580 * @param len Number of bytes to be sent
iforce2d 2:75a5b58b2338 581 * @return True if the payload was delivered successfully false if not
iforce2d 2:75a5b58b2338 582 */
iforce2d 2:75a5b58b2338 583 void startWrite( const void* buf, uint8_t len );
iforce2d 2:75a5b58b2338 584
iforce2d 2:75a5b58b2338 585 /**
iforce2d 2:75a5b58b2338 586 * Write an ack payload for the specified pipe
iforce2d 2:75a5b58b2338 587 *
iforce2d 2:75a5b58b2338 588 * The next time a message is received on @p pipe, the data in @p buf will
iforce2d 2:75a5b58b2338 589 * be sent back in the acknowledgement.
iforce2d 2:75a5b58b2338 590 *
iforce2d 2:75a5b58b2338 591 * @warning According to the data sheet, only three of these can be pending
iforce2d 2:75a5b58b2338 592 * at any time. I have not tested this.
iforce2d 2:75a5b58b2338 593 *
iforce2d 2:75a5b58b2338 594 * @param pipe Which pipe# (typically 1-5) will get this response.
iforce2d 2:75a5b58b2338 595 * @param buf Pointer to data that is sent
iforce2d 2:75a5b58b2338 596 * @param len Length of the data to send, up to 32 bytes max. Not affected
iforce2d 2:75a5b58b2338 597 * by the static payload set by setPayloadSize().
iforce2d 2:75a5b58b2338 598 */
iforce2d 2:75a5b58b2338 599 void writeAckPayload(uint8_t pipe, const void* buf, uint8_t len);
iforce2d 2:75a5b58b2338 600
iforce2d 2:75a5b58b2338 601 /**
iforce2d 2:75a5b58b2338 602 * Determine if an ack payload was received in the most recent call to
iforce2d 2:75a5b58b2338 603 * write().
iforce2d 2:75a5b58b2338 604 *
iforce2d 2:75a5b58b2338 605 * Call read() to retrieve the ack payload.
iforce2d 2:75a5b58b2338 606 *
iforce2d 2:75a5b58b2338 607 * @warning Calling this function clears the internal flag which indicates
iforce2d 2:75a5b58b2338 608 * a payload is available. If it returns true, you must read the packet
iforce2d 2:75a5b58b2338 609 * out as the very next interaction with the radio, or the results are
iforce2d 2:75a5b58b2338 610 * undefined.
iforce2d 2:75a5b58b2338 611 *
iforce2d 2:75a5b58b2338 612 * @return True if an ack payload is available.
iforce2d 2:75a5b58b2338 613 */
iforce2d 2:75a5b58b2338 614 bool isAckPayloadAvailable(void);
iforce2d 2:75a5b58b2338 615
iforce2d 2:75a5b58b2338 616 /**
iforce2d 2:75a5b58b2338 617 * Call this when you get an interrupt to find out why
iforce2d 2:75a5b58b2338 618 *
iforce2d 2:75a5b58b2338 619 * Tells you what caused the interrupt, and clears the state of
iforce2d 2:75a5b58b2338 620 * interrupts.
iforce2d 2:75a5b58b2338 621 *
iforce2d 2:75a5b58b2338 622 * @param[out] tx_ok The send was successful (TX_DS)
iforce2d 2:75a5b58b2338 623 * @param[out] tx_fail The send failed, too many retries (MAX_RT)
iforce2d 2:75a5b58b2338 624 * @param[out] rx_ready There is a message waiting to be read (RX_DS)
iforce2d 2:75a5b58b2338 625 */
iforce2d 2:75a5b58b2338 626 void whatHappened(bool& tx_ok,bool& tx_fail,bool& rx_ready);
iforce2d 2:75a5b58b2338 627
iforce2d 2:75a5b58b2338 628 /**
iforce2d 2:75a5b58b2338 629 * Test whether there was a carrier on the line for the
iforce2d 2:75a5b58b2338 630 * previous listening period.
iforce2d 2:75a5b58b2338 631 *
iforce2d 2:75a5b58b2338 632 * Useful to check for interference on the current channel.
iforce2d 2:75a5b58b2338 633 *
iforce2d 2:75a5b58b2338 634 * @return true if was carrier, false if not
iforce2d 2:75a5b58b2338 635 */
iforce2d 2:75a5b58b2338 636 bool testCarrier(void);
iforce2d 2:75a5b58b2338 637
iforce2d 2:75a5b58b2338 638 /**
iforce2d 2:75a5b58b2338 639 * Test whether a signal (carrier or otherwise) greater than
iforce2d 2:75a5b58b2338 640 * or equal to -64dBm is present on the channel. Valid only
iforce2d 2:75a5b58b2338 641 * on nRF24L01P (+) hardware. On nRF24L01, use testCarrier().
iforce2d 2:75a5b58b2338 642 *
iforce2d 2:75a5b58b2338 643 * Useful to check for interference on the current channel and
iforce2d 2:75a5b58b2338 644 * channel hopping strategies.
iforce2d 2:75a5b58b2338 645 *
iforce2d 2:75a5b58b2338 646 * @return true if signal => -64dBm, false if not
iforce2d 2:75a5b58b2338 647 */
iforce2d 2:75a5b58b2338 648 bool testRPD(void) ;
iforce2d 2:75a5b58b2338 649
iforce2d 2:75a5b58b2338 650 /**
iforce2d 2:75a5b58b2338 651 * Test whether this is a real radio, or a mock shim for
iforce2d 2:75a5b58b2338 652 * debugging. Setting either pin to 0xff is the way to
iforce2d 2:75a5b58b2338 653 * indicate that this is not a real radio.
iforce2d 2:75a5b58b2338 654 *
iforce2d 2:75a5b58b2338 655 * @return true if this is a legitimate radio
iforce2d 2:75a5b58b2338 656 */
iforce2d 2:75a5b58b2338 657 bool isValid() { return ce_pin != 0xff && csn_pin != 0xff; }
iforce2d 2:75a5b58b2338 658
iforce2d 2:75a5b58b2338 659 /**@}*/
iforce2d 2:75a5b58b2338 660 };
iforce2d 2:75a5b58b2338 661
iforce2d 2:75a5b58b2338 662 /**
iforce2d 2:75a5b58b2338 663 * @example GettingStarted.pde
iforce2d 2:75a5b58b2338 664 *
iforce2d 2:75a5b58b2338 665 * This is an example which corresponds to my "Getting Started" blog post:
iforce2d 2:75a5b58b2338 666 * <a style="text-align:center" href="http://maniacbug.wordpress.com/2011/11/02/getting-started-rf24/">Getting Started with nRF24L01+ on Arduino</a>.
iforce2d 2:75a5b58b2338 667 *
iforce2d 2:75a5b58b2338 668 * It is an example of how to use the RF24 class. Write this sketch to two
iforce2d 2:75a5b58b2338 669 * different nodes. Put one of the nodes into 'transmit' mode by connecting
iforce2d 2:75a5b58b2338 670 * with the serial monitor and sending a 'T'. The ping node sends the current
iforce2d 2:75a5b58b2338 671 * time to the pong node, which responds by sending the value back. The ping
iforce2d 2:75a5b58b2338 672 * node can then see how long the whole cycle took.
iforce2d 2:75a5b58b2338 673 */
iforce2d 2:75a5b58b2338 674
iforce2d 2:75a5b58b2338 675 /**
iforce2d 2:75a5b58b2338 676 * @example nordic_fob.pde
iforce2d 2:75a5b58b2338 677 *
iforce2d 2:75a5b58b2338 678 * This is an example of how to use the RF24 class to receive signals from the
iforce2d 2:75a5b58b2338 679 * Sparkfun Nordic FOB. See http://www.sparkfun.com/products/8602 .
iforce2d 2:75a5b58b2338 680 * Thanks to Kirk Mower for providing test hardware.
iforce2d 2:75a5b58b2338 681 */
iforce2d 2:75a5b58b2338 682
iforce2d 2:75a5b58b2338 683 /**
iforce2d 2:75a5b58b2338 684 * @example led_remote.pde
iforce2d 2:75a5b58b2338 685 *
iforce2d 2:75a5b58b2338 686 * This is an example of how to use the RF24 class to control a remote
iforce2d 2:75a5b58b2338 687 * bank of LED's using buttons on a remote control.
iforce2d 2:75a5b58b2338 688 *
iforce2d 2:75a5b58b2338 689 * Every time the buttons change on the remote, the entire state of
iforce2d 2:75a5b58b2338 690 * buttons is send to the led board, which displays the state.
iforce2d 2:75a5b58b2338 691 */
iforce2d 2:75a5b58b2338 692
iforce2d 2:75a5b58b2338 693 /**
iforce2d 2:75a5b58b2338 694 * @example pingpair.pde
iforce2d 2:75a5b58b2338 695 *
iforce2d 2:75a5b58b2338 696 * This is an example of how to use the RF24 class. Write this sketch to two
iforce2d 2:75a5b58b2338 697 * different nodes, connect the role_pin to ground on one. The ping node sends
iforce2d 2:75a5b58b2338 698 * the current time to the pong node, which responds by sending the value back.
iforce2d 2:75a5b58b2338 699 * The ping node can then see how long the whole cycle took.
iforce2d 2:75a5b58b2338 700 */
iforce2d 2:75a5b58b2338 701
iforce2d 2:75a5b58b2338 702 /**
iforce2d 2:75a5b58b2338 703 * @example pingpair_maple.pde
iforce2d 2:75a5b58b2338 704 *
iforce2d 2:75a5b58b2338 705 * This is an example of how to use the RF24 class on the Maple. For a more
iforce2d 2:75a5b58b2338 706 * detailed explanation, see my blog post:
iforce2d 2:75a5b58b2338 707 * <a href="http://maniacbug.wordpress.com/2011/12/14/nrf24l01-running-on-maple-3/">nRF24L01+ Running on Maple</a>
iforce2d 2:75a5b58b2338 708 *
iforce2d 2:75a5b58b2338 709 * It will communicate well to an Arduino-based unit as well, so it's not for only Maple-to-Maple communication.
iforce2d 2:75a5b58b2338 710 *
iforce2d 2:75a5b58b2338 711 * Write this sketch to two different nodes,
iforce2d 2:75a5b58b2338 712 * connect the role_pin to ground on one. The ping node sends the current time to the pong node,
iforce2d 2:75a5b58b2338 713 * which responds by sending the value back. The ping node can then see how long the whole cycle
iforce2d 2:75a5b58b2338 714 * took.
iforce2d 2:75a5b58b2338 715 */
iforce2d 2:75a5b58b2338 716
iforce2d 2:75a5b58b2338 717 /**
iforce2d 2:75a5b58b2338 718 * @example starping.pde
iforce2d 2:75a5b58b2338 719 *
iforce2d 2:75a5b58b2338 720 * This sketch is a more complex example of using the RF24 library for Arduino.
iforce2d 2:75a5b58b2338 721 * Deploy this on up to six nodes. Set one as the 'pong receiver' by tying the
iforce2d 2:75a5b58b2338 722 * role_pin low, and the others will be 'ping transmit' units. The ping units
iforce2d 2:75a5b58b2338 723 * unit will send out the value of millis() once a second. The pong unit will
iforce2d 2:75a5b58b2338 724 * respond back with a copy of the value. Each ping unit can get that response
iforce2d 2:75a5b58b2338 725 * back, and determine how long the whole cycle took.
iforce2d 2:75a5b58b2338 726 *
iforce2d 2:75a5b58b2338 727 * This example requires a bit more complexity to determine which unit is which.
iforce2d 2:75a5b58b2338 728 * The pong receiver is identified by having its role_pin tied to ground.
iforce2d 2:75a5b58b2338 729 * The ping senders are further differentiated by a byte in eeprom.
iforce2d 2:75a5b58b2338 730 */
iforce2d 2:75a5b58b2338 731
iforce2d 2:75a5b58b2338 732 /**
iforce2d 2:75a5b58b2338 733 * @example pingpair_pl.pde
iforce2d 2:75a5b58b2338 734 *
iforce2d 2:75a5b58b2338 735 * This is an example of how to do two-way communication without changing
iforce2d 2:75a5b58b2338 736 * transmit/receive modes. Here, a payload is set to the transmitter within
iforce2d 2:75a5b58b2338 737 * the Ack packet of each transmission. Note that the payload is set BEFORE
iforce2d 2:75a5b58b2338 738 * the sender's message arrives.
iforce2d 2:75a5b58b2338 739 */
iforce2d 2:75a5b58b2338 740
iforce2d 2:75a5b58b2338 741 /**
iforce2d 2:75a5b58b2338 742 * @example pingpair_irq.pde
iforce2d 2:75a5b58b2338 743 *
iforce2d 2:75a5b58b2338 744 * This is an example of how to user interrupts to interact with the radio.
iforce2d 2:75a5b58b2338 745 * It builds on the pingpair_pl example, and uses ack payloads.
iforce2d 2:75a5b58b2338 746 */
iforce2d 2:75a5b58b2338 747
iforce2d 2:75a5b58b2338 748 /**
iforce2d 2:75a5b58b2338 749 * @example pingpair_sleepy.pde
iforce2d 2:75a5b58b2338 750 *
iforce2d 2:75a5b58b2338 751 * This is an example of how to use the RF24 class to create a battery-
iforce2d 2:75a5b58b2338 752 * efficient system. It is just like the pingpair.pde example, but the
iforce2d 2:75a5b58b2338 753 * ping node powers down the radio and sleeps the MCU after every
iforce2d 2:75a5b58b2338 754 * ping/pong cycle.
iforce2d 2:75a5b58b2338 755 */
iforce2d 2:75a5b58b2338 756
iforce2d 2:75a5b58b2338 757 /**
iforce2d 2:75a5b58b2338 758 * @example scanner.pde
iforce2d 2:75a5b58b2338 759 *
iforce2d 2:75a5b58b2338 760 * Example to detect interference on the various channels available.
iforce2d 2:75a5b58b2338 761 * This is a good diagnostic tool to check whether you're picking a
iforce2d 2:75a5b58b2338 762 * good channel for your application.
iforce2d 2:75a5b58b2338 763 *
iforce2d 2:75a5b58b2338 764 * Inspired by cpixip.
iforce2d 2:75a5b58b2338 765 * See http://arduino.cc/forum/index.php/topic,54795.0.html
iforce2d 2:75a5b58b2338 766 */
iforce2d 2:75a5b58b2338 767
iforce2d 2:75a5b58b2338 768 /**
iforce2d 2:75a5b58b2338 769 * @mainpage Driver for nRF24L01(+) 2.4GHz Wireless Transceiver
iforce2d 2:75a5b58b2338 770 *
iforce2d 2:75a5b58b2338 771 * @section Goals Design Goals
iforce2d 2:75a5b58b2338 772 *
iforce2d 2:75a5b58b2338 773 * This library is designed to be...
iforce2d 2:75a5b58b2338 774 * @li Maximally compliant with the intended operation of the chip
iforce2d 2:75a5b58b2338 775 * @li Easy for beginners to use
iforce2d 2:75a5b58b2338 776 * @li Consumed with a public interface that's similiar to other Arduino standard libraries
iforce2d 2:75a5b58b2338 777 *
iforce2d 2:75a5b58b2338 778 * @section News News
iforce2d 2:75a5b58b2338 779 *
iforce2d 2:75a5b58b2338 780 * NOW COMPATIBLE WITH ARDUINO 1.0 - The 'master' branch and all examples work with both Arduino 1.0 and earlier versions.
iforce2d 2:75a5b58b2338 781 * Please <a href="https://github.com/maniacbug/RF24/issues/new">open an issue</a> if you find any problems using it with any version of Arduino.
iforce2d 2:75a5b58b2338 782 *
iforce2d 2:75a5b58b2338 783 * NOW COMPATIBLE WITH MAPLE - RF24 has been tested with the
iforce2d 2:75a5b58b2338 784 * <a href="http://leaflabs.com/store/#Maple-Native">Maple Native</a>,
iforce2d 2:75a5b58b2338 785 * and should work with any Maple board. See the pingpair_maple example.
iforce2d 2:75a5b58b2338 786 * Note that only the pingpair_maple example has been tested on Maple, although
iforce2d 2:75a5b58b2338 787 * the others can certainly be adapted.
iforce2d 2:75a5b58b2338 788 *
iforce2d 2:75a5b58b2338 789 * @section Useful Useful References
iforce2d 2:75a5b58b2338 790 *
iforce2d 2:75a5b58b2338 791 * Please refer to:
iforce2d 2:75a5b58b2338 792 *
iforce2d 2:75a5b58b2338 793 * @li <a href="http://maniacbug.github.com/RF24/">Documentation Main Page</a>
iforce2d 2:75a5b58b2338 794 * @li <a href="http://maniacbug.github.com/RF24/classRF24.html">RF24 Class Documentation</a>
iforce2d 2:75a5b58b2338 795 * @li <a href="https://github.com/maniacbug/RF24/">Source Code</a>
iforce2d 2:75a5b58b2338 796 * @li <a href="https://github.com/maniacbug/RF24/archives/master">Downloads Page</a>
iforce2d 2:75a5b58b2338 797 * @li <a href="http://www.nordicsemi.com/files/Product/data_sheet/nRF24L01_Product_Specification_v2_0.pdf">Chip Datasheet</a>
iforce2d 2:75a5b58b2338 798 *
iforce2d 2:75a5b58b2338 799 * This chip uses the SPI bus, plus two chip control pins. Remember that pin 10 must still remain an output, or
iforce2d 2:75a5b58b2338 800 * the SPI hardware will go into 'slave' mode.
iforce2d 2:75a5b58b2338 801 *
iforce2d 2:75a5b58b2338 802 * @section More More Information
iforce2d 2:75a5b58b2338 803 *
iforce2d 2:75a5b58b2338 804 * @subpage FAQ
iforce2d 2:75a5b58b2338 805 *
iforce2d 2:75a5b58b2338 806 * @section Projects Projects
iforce2d 2:75a5b58b2338 807 *
iforce2d 2:75a5b58b2338 808 * Stuff I have built with RF24
iforce2d 2:75a5b58b2338 809 *
iforce2d 2:75a5b58b2338 810 * <img src="http://farm7.staticflickr.com/6044/6307669179_a8d19298a6_m.jpg" width="240" height="160" alt="RF24 Getting Started - Finished Product">
iforce2d 2:75a5b58b2338 811 *
iforce2d 2:75a5b58b2338 812 * <a style="text-align:center" href="http://maniacbug.wordpress.com/2011/11/02/getting-started-rf24/">Getting Started with nRF24L01+ on Arduino</a>
iforce2d 2:75a5b58b2338 813 *
iforce2d 2:75a5b58b2338 814 * <img src="http://farm8.staticflickr.com/7159/6645514331_38eb2bdeaa_m.jpg" width="240" height="160" alt="Nordic FOB and nRF24L01+">
iforce2d 2:75a5b58b2338 815 *
iforce2d 2:75a5b58b2338 816 * <a style="text-align:center" href="http://maniacbug.wordpress.com/2012/01/08/nordic-fob/">Using the Sparkfun Nordic FOB</a>
iforce2d 2:75a5b58b2338 817 *
iforce2d 2:75a5b58b2338 818 * <img src="http://farm7.staticflickr.com/6097/6224308836_b9b3b421a3_m.jpg" width="240" height="160" alt="RF Duinode V3 (2V4)">
iforce2d 2:75a5b58b2338 819 *
iforce2d 2:75a5b58b2338 820 * <a href="http://maniacbug.wordpress.com/2011/10/19/sensor-node/">Low-Power Wireless Sensor Node</a>
iforce2d 2:75a5b58b2338 821 *
iforce2d 2:75a5b58b2338 822 * <img src="http://farm8.staticflickr.com/7012/6489477865_b56edb629b_m.jpg" width="240" height="161" alt="nRF24L01+ connected to Leaf Labs Maple Native">
iforce2d 2:75a5b58b2338 823 *
iforce2d 2:75a5b58b2338 824 * <a href="http://maniacbug.wordpress.com/2011/12/14/nrf24l01-running-on-maple-3/">nRF24L01+ Running on Maple</a>
iforce2d 2:75a5b58b2338 825 */
iforce2d 2:75a5b58b2338 826
iforce2d 2:75a5b58b2338 827 #endif // __RF24_H__
iforce2d 2:75a5b58b2338 828 // vim:ai:cin:sts=2 sw=2 ft=cpp
iforce2d 2:75a5b58b2338 829