nRF905 Radio Library for AVR and Arduino  3.0
Macros | Enumerations | Functions
nRF905.h File Reference
#include <stdint.h>
#include "nRF905_config.h"

Go to the source code of this file.

Macros

#define NRF905_MAX_PAYLOAD   32
 Maximum payload size. More...
 
#define NRF905_REGISTER_COUNT   10
 Configuration register count. More...
 
#define NRF905_DEFAULT_RXADDR   0xE7E7E7E7
 Default receive address. More...
 
#define NRF905_DEFAULT_TXADDR   0xE7E7E7E7
 Default transmit/destination address. More...
 
#define NRF905_CALC_CHANNEL(f, b)   ((((f) / (1 + (b>>1))) - 422400000UL) / 100000UL)
 Workout channel from frequency & band. More...
 
#define NRF905_NO_INTERRUPT()
 Disable nRF905 interrupts for code inside this block. More...
 

Enumerations

enum  nRF905_nextmode_t { NRF905_NEXTMODE_STANDBY, NRF905_NEXTMODE_RX, NRF905_NEXTMODE_TX }
 Available modes after transmission complete. More...
 
enum  nRF905_band_t { NRF905_BAND_433 = 0x00, NRF905_BAND_868 = 0x02, NRF905_BAND_915 = 0x02 }
 Frequency bands. More...
 
enum  nRF905_pwr_t { NRF905_PWR_n10 = 0x00, NRF905_PWR_n2 = 0x04, NRF905_PWR_6 = 0x08, NRF905_PWR_10 = 0x0C }
 Output power (n means negative, n10 = -10). More...
 
enum  nRF905_low_rx_t { NRF905_LOW_RX_DISABLE = 0x00, NRF905_LOW_RX_ENABLE = 0x10 }
 Save a few mA by reducing receive sensitivity. More...
 
enum  nRF905_auto_retran_t { NRF905_AUTO_RETRAN_DISABLE = 0x00, NRF905_AUTO_RETRAN_ENABLE = 0x20 }
 Auto re-transmit options. More...
 
enum  nRF905_outclk_t {
  NRF905_OUTCLK_DISABLE = 0x00, NRF905_OUTCLK_4MHZ = 0x04, NRF905_OUTCLK_2MHZ = 0x05, NRF905_OUTCLK_1MHZ = 0x06,
  NRF905_OUTCLK_500KHZ = 0x07
}
 Output a clock signal on pin 3 of IC. More...
 
enum  nRF905_crc_t { NRF905_CRC_DISABLE = 0x00, NRF905_CRC_8 = 0x40, NRF905_CRC_16 = 0xC0 }
 CRC Checksum. More...
 
enum  nRF905_addr_size_t { NRF905_ADDR_SIZE_1 = 0x01, NRF905_ADDR_SIZE_4 = 0x04 }
 Address size. More...
 

Functions

void nRF905_init (void)
 Initialise, must be called before anything else! More...
 
void nRF905_setChannel (uint16_t channel)
 Channel to listen and transmit on. More...
 
void nRF905_setBand (nRF905_band_t band)
 Frequency band. More...
 
void nRF905_setAutoRetransmit (nRF905_auto_retran_t val)
 Set auto retransmit. More...
 
void nRF905_setLowRxPower (nRF905_low_rx_t val)
 Set low power receive. More...
 
void nRF905_setTransmitPower (nRF905_pwr_t val)
 Set output power. More...
 
void nRF905_setCRC (nRF905_crc_t val)
 Set CRC. More...
 
void nRF905_setClockOut (nRF905_outclk_t val)
 Set clock output. More...
 
void nRF905_setPayloadSize (uint8_t size)
 Payload size. More...
 
void nRF905_setAddressSize (nRF905_addr_size_t size)
 Address size. More...
 
uint8_t nRF905_receiveBusy (void)
 See if the attach match is asserted. More...
 
uint8_t nRF905_airwayBusy (void)
 See if airway is busy (carrier detect pin asserted). More...
 
void nRF905_setListenAddress (uint32_t address)
 Set address to listen to. More...
 
uint8_t nRF905_TX (uint32_t sendTo, void *data, uint8_t len, nRF905_nextmode_t nextMode)
 Begin a transmission. More...
 
void nRF905_RX (void)
 Enter receive mode. More...
 
void nRF905_read (void *data, uint8_t len)
 Get received payload. More...
 
void nRF905_powerDown (void)
 Sleep. More...
 
void nRF905_powerUp (void)
 Enter standby mode. More...
 
void nRF905_standby (void)
 Enter standby mode. More...
 
void nRF905_getConfigRegisters (void *)
 Read configuration registers into byte array of NRF905_REGISTER_COUNT elements, mainly for debugging. More...
 
void nRF905_SERVICE (void)
 If interrupts are disabled (::NRF905_INTERRUPTS in nRF905_config.h) then this function should be called as often as possible to process any events. More...
 
uint8_t nRF905_irq_off (void)
 When using interrupts use this to disable them for the nRF905. More...
 
void nRF905_irq_on (uint8_t origVal)
 When using interrupts use this to re-enable them for the nRF905. More...
 

Macro Definition Documentation

◆ NRF905_CALC_CHANNEL

#define NRF905_CALC_CHANNEL (   f,
 
)    ((((f) / (1 + (b>>1))) - 422400000UL) / 100000UL)

Workout channel from frequency & band.

◆ NRF905_DEFAULT_RXADDR

#define NRF905_DEFAULT_RXADDR   0xE7E7E7E7

Default receive address.

◆ NRF905_DEFAULT_TXADDR

#define NRF905_DEFAULT_TXADDR   0xE7E7E7E7

Default transmit/destination address.

◆ NRF905_MAX_PAYLOAD

#define NRF905_MAX_PAYLOAD   32

Maximum payload size.

◆ NRF905_NO_INTERRUPT

#define NRF905_NO_INTERRUPT ( )
Value:
for(uint8_t nrf905_irq __attribute__((__cleanup__(_nRF905_iRestore))) = nRF905_irq_off(), \
nrf905_tmp = 1; nrf905_tmp ; nrf905_tmp = 0)
uint8_t nRF905_irq_off(void)
When using interrupts use this to disable them for the nRF905.

Disable nRF905 interrupts for code inside this block.

When communicating with other SPI devices on the same bus as the radio then you should wrap those sections in a NRF905_NO_INTERRUPT() block, this will stop the nRF905 interrupt from running and trying to use the bus at the same time. This macro is based on the code from avr/atomic.h, and wraps the nRF905_irq_off() and nRF905_irq_on() functions instead of messing with global interrupts. It is safe to return, break or continue inside an NRF905_NO_INTERRUPT() block.

Example:

nRF905_RX();
NRF905_NO_INTERRUPT()
{
OLED.write("blah", 2, 10); // Communicate with SPI OLED display
}

◆ NRF905_REGISTER_COUNT

#define NRF905_REGISTER_COUNT   10

Configuration register count.

Enumeration Type Documentation

◆ nRF905_addr_size_t

Address size.

This is actually used as the SYNC word

Enumerator
NRF905_ADDR_SIZE_1 

1 byte (not recommended, a lot of false invalid packets will be received)

NRF905_ADDR_SIZE_4 

4 bytes

◆ nRF905_auto_retran_t

Auto re-transmit options.

Enumerator
NRF905_AUTO_RETRAN_DISABLE 

Disable auto re-transmit.

NRF905_AUTO_RETRAN_ENABLE 

Enable auto re-transmit.

◆ nRF905_band_t

Frequency bands.

Enumerator
NRF905_BAND_433 

433MHz band

NRF905_BAND_868 

868/915MHz band

NRF905_BAND_915 

868/915MHz band

◆ nRF905_crc_t

CRC Checksum.

The CRC is calculated across the address (SYNC word) and payload

Enumerator
NRF905_CRC_DISABLE 

Disable CRC.

NRF905_CRC_8 

8bit CRC (Don't know what algorithm is used for this one)

NRF905_CRC_16 

16bit CRC (CRC16-CCITT-FALSE (0xFFFF))

◆ nRF905_low_rx_t

Save a few mA by reducing receive sensitivity.

Enumerator
NRF905_LOW_RX_DISABLE 

Disable low power receive.

NRF905_LOW_RX_ENABLE 

Enable low power receive.

◆ nRF905_nextmode_t

Available modes after transmission complete.

Enumerator
NRF905_NEXTMODE_STANDBY 

Standby mode.

NRF905_NEXTMODE_RX 

Receive mode.

NRF905_NEXTMODE_TX 

Transmit mode (will auto-retransmit if ::NRF905_AUTO_RETRAN is NRF905_AUTO_RETRAN_ENABLE, otherwise will transmit a carrier wave with no data)

◆ nRF905_outclk_t

Output a clock signal on pin 3 of IC.

Enumerator
NRF905_OUTCLK_DISABLE 

Disable output clock.

NRF905_OUTCLK_4MHZ 

4MHz clock

NRF905_OUTCLK_2MHZ 

2MHz clock

NRF905_OUTCLK_1MHZ 

1MHz clock

NRF905_OUTCLK_500KHZ 

500KHz clock (default)

◆ nRF905_pwr_t

Output power (n means negative, n10 = -10).

Enumerator
NRF905_PWR_n10 

-10dBm = 100uW

NRF905_PWR_n2 

-2dBm = 631uW

NRF905_PWR_6 

6dBm = 4mW

NRF905_PWR_10 

10dBm = 10mW

Function Documentation

◆ nRF905_airwayBusy()

uint8_t nRF905_airwayBusy ( void  )

See if airway is busy (carrier detect pin asserted).

Returns
1 if other transmissions detected, otherwise 0

◆ nRF905_getConfigRegisters()

void nRF905_getConfigRegisters ( void *  )

Read configuration registers into byte array of NRF905_REGISTER_COUNT elements, mainly for debugging.

Returns
(none)

◆ nRF905_init()

void nRF905_init ( void  )

Initialise, must be called before anything else!

Returns
(none)

◆ nRF905_irq_off()

uint8_t nRF905_irq_off ( void  )

When using interrupts use this to disable them for the nRF905.

Ideally you should wrap sensitive sections with NRF905_NO_INTERRUPT() instead, as it automatically deals with this function and nRF905_irq_on()

See also
nRF905_irq_on() and NRF905_NO_INTERRUPT()
Returns
The previous interrupt status; 1 if interrupt was enabled, 0 if it was already disabled

◆ nRF905_irq_on()

void nRF905_irq_on ( uint8_t  origVal)

When using interrupts use this to re-enable them for the nRF905.

Ideally you should wrap sensitive sections with NRF905_NO_INTERRUPT() instead, as it automatically deals with this function and nRF905_irq_off()

See also
nRF905_irq_off() and NRF905_NO_INTERRUPT()
Parameters
[origVal]The original interrupt status returned from nRF905_irq_off()
Returns
(none)

◆ nRF905_powerDown()

void nRF905_powerDown ( void  )

Sleep.

This also clears the RX payload.

Returns
(none)

◆ nRF905_powerUp()

void nRF905_powerUp ( void  )

Enter standby mode.

Will take 3ms to complete if the radio was in power down mode. nRF905_standby() does the same thing, but without the delay. There must be a 3ms delay between powering up and beginning a transmission.

Returns
(none)

◆ nRF905_read()

void nRF905_read ( void *  data,
uint8_t  len 
)

Get received payload.

This function can be called multiple times to read a few bytes at a time. The payload is cleared when the radio enters power down mode or leaves standby and enters RX mode. The radio will not receive anymore data until all of the payload has been read or cleared.

Parameters
[data]Buffer for the data
[len]How many bytes to get
Returns
(none)

◆ nRF905_receiveBusy()

uint8_t nRF905_receiveBusy ( void  )

See if the attach match is asserted.

Returns
1 if currently receiving payload or payload is ready to be read, otherwise 0

◆ nRF905_RX()

void nRF905_RX ( void  )

Enter receive mode.

If the radio is currently transmitting then receive mode will be entered once it has finished. This function will also automatically power up the radio and leave standby mode.

Returns
(none)

◆ nRF905_SERVICE()

void nRF905_SERVICE ( void  )

If interrupts are disabled (::NRF905_INTERRUPTS in nRF905_config.h) then this function should be called as often as possible to process any events.

If the radio seems to stop receiving new data then you're probably not calling this often enough (at least every few milliseconds).

Returns
(none)

◆ nRF905_setAddressSize()

void nRF905_setAddressSize ( nRF905_addr_size_t  size)

Address size.

Parameters
[size]Address size, see nRF905_addr_size_t
Returns
(none)

◆ nRF905_setAutoRetransmit()

void nRF905_setAutoRetransmit ( nRF905_auto_retran_t  val)

Set auto retransmit.

If next mode is set to NRF905_NEXTMODE_TX when calling nRF905_TX() and auto-retransmit is enabled then it will constantly retransmit the payload, otherwise a carrier wave with no data will be transmitted instead (kinda useless).
Transmission will continue until the radio is put into standby, power down or RX mode.

Can be useful in areas with lots of interference, but you'll need to make sure you can differentiate between re-transmitted packets and new packets (like an ID number).

Other transmissions will be blocked if collision avoidance is enabled.

Parameters
[val]Enable/disable auto retransmit, see nRF905_auto_retran_t
Returns
(none)

◆ nRF905_setBand()

void nRF905_setBand ( nRF905_band_t  band)

Frequency band.

Parameters
[band]Frequency band, see nRF905_band_t
Returns
(none)
See also
nRF905_setChannel() nRF905_band_t

◆ nRF905_setChannel()

void nRF905_setChannel ( uint16_t  channel)

Channel to listen and transmit on.

433MHz band: Channel 0 is 422.4MHz up to 511 which is 473.5MHz (Each channel is 100KHz apart)

868/915MHz band: Channel 0 is 844.8MHz up to 511 which is 947MHz (Each channel is 200KHz apart)

Parameters
[channel]The channel (0 - 511)
Returns
(none)
See also
nRF905_setBand()

◆ nRF905_setClockOut()

void nRF905_setClockOut ( nRF905_outclk_t  val)

Set clock output.

Parameters
[val]Clock out frequency, see nRF905_outclk_t
Returns
(none)

◆ nRF905_setCRC()

void nRF905_setCRC ( nRF905_crc_t  val)

Set CRC.

Parameters
[val]CRC Type, see nRF905_crc_t
Returns
(none)

◆ nRF905_setListenAddress()

void nRF905_setListenAddress ( uint32_t  address)

Set address to listen to.

Note
From the datasheet: Each byte within the address should be unique. Repeating bytes within the address reduces the effectiveness of the address and increases its susceptibility to noise which increases the packet error rate. The address should also have several level shifts (that is, 10101100) reducing the statistical effect of noise and the packet error rate.
Parameters
[address]The address, a 32 bit integer (default address is 0xE7E7E7E7)
Returns
(none)

◆ nRF905_setLowRxPower()

void nRF905_setLowRxPower ( nRF905_low_rx_t  val)

Set low power receive.

Parameters
[val]Enable/disable low power receive, see nRF905_low_rx_t
Returns
(none)

◆ nRF905_setPayloadSize()

void nRF905_setPayloadSize ( uint8_t  size)

Payload size.

Parameters
[size]Payload size (1 - 32)
Returns
(none)
See also
NRF905_MAX_PAYLOAD

◆ nRF905_setTransmitPower()

void nRF905_setTransmitPower ( nRF905_pwr_t  val)

Set output power.

Parameters
[val]Output power level, see nRF905_pwr_t
Returns
(none)

◆ nRF905_standby()

void nRF905_standby ( void  )

Enter standby mode.

Similar to nRF905_powerUp() but without any delays. There must be a 3ms delay between powering up and beginning a transmission.

Returns
(none)

◆ nRF905_TX()

uint8_t nRF905_TX ( uint32_t  sendTo,
void *  data,
uint8_t  len,
nRF905_nextmode_t  nextMode 
)

Begin a transmission.

If the radio is still transmitting then the the payload and address will be updated as it is being sent, this means the payload on the receiving end may contain old and new data.
This also means that a node may receive part of a payload that was meant for a node with a different address.
Use the ::NRF905_CB_TXCOMPLETE callback to set a flag or something to ensure the transmission is complete before sending another payload.

If the radio is in power down mode then this function will take an additional 3ms to complete. If 3ms is too long then call nRF905_standby(), do whatever you need to do for at least 3ms then call nRF905_TX().

If nextMode is set to NRF905_NEXTMODE_RX then this function will take an additional 700us to complete.
If 700us is too long then set nextMode to NRF905_NEXTMODE_STANDBY and call nRF905_RX() in the ::NRF905_CB_TXCOMPLETE callback instead.

If data is NULL and/or len is 0 then the payload will not be modified, whatever was previously transmitted will be sent again to the sendTo address.

For the collision avoidance to work the radio should be in RX mode for around 5ms before attempting to transmit.

Parameters
[sendTo]Address to send the payload to
[data]The data
[len]Data length (max NRF905_MAX_PAYLOAD)
[nextMode]What mode to enter once the transmission is complete, see nRF905_nextmode_t
Returns
0 if other transmissions are going on and collision avoidance is enabled, 1 if transmission has successfully began