nRF905 Radio Library for AVR and Arduino
3.0
|
#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... | |
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... | |
#define NRF905_CALC_CHANNEL | ( | f, | |
b | |||
) | ((((f) / (1 + (b>>1))) - 422400000UL) / 100000UL) |
Workout channel from frequency & band.
#define NRF905_DEFAULT_RXADDR 0xE7E7E7E7 |
Default receive address.
#define NRF905_DEFAULT_TXADDR 0xE7E7E7E7 |
Default transmit/destination address.
#define NRF905_MAX_PAYLOAD 32 |
Maximum payload size.
#define NRF905_NO_INTERRUPT | ( | ) |
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
}
#define NRF905_REGISTER_COUNT 10 |
Configuration register count.
enum nRF905_addr_size_t |
enum nRF905_auto_retran_t |
enum nRF905_band_t |
enum nRF905_crc_t |
enum nRF905_low_rx_t |
enum 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) |
enum nRF905_outclk_t |
enum nRF905_pwr_t |
uint8_t nRF905_airwayBusy | ( | void | ) |
See if airway is busy (carrier detect pin asserted).
void nRF905_getConfigRegisters | ( | void * | ) |
Read configuration registers into byte array of NRF905_REGISTER_COUNT elements, mainly for debugging.
void nRF905_init | ( | void | ) |
Initialise, must be called before anything else!
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()
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()
[origVal] | The original interrupt status returned from nRF905_irq_off() |
void nRF905_powerDown | ( | void | ) |
Sleep.
This also clears the RX payload.
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.
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.
[data] | Buffer for the data |
[len] | How many bytes to get |
uint8_t nRF905_receiveBusy | ( | void | ) |
See if the attach match is asserted.
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.
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).
void nRF905_setAddressSize | ( | nRF905_addr_size_t | size | ) |
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.
[val] | Enable/disable auto retransmit, see nRF905_auto_retran_t |
void nRF905_setBand | ( | nRF905_band_t | band | ) |
Frequency band.
[band] | Frequency band, see nRF905_band_t |
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)
[channel] | The channel (0 - 511) |
void nRF905_setClockOut | ( | nRF905_outclk_t | val | ) |
void nRF905_setCRC | ( | nRF905_crc_t | val | ) |
void nRF905_setListenAddress | ( | uint32_t | address | ) |
Set address to listen to.
[address] | The address, a 32 bit integer (default address is 0xE7E7E7E7) |
void nRF905_setLowRxPower | ( | nRF905_low_rx_t | val | ) |
Set low power receive.
[val] | Enable/disable low power receive, see nRF905_low_rx_t |
void nRF905_setPayloadSize | ( | uint8_t | size | ) |
void nRF905_setTransmitPower | ( | nRF905_pwr_t | val | ) |
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.
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.
[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 |