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