# nrf905

nRF905 library for wireless communication.

Author | Rob Jansen, Copyright © 2020..2024, all rights reserved.
Adapted-by |
Compiler | 2.5r8

Description

    Libray for wireless transmission and reception using the nRF905.

Sources

    nRF905 product specification Revision 1.5 (April 2008)

Notes

    The following pins must be defined by the main program before
             including this library:
             -) alias nrf905_spi_sck               -- To sck of nRF905
             -) alias nrf905_spi_sck_direction
             -) alias nrf905_spi_sdi               -- To MISO of nRF905
             -) alias nrf905_spi_sdi_direction
             -) alias nrf905_spi_sdo               -- To MOSI of nRFF905
             -) alias nrf905_spi_sdo_direction
             -) alias nrf905_csn_pin               -- To csn of nRF905
             -) alias nrf905_csn_pin_direction
             -) alias nrf905_txen_pin              -- To txen of nRF905
             -) alias nrf905_txen_pin_direction
             -) alias nrf905_trx_ce_pin            -- To (tx_)ce of nRF905
             -) alias nrf905_trx_ce_pin_direction
             Optional pins (see defines below):
             -) alias nrf905_pwr_up_pin            -- To pwr(_up) of nRF905
             -) alias nrf905_pwr_up_pin_direction
             -) alias nrf905_dr_pin                -- To DR of nRF905. Pin is
             -) alias nrf905_dr_pin_direction         connected to the INT pin.

Dependencies

No dependency found

## Summary

### Global variables/contants

- `const byte _NRF905_CMD_READ_RX_PAYLOAD = 0x24`
- `const byte _NRF905_CMD_READ_TX_PAYLOAD = 0x21`
- `const byte NRF905_POWER_LEVEL_MIN = 0b000_0000`
- `var byte _nrf905_tx_payload_size`
- `const byte NRF905_MIN_PAYLOAD = 1`
- `const byte _NRF905_REG_CRC_ENABLE = 0x09`
- `const byte _NRF905_CMD_WRITE_TX_ADDR = 0x22`
- `const byte _NRF905_CMD_WRITE_TX_PAYLOAD = 0x20`
- `const byte _NRF905_MASK_OUTPUT_CLOCK = 0b0000_0011`
- `const word NRF905_MAX_CHANNEL = 511`
- `const byte _NRF905_REG_RX_ADDRESS_WIDTH = 0x02`
- `const _NRF905_STATUS_DR = 0b0010_0000`
- `const byte NRF905_CRYSTAL_CLK_4MHZ = 0x00`
- `const _NRF905_STATUS_AM = 0b1000_0000`
- `const byte NRF905_CRYSTAL_CLK_8MHZ = 0x01`
- `const byte _NRF905_CMD_CHANNEL_CONFIG = 0x80`
- `const byte _NRF905_CMD_READ_CONFIG_REG = 0x10`
- `const byte NRF905_OUTPUT_CLK_500KHZ = 0x03`
- `const byte NRF905_MAX_TX_ADDRESS = 4`
- `const byte NRF905_OUTPUT_CLK_4MHZ = 0x00`
- `const byte NRF905_CRYSTAL_CLK_20MHZ = 0x04`
- `const byte _NRF905_REG_TX_ADDRESS_WIDTH = 0x02`
- `const byte _NRF905_REG_OUTPUT_CLK_ENABLE = 0x09`
- `const byte _NRF905_REG_RX_POWER_REDUCTION = 0x01`
- `var byte _nrf905_rx_address_width`
- `const byte NRF905_OUTPUT_CLK_2MHZ = 0x01`
- `var byte _nrf905_rx_payload_size`
- `var volatile byte nrf905_rx_buffer[NRF905_RX_BUFFER_SIZE]`
- `const byte _NRF905_REG_OUTPUT_CLK_FREQ = 0x09`
- `const byte NRF905_OUTPUT_CLK_1MHZ = 0x02`
- `const byte _NRF905_MASK_CRYSTAL_CLOCK = 0b0011_1000`
- `const byte NRF905_MAX_RX_ADDRESS = 4`
- `const byte _NRF905_REG_RX_PAYLOAD_WIDTH = 0x03`
- `const byte _NRF905_MASK_PAYLOAD = 0b0011_1111`
- `const byte _NRF905_REG_OSC_FREQUENCY = 0x09`
- `const _NRF905_STATUS_AM_DR = 0b1010_0000`
- `const byte _NRF905_REG_RX_ADDRESS = 0x05`
- `const byte _NRF905_MASK_POWER = 0b0000_1100`
- `const byte _NRF905_CMD_NOP = 0xFF`
- `const byte NRF905_CRYSTAL_CLK_16MHZ = 0x03`
- `const byte _NRF905_MASK_CONFIG = 0b0000_1111`
- `const byte NRF905_POWER_LEVEL_MAX = 0b000_1100`
- `var byte _nrf905_tx_address_width`
- `const byte _NRF905_REG_OUTPUT_POWER = 0x01`
- `const byte _NRF905_REG_CHANNEL = 0x00`
- `const byte NRF905_CRYSTAL_CLK_12MHZ = 0x02`
- `const byte NRF905_POWER_LEVEL_MED = 0b000_1000`
- `const byte _NRF905_REG_TX_PAYLOAD_WIDTH = 0x04`
- `const byte NRF905_MAX_PAYLOAD = 32`
- `const byte _NRF905_CMD_READ_TX_ADDR = 0x23`
- `const byte _NRF905_REG_CRC_MODE = 0x09`
- `const byte NRF905_POWER_LEVEL_LOW = 0b000_0100`
- `var bit _nrf905_tx_active`
- `const byte _NRF905_CMD_WRITE_CONFIG_REG = 0x00`
- `const byte _NRF905_REG_PLL = 0x01`
- `const byte _NRF905_REG_AUTO_RETRANSMIT = 0x01`

### Procedures

- `nrf905_power_up_rx()`
- `nrf905_set_tx_address_width_1_byte()`
- `nrf905_power_up_tx()`
- `nrf905_set_rx_payload_width(byte in payload)`
- `nrf905_enable_auto_retransmit()`
- `nrf905_enable_crc_check()`
- `nrf905_print_status_register()`
- `nrf905_set_rx_address_width_4_byte()`
- `nrf905_set_tx_address_width_4_byte()`
- `nrf905_set_crc_check_16_bit()`
- `nrf905_set_crystal_clock(byte in crystal_clock)`
- `nrf905_disable_output_clock()`
- `nrf905_on()`
- `nrf905_send_data(byte in data[], byte in nr_of_bytes)`
- `nrf905_set_rx_address_width_1_byte()`
- `nrf905_set_output_clock_frequency(byte in output_clock)`
- `nrf905_set_rx_normal_power()`
- `nrf905_print_configuration_register()`
- `nrf905_set_rf_band_433()`
- `nrf905_enable_output_clock()`
- `nrf905_disable_auto_retransmit()`
- `nrf905_disable_crc_check()`
- `nrf905_set_crc_check_8_bit()`
- `nrf905_set_tx_payload_width(byte in payload)`
- `nrf905_power_up_device()`
- `nrf905_set_power_level(byte in power)`
- `nrf905_power_down_device()`
- `nrf905_standby()`
- `nrf905_set_rf_band_868_915()`
- `nrf905_set_rx_address(dword in address)`
- `nrf905_set_tx_address(dword in address)`
- `nrf905_init()`
- `nrf905_set_rx_low_power()`
- `nrf905_set_rf_channel(word in channel)`

Private

- `_nrf905_copy_data()`

### Functions

- `nrf905_tx_ready() return bit`
- `nrf905_data_available() return bit`
- `nrf905_get_data() return bit`

Private

- `_nrf905_get_dr_status() return bit`
- `_nrf905_get_am_status() return bit`
- `_nrf905_get_status_register() return byte`
- `_nrf905_read_configuration_register(byte in location) return byte`

## API details

### Global variables/contants

- `const byte _NRF905_CMD_READ_RX_PAYLOAD = 0x24`

  No documentation found

- `const byte _NRF905_CMD_READ_TX_PAYLOAD = 0x21`

  No documentation found

- `const byte NRF905_POWER_LEVEL_MIN = 0b000_0000`

      Power levels. Default is -10 dBm.

- `var byte _nrf905_tx_payload_size`

  No documentation found

- `const byte NRF905_MIN_PAYLOAD = 1`

      General minimum and maximum definitions.

- `const byte _NRF905_REG_CRC_ENABLE = 0x09`

  No documentation found

- `const byte _NRF905_CMD_WRITE_TX_ADDR = 0x22`

  No documentation found

- `const byte _NRF905_CMD_WRITE_TX_PAYLOAD = 0x20`

  No documentation found

- `const byte _NRF905_MASK_OUTPUT_CLOCK = 0b0000_0011`

  No documentation found

- `const word NRF905_MAX_CHANNEL = 511`

  No documentation found

- `const byte _NRF905_REG_RX_ADDRESS_WIDTH = 0x02`

  No documentation found

- `const _NRF905_STATUS_DR = 0b0010_0000`

      Bit positions for Data Ready and Address Match.

- `const byte NRF905_CRYSTAL_CLK_4MHZ = 0x00`

      Crystal clock options, check your module which crystal clock is used.

- `const _NRF905_STATUS_AM = 0b1000_0000`

  No documentation found

- `const byte NRF905_CRYSTAL_CLK_8MHZ = 0x01`

  No documentation found

- `const byte _NRF905_CMD_CHANNEL_CONFIG = 0x80`

  No documentation found

- `const byte _NRF905_CMD_READ_CONFIG_REG = 0x10`

  No documentation found

- `const byte NRF905_OUTPUT_CLK_500KHZ = 0x03`

  No documentation found

- `const byte NRF905_MAX_TX_ADDRESS = 4`

  No documentation found

- `const byte NRF905_OUTPUT_CLK_4MHZ = 0x00`

      Output clock options.

- `const byte NRF905_CRYSTAL_CLK_20MHZ = 0x04`

  No documentation found

- `const byte _NRF905_REG_TX_ADDRESS_WIDTH = 0x02`

  No documentation found

- `const byte _NRF905_REG_OUTPUT_CLK_ENABLE = 0x09`

  No documentation found

- `const byte _NRF905_REG_RX_POWER_REDUCTION = 0x01`

  No documentation found

- `var byte _nrf905_rx_address_width`

  No documentation found

- `const byte NRF905_OUTPUT_CLK_2MHZ = 0x01`

  No documentation found

- `var byte _nrf905_rx_payload_size`

      Variable to store the set payload sized. The main program can change the
      payload size dynamically.

- `var volatile byte nrf905_rx_buffer[NRF905_RX_BUFFER_SIZE]`

      Receiver buffer containing the data received by the nrf905.

- `const byte _NRF905_REG_OUTPUT_CLK_FREQ = 0x09`

  No documentation found

- `const byte NRF905_OUTPUT_CLK_1MHZ = 0x02`

  No documentation found

- `const byte _NRF905_MASK_CRYSTAL_CLOCK = 0b0011_1000`

  No documentation found

- `const byte NRF905_MAX_RX_ADDRESS = 4`

  No documentation found

- `const byte _NRF905_REG_RX_PAYLOAD_WIDTH = 0x03`

  No documentation found

- `const byte _NRF905_MASK_PAYLOAD = 0b0011_1111`

  No documentation found

- `const byte _NRF905_REG_OSC_FREQUENCY = 0x09`

  No documentation found

- `const _NRF905_STATUS_AM_DR = 0b1010_0000`

      Used to detect data for this device.

- `const byte _NRF905_REG_RX_ADDRESS = 0x05`

  No documentation found

- `const byte _NRF905_MASK_POWER = 0b0000_1100`

  No documentation found

- `const byte _NRF905_CMD_NOP = 0xFF`

      Instruction set of the NRF905.

- `const byte NRF905_CRYSTAL_CLK_16MHZ = 0x03`

  No documentation found

- `const byte _NRF905_MASK_CONFIG = 0b0000_1111`

      Register masks.

- `const byte NRF905_POWER_LEVEL_MAX = 0b000_1100`

      +10dBm

- `var byte _nrf905_tx_address_width`

      Address width we need to remember.

- `const byte _NRF905_REG_OUTPUT_POWER = 0x01`

  No documentation found

- `const byte _NRF905_REG_CHANNEL = 0x00`

      Configuration register. This register is in fact 10 bytes wide with functions
      spread over several bits. The address mentioned below is the byte on which
      the function can be found.

- `const byte NRF905_CRYSTAL_CLK_12MHZ = 0x02`

  No documentation found

- `const byte NRF905_POWER_LEVEL_MED = 0b000_1000`

      +6dBm

- `const byte _NRF905_REG_TX_PAYLOAD_WIDTH = 0x04`

  No documentation found

- `const byte NRF905_MAX_PAYLOAD = 32`

  No documentation found

- `const byte _NRF905_CMD_READ_TX_ADDR = 0x23`

  No documentation found

- `const byte _NRF905_REG_CRC_MODE = 0x09`

  No documentation found

- `const byte NRF905_POWER_LEVEL_LOW = 0b000_0100`

      -2dBm

- `var bit _nrf905_tx_active`

      Indicates when we are busy sending data.

- `const byte _NRF905_CMD_WRITE_CONFIG_REG = 0x00`

  No documentation found

- `const byte _NRF905_REG_PLL = 0x01`

  No documentation found

- `const byte _NRF905_REG_AUTO_RETRANSMIT = 0x01`

  No documentation found

### Procedures

- `nrf905_power_up_rx()`

      Power up the receiver

- `nrf905_set_tx_address_width_1_byte()`

      Set the transmitter address field width to 1 byte.

- `nrf905_power_up_tx()`

      Power up the transmitter.

- `nrf905_set_rx_payload_width(byte in payload)`

      Set the receiver payload width.

- `nrf905_enable_auto_retransmit()`

      Enable the auto retransmit feature.

- `nrf905_enable_crc_check()`

      Enable the CRC check.

- `nrf905_print_status_register()`

  No documentation found

- `nrf905_set_rx_address_width_4_byte()`

      Set the receiver address fieldt width to 4 bytes.

- `nrf905_set_tx_address_width_4_byte()`

      Set the transmitter address fieldt width to 4 bytes.

- `nrf905_set_crc_check_16_bit()`

      Set the crc check to 16 bit.

- `nrf905_set_crystal_clock(byte in crystal_clock)`

      Set the crystal clock frequency.

- `nrf905_disable_output_clock()`

      Disable the output clock feature.

- `nrf905_on()`

      Switch the nRF905 on.

- `nrf905_send_data(byte in data[], byte in nr_of_bytes)`

      Power up the transmitter and send the given data to the previously set TX
      address. The transmitter remains powered up after completion.

- `nrf905_set_rx_address_width_1_byte()`

      Set the receiver address field width to 1 byte.

- `nrf905_set_output_clock_frequency(byte in output_clock)`

      Set the output clock frequency. Use the defined ouput clock constants.

- `nrf905_set_rx_normal_power()`

      Set normal power receiver mode.

- `nrf905_print_configuration_register()`

  No documentation found

- `nrf905_set_rf_band_433()`

      Set the RF band to 433 MHz.

- `nrf905_enable_output_clock()`

      Enable the output clock feature.

- `nrf905_disable_auto_retransmit()`

      Disable the auto retransmit feature.

- `nrf905_disable_crc_check()`

      Disable the CRC check.

- `nrf905_set_crc_check_8_bit()`

      Set the crc check to 8 bit.

- `nrf905_set_tx_payload_width(byte in payload)`

      Set the transmitter payload width.

- `nrf905_power_up_device()`

      Power up the device. Only used when power pin is defined.

- `nrf905_set_power_level(byte in power)`

      Set the power level of the transmitter. Use the defined power rate constants.

- `nrf905_power_down_device()`

      Power down the device. Only used when a power pin is defined.

- `nrf905_standby()`

      Place the nRF905 in standby.

- `nrf905_set_rf_band_868_915()`

      Set the RF band to 868 / 915 MHz.

- `nrf905_set_rx_address(dword in address)`

      Set the receiver address. Address can be 1 byte or 4 bytes.

- `nrf905_set_tx_address(dword in address)`

      Set the transmitter address. Address can be 1 byte or 4 bytes.

- `nrf905_init()`

      Initialize the SPI interface and the nRF905 module. The module is placed in
      its default mode: Channel 108, 433 MHz band, -10 dBm power, normal power use,
      no retransmit, tx and rx address width 4 bytes, maximum payload, output clock
      500 kHz, output clock enabled, crystal clock 20 MHz, crc check enabled,
      16-bit crc check used. After intialized the module is in standby mode.

- `nrf905_set_rx_low_power()`

      Set low power receiver mode.

- `nrf905_set_rf_channel(word in channel)`

      Set the RF channel. Channel is a 9-bit value. Some info on channels:
      ) Channel 0 is 422.4MHz for the 433MHz band, each channel increments the
      frequency by 100KHz, so channel 10 would be 423.4MHz
      ) Channel 0 is 844.8MHz for the 868/915MHz band, each channel increments the
      frequency by 200KHz, so channel 10 would be 846.8MHz
      ) Max channel is 511 (473.5MHz / 947.0MHz)

Private

- `_nrf905_copy_data()`

      Copy the rx payload to the receive buffer. Depending on the selected mode
      this procedure can be called by the function nrf905_get_data() or by the
      function _nrf905_interrupt().

### Functions

- `nrf905_tx_ready() return bit`

      Check the status of the transmission and return TRUE when ready.

- `nrf905_data_available() return bit`

      Check if there is data available and return TRUE when ready.

- `nrf905_get_data() return bit`

      Checks if data is available and if so copies the data to the nrf905_read_buffer
      and returns TRUE when done.

Private

- `_nrf905_get_dr_status() return bit`

      Get the status of the Data Ready flag and return its value.

- `_nrf905_get_am_status() return bit`

      Get the status of the Address Match flag and return its value.

- `_nrf905_get_status_register() return byte`

      Read the status register and return the contents of it.

- `_nrf905_read_configuration_register(byte in location) return byte`

      Read the configuration register from the given location and return the
      value read.

## Related samples

Here are the list of samples which use this library:

16f1823 | 16f1823_nrf905.jal
16f1825 | 16f1825_nrf905.jal