手机数码

nRF905 AVR/Arduino Library/Driver

微信扫一扫,分享到朋友圈

nRF905 AVR/Arduino Library/Driver
0

The nRF905 is a radio transceiver IC similar to the well known nRF24L01, but operates at 433/898/915MHz instead of 2.4GHz, has a much longer range and has a few extra IO pins, however the nRF905 air data rate is only 50Kbps compared to nRF24L01′s 2Mbps.

This library offers quite a bit of flexibility: Optional use of interrupts, 2 of the connections to the module are optional since their states can also be accessed by the ICs status register, and supports basic collision avoidance.


Download from
GitHub

nRF905 ATmega48/88/168/328 Arduino Uno Description
VCC 3.3V 3.3V Power (3.3V)
CE D7 (13) 7 Stand by – High = TX/RX mode, Low = standby
TXE B1 (15) 9 Transmit or receive mode – High = transmit, Low = receive
PWR B0 (14) 8 Power up – High = on, Low = off
CD D2 (4) 2 Carrier detect – High when a signal is detected, for collision avoidance
AM Address Match – High when receiving a packet that has the same address as the one set for this device, optional since state is stored in register, not used by this library
DR D3 (5) 3 Data Ready – High when finished transmitting/High when new data received, optional since state is stored in register, if interrupts are used this pin must be connected
SO B4 (18) 12 SPI MISO
SI B3 (17) 11 SPI MOSI
SCK B5 (19) 13 SPI SCK
CSN B2 (16) 10 SPI SS
GND GND GND Ground

Some of the module pin names differ from the IC pin names in the datasheet:

Module IC
CE TRX_EN
TXE TX_EN

The nRF905 is not 5V compatible, so some level conversions will need to be done with the Arduino outputs, a simple resistor divider or resistor and zener diode will do the trick, only TXE, CE, PWR, SI, SCK and CSN pins need level conversion.

Divider Zener




The nRF905 has 511 channels ranging 422.4MHz – 473.5MHz in 100KHz steps on the 433MHz band and 844.8MHz – 947MHz in 200KHz steps on the 868/915MHz band (remember to check which frequencies are legal in your country!), but each channel overlaps adjacent channels so there is only a total of 170 usable channels at once.

Searching for nRF905, PTR8000 and PTR8000+ should yield some results for modules on Ebay and DealExtreme, you should be able to get 2 for around £10.

API

Function Description Parameters Returns
nRF905_init() Initializes library, must be called first! None void
nRF905_setFrequency(

byte band,

ulong frequency

)
Sets the radio channel, the channel is calculated from the frequency band
– NRF905_BAND_433 / NRF905_BAND_868 / NRF905_BAND_915

frequency
– The frequency to use in Hz, like 433200000 for 433.2MHz
void
nRF905_setChannel(

byte band,

uint channel

)
Sets the radio channel band
– NRF905_BAND_433 / NRF905_BAND_868 / NRF905_BAND_915

channel
– The channel to use (0 – 511)
void
nRF905_setAutoRetransmit(

byte val

)
Constantly re-transmit payload as fast as possible while in transmit mode, useful for high noise environments val
– NRF905_AUTO_RETRAN_ENABLE / NRF905_AUTO_RETRAN_DISABLE
void
nRF905_setLowRxPower(

byte val

)
Save 1.6mA by reducing receiver sensitivity val
– NRF905_LOW_RX_ENABLE / NRF905_LOW_RX_DISABLE
void
nRF905_setTransmitPower(

byte val

)
Set transmit power val
– NRF905_PWR_n10 / NRF905_PWR_n2 / NRF905_PWR_6 / NRF905_PWR_10
void
nRF905_setCRCMode(

byte val

)
CRC size val
– NRF905_CRC_MODE_8 / NRF905_CRC_MODE_16
void
nRF905_setCRC(

byte val

)
Use CRC val
– NRF905_CRC_ENABLE / NRF905_CRC_DISABLE
void
nRF905_setClockOut(

byte val

)
Clock output val
– NRF905_OUTCLK_ENABLE / NRF905_OUTCLK_DISABLE
void
nRF905_setClockOutFreq(

byte val

)
Clock output frequency val
– NRF905_OUTCLK_500KHZ / NRF905_OUTCLK_1MHZ / NRF905_OUTCLK_2MHZ / NRF905_OUTCLK_4MHZ
void
nRF905_setPayloadSize(

byte size

)
Set payload size size
– Payload size (1 – 32)
void
nRF905_setTXAddress(

long address

)
Address of device to send payload to address
– Address of device to send payload to, number 0 – 4294967295
void
nRF905_setRXAddress(

long address

)
Address of this device address
– Address of this device, number 0 – 4294967295
void
nRF905_setData(

byte* data

byte len

)
Set the payload data data
– Pointer to buffer to send

len
– Length of buffer
void
nRF905_airwayBusy() See if other transmissions are going on, returns true if there are, otherwise false None bool
nRF905_send() Put into transmit mode and send payload, if collision detection is enabled and other transmissions are going on false is returned and payload is not transmitted, otherwise true returned None bool
nRF905_waitForTransmitEnd() Block until current transmission has finished None void
nRF905_receive() Put into receive mode None void
nRF905_getData(

byte* data

byte len

)
Get received payload, if no data is available false is returned, otherwise data is copied to buffer and returns true data
– Pointer to buffer were data will go

len
– How many bytes to get
bool
nRF905_powerUp() Turn on radio (takes 3ms) None void
nRF905_powerDown() Turn off radio None void
nRF905_enterStandBy() Standby, stops receiving and transmitting None void
nRF905_leaveStandBy() Enable receiving and transmitting again None void

Tips and things to watch out for

  • You can call nRF905_receive() straight after calling nRF905_sendData(), this makes the radio go into receive mode once the payload has finished transmitting.
  • If auto-retransmit is disabled and you don’t put the radio into receive mode after transmitting, it will constantly transmit a carrier signal with no data, if collision avoidance is enabled then the carrier signal will stop other radios from transmitting.
  • Calling an nRF905_set***() function will put the radio into standby mode (radio must be in standby mode to change registers), if you want it to carry on receiving you must call nRF905_receive() again.
  • nRF905_waitForTransmitEnd() should only be called after nRF905_sendData() and only if it returned true, can be useful for counting retransmits when auto-retransmit is enabled (DR is set low again when a new retransmit starts).

阅读原文...


Avatar

分析源码安装Go的过程(初稿)

上一篇

Perl - How to print a hash?

下一篇

您也可能喜欢

评论已经被关闭。

插入图片
nRF905 AVR/Arduino Library/Driver

长按储存图像,分享给朋友