nRF905 Radio Library for AVR and Arduino  3.0
nRF905.h
Go to the documentation of this file.
1 /*
2  * Project: nRF905 AVR/Arduino Library/Driver
3  * Author: Zak Kemble, contact@zakkemble.co.uk
4  * Copyright: (C) 2017 by Zak Kemble
5  * License: GNU GPL v3 (see License.txt)
6  * Web: http://blog.zakkemble.co.uk/nrf905-avrarduino-librarydriver/
7  */
8 
9 #ifndef NRF905_H_
10 #define NRF905_H_
11 
12 #ifdef ARDUINO
13 #include <Arduino.h>
14 #endif
15 
16 #include <stdint.h>
17 
18 #include "nRF905_config.h"
19 
23 typedef enum
24 {
29 
33 typedef enum
34 {
35 // NOTE:
36 // When using NRF905_BAND_868 and NRF905_BAND_915 for calculating channel (NRF905_CALC_CHANNEL(f, b)) they should be value 0x01,
37 // but when using them for setting registers their value should be 0x02.
38 // They're defined as 0x02 here so when used for calculating channel they're right shifted by 1
39 
40  NRF905_BAND_433 = 0x00,
41  NRF905_BAND_868 = 0x02,
44 
48 typedef enum
49 {
50  NRF905_PWR_n10 = 0x00,
51  NRF905_PWR_n2 = 0x04,
52  NRF905_PWR_6 = 0x08,
53  NRF905_PWR_10 = 0x0C
54 } nRF905_pwr_t;
55 
59 typedef enum
60 {
64 
68 typedef enum
69 {
73 
77 typedef enum
78 {
85 
91 typedef enum
92 {
94  NRF905_CRC_8 = 0x40,
95  NRF905_CRC_16 = 0xC0,
96 } nRF905_crc_t;
97 
103 typedef enum
104 {
108 
109 // TODO remove?
110 // Setting options
111 //#define NRF905_BAND_433 0x00
112 //#define NRF905_BAND_868 0x02
113 //#define NRF905_BAND_915 0x02
114 //#define NRF905_PWR_n10 0x00
115 //#define NRF905_PWR_n2 0x04
116 //#define NRF905_PWR_6 0x08
117 //#define NRF905_PWR_10 0x0C
118 //#define NRF905_LOW_RX_ENABLE 0x10
119 //#define NRF905_LOW_RX_DISABLE 0x00
120 //#define NRF905_AUTO_RETRAN_ENABLE 0x20
121 //#define NRF905_AUTO_RETRAN_DISABLE 0x00
122 //#define NRF905_OUTCLK_DISABLE 0x00
123 //#define NRF905_OUTCLK_4MHZ 0x04
124 //#define NRF905_OUTCLK_2MHZ 0x05
125 //#define NRF905_OUTCLK_1MHZ 0x06
126 //#define NRF905_OUTCLK_500KHZ 0x07
127 //#define NRF905_CRC_DISABLE 0x00
128 //#define NRF905_CRC_8 0x40
129 //#define NRF905_CRC_16 0xC0
130 //#define NRF905_ADDR_SIZE_1 0x01
131 //#define NRF905_ADDR_SIZE_4 0x04
132 
133 #define NRF905_MAX_PAYLOAD 32
134 #define NRF905_REGISTER_COUNT 10
135 #define NRF905_DEFAULT_RXADDR 0xE7E7E7E7
136 #define NRF905_DEFAULT_TXADDR 0xE7E7E7E7
137 
138 #define NRF905_CALC_CHANNEL(f, b) ((((f) / (1 + (b>>1))) - 422400000UL) / 100000UL)
139 
140 #if defined(__cplusplus)
141 extern "C" {
142 #endif
143 
149 void nRF905_init(void);
150 
163 void nRF905_setChannel(uint16_t channel);
164 
173 void nRF905_setBand(nRF905_band_t band);
174 
189 
197 
205 
212 void nRF905_setCRC(nRF905_crc_t val);
213 
221 
230 void nRF905_setPayloadSize(uint8_t size);
231 
239 
245 uint8_t nRF905_receiveBusy(void);
246 
252 uint8_t nRF905_airwayBusy(void);
253 
261 void nRF905_setListenAddress(uint32_t address);
262 
286 uint8_t nRF905_TX(uint32_t sendTo, void* data, uint8_t len, nRF905_nextmode_t nextMode);
287 
296 void nRF905_RX(void);
297 
309 void nRF905_read(void* data, uint8_t len);
310 
318 void nRF905_powerDown(void);
319 
329 void nRF905_powerUp(void);
330 
339 void nRF905_standby(void);
340 
346 void nRF905_getConfigRegisters(void*);
347 
355 #if DOXYGEN || NRF905_INTERRUPTS == 0
356 void nRF905_SERVICE(void);
357 #else
358 #define nRF905_SERVICE() ((void)(0))
359 #endif
360 
369 uint8_t nRF905_irq_off(void);
370 
380 void nRF905_irq_on(uint8_t origVal);
381 
382 #if DOXYGEN || NRF905_INTERRUPTS != 0
383 
384 #if !defined(DOXYGEN)
385 static inline void _nRF905_iRestore(const uint8_t *__s)
386 {
387  nRF905_irq_on(*__s);
388  __asm__ volatile ("" ::: "memory");
389 }
390 #endif
391 
406 #define NRF905_NO_INTERRUPT() \
407  for(uint8_t nrf905_irq __attribute__((__cleanup__(_nRF905_iRestore))) = nRF905_irq_off(), \
408  nrf905_tmp = 1; nrf905_tmp ; nrf905_tmp = 0)
409 
410 #else
411 #define NRF905_NO_INTERRUPT() ((void)(0));
412 #endif
413 
414 
415 #if defined(__cplusplus)
416 }
417 #endif
418 
419 #endif /* NRF905_H_ */
nRF905_addr_size_t
Address size.
Definition: nRF905.h:103
void nRF905_setAddressSize(nRF905_addr_size_t size)
Address size.
10dBm = 10mW
Definition: nRF905.h:53
uint8_t nRF905_airwayBusy(void)
See if airway is busy (carrier detect pin asserted).
void nRF905_setPayloadSize(uint8_t size)
Payload size.
868/915MHz band
Definition: nRF905.h:42
nRF905_auto_retran_t
Auto re-transmit options.
Definition: nRF905.h:68
4MHz clock
Definition: nRF905.h:80
nRF905_band_t
Frequency bands.
Definition: nRF905.h:33
Transmit mode (will auto-retransmit if ::NRF905_AUTO_RETRAN is NRF905_AUTO_RETRAN_ENABLE, otherwise will transmit a carrier wave with no data)
Definition: nRF905.h:27
uint8_t nRF905_TX(uint32_t sendTo, void *data, uint8_t len, nRF905_nextmode_t nextMode)
Begin a transmission.
Disable auto re-transmit.
Definition: nRF905.h:70
void nRF905_powerUp(void)
Enter standby mode.
2MHz clock
Definition: nRF905.h:81
void nRF905_setAutoRetransmit(nRF905_auto_retran_t val)
Set auto retransmit.
void nRF905_setLowRxPower(nRF905_low_rx_t val)
Set low power receive.
nRF905_outclk_t
Output a clock signal on pin 3 of IC.
Definition: nRF905.h:77
6dBm = 4mW
Definition: nRF905.h:52
Disable low power receive.
Definition: nRF905.h:61
void nRF905_setClockOut(nRF905_outclk_t val)
Set clock output.
void nRF905_standby(void)
Enter standby mode.
Disable CRC.
Definition: nRF905.h:93
1MHz clock
Definition: nRF905.h:82
nRF905_pwr_t
Output power (n means negative, n10 = -10).
Definition: nRF905.h:48
void nRF905_irq_on(uint8_t origVal)
When using interrupts use this to re-enable them for the nRF905.
void nRF905_getConfigRegisters(void *)
Read configuration registers into byte array of NRF905_REGISTER_COUNT elements, mainly for debugging...
433MHz band
Definition: nRF905.h:40
Standby mode.
Definition: nRF905.h:25
void nRF905_setBand(nRF905_band_t band)
Frequency band.
1 byte (not recommended, a lot of false invalid packets will be received)
Definition: nRF905.h:105
8bit CRC (Don&#39;t know what algorithm is used for this one)
Definition: nRF905.h:94
void nRF905_setListenAddress(uint32_t address)
Set address to listen to.
nRF905_low_rx_t
Save a few mA by reducing receive sensitivity.
Definition: nRF905.h:59
void nRF905_init(void)
Initialise, must be called before anything else!
void nRF905_setChannel(uint16_t channel)
Channel to listen and transmit on.
4 bytes
Definition: nRF905.h:106
void nRF905_setCRC(nRF905_crc_t val)
Set CRC.
Receive mode.
Definition: nRF905.h:26
void nRF905_RX(void)
Enter receive mode.
void nRF905_setTransmitPower(nRF905_pwr_t val)
Set output power.
nRF905_nextmode_t
Available modes after transmission complete.
Definition: nRF905.h:23
void nRF905_read(void *data, uint8_t len)
Get received payload.
Disable output clock.
Definition: nRF905.h:79
void nRF905_powerDown(void)
Sleep.
16bit CRC (CRC16-CCITT-FALSE (0xFFFF))
Definition: nRF905.h:95
uint8_t nRF905_irq_off(void)
When using interrupts use this to disable them for the nRF905.
868/915MHz band
Definition: nRF905.h:41
Enable low power receive.
Definition: nRF905.h:62
void nRF905_SERVICE(void)
If interrupts are disabled (::NRF905_INTERRUPTS in nRF905_config.h) then this function should be call...
-2dBm = 631uW
Definition: nRF905.h:51
-10dBm = 100uW
Definition: nRF905.h:50
nRF905_crc_t
CRC Checksum.
Definition: nRF905.h:91
500KHz clock (default)
Definition: nRF905.h:83
Enable auto re-transmit.
Definition: nRF905.h:71
uint8_t nRF905_receiveBusy(void)
See if the attach match is asserted.