Files

RF tranceiver (hal_nrf)
[nRF24L01+ HAL]


This is the nRF24L01+ transceiver used in several Nordic Semiconductor devices. The transceiver is set up and controlled via an internal SPI interface on the chip. The HAL for the radio transceiver hides this SPI interface from the programmer.

The nRF24LE1 uses the same 2.4GHz GFSK RF transceiver with embedded protocol engine (Enhanced ShockBurst™) that is found in the nRF24L01+ single chip RF Transceiver.

The RF Transceiver module is configured and operated through the RF transceiver map. This register map is accessed by the MCU through a dedicated on-chip Serial Peripheral interface (SPI) and is available in all power modes of the RF Transceiver module. The register map contains all configuration registers in the RF Transceiver and is accessible in all operation modes of the transceiver. The radio transceiver HAL hides this register map and the usage of the internal SPI.

This HAL module contains setup functions for configurating the radio; operation functions for controlling the radio when active and for sending and receiving data; and test functions for setting the radio in test modes.

Files

file  hal_nrf_reg.h
 

Register definitions for nRF24L01+.


Setup

void hal_nrf_set_irq_mode (hal_nrf_irq_source_t int_source, _Bool irq_state)
void hal_nrf_activate_features (void)
void hal_nrf_enable_dynamic_payload (_Bool enable)
void hal_nrf_enable_ack_payload (_Bool enable)
void hal_nrf_enable_dynamic_ack (_Bool enable)
void hal_nrf_setup_dynamic_payload (uint8_t setup)
uint8_t hal_nrf_read_rx_payload_width (void)
void hal_nrf_write_ack_payload (uint8_t pipe, const uint8_t *tx_pload, uint8_t length)
uint8_t hal_nrf_get_clear_irq_flags (void)
uint8_t hal_nrf_clear_irq_flags_get_status (void)
void hal_nrf_clear_irq_flag (hal_nrf_irq_source_t int_source)
void hal_nrf_set_crc_mode (hal_nrf_crc_mode_t crc_mode)
void hal_nrf_open_pipe (hal_nrf_address_t pipe_num, _Bool auto_ack)
void hal_nrf_close_pipe (hal_nrf_address_t pipe_num)
void hal_nrf_set_address (const hal_nrf_address_t address, const uint8_t *addr)
uint8_t hal_nrf_get_address (uint8_t address, uint8_t *addr)
void hal_nrf_set_auto_retr (uint8_t retr, uint16_t delay)
void hal_nrf_set_address_width (hal_nrf_address_width_t address_width)
uint8_t hal_nrf_get_address_width (void)
void hal_nrf_set_rx_payload_width (uint8_t pipe_num, uint8_t pload_width)
_Bool hal_nrf_get_irq_mode (uint8_t int_source)
uint8_t hal_nrf_get_irq_flags (void)
uint8_t hal_nrf_get_pipe_status (uint8_t pipe_num)
uint8_t hal_nrf_get_auto_retr_status (void)
uint8_t hal_nrf_get_packet_lost_ctr (void)
uint8_t hal_nrf_get_rx_payload_width (uint8_t pipe_num)

Operation

void hal_nrf_set_operation_mode (hal_nrf_operation_mode_t op_mode)
void hal_nrf_set_power_mode (hal_nrf_pwr_mode_t pwr_mode)
void hal_nrf_set_rf_channel (uint8_t channel)
void hal_nrf_set_output_power (hal_nrf_output_power_t power)
void hal_nrf_set_datarate (hal_nrf_datarate_t datarate)
uint8_t hal_nrf_get_tx_fifo_status (void)
_Bool hal_nrf_tx_fifo_empty (void)
_Bool hal_nrf_tx_fifo_full (void)
uint8_t hal_nrf_get_rx_fifo_status (void)
uint8_t hal_nrf_get_fifo_status (void)
_Bool hal_nrf_rx_fifo_empty (void)
_Bool hal_nrf_rx_fifo_full (void)
uint8_t hal_nrf_get_transmit_attempts (void)
_Bool hal_nrf_get_carrier_detect (void)
uint8_t hal_nrf_get_rx_data_source (void)
uint16_t hal_nrf_read_rx_payload (uint8_t *rx_pload)
void hal_nrf_write_tx_payload (const uint8_t *tx_pload, uint8_t length)
void hal_nrf_write_tx_payload_noack (const uint8_t *tx_pload, uint8_t length)
void hal_nrf_reuse_tx (void)
_Bool hal_nrf_get_reuse_tx_status (void)
void hal_nrf_flush_rx (void)
void hal_nrf_flush_tx (void)
uint8_t hal_nrf_nop (void)

Test

void hal_nrf_set_pll_mode (_Bool pll_lock)
void hal_nrf_set_lna_gain (_Bool lna_gain)
void hal_nrf_enable_continious_wave (_Bool enable)

SPI interface

uint8_t hal_nrf_rw (uint8_t value)

Function Documentation

void hal_nrf_set_irq_mode ( hal_nrf_irq_source_t  int_source,
_Bool  irq_state 
)

Enable or disable interrupt for radio. Use this function to enable or disable one of the interrupt sources for the radio. This function only changes state for selected int_type, the rest of the interrupt sources are left unchanged.

Parameters:
int_sourceRadio interrupt Source.
irq_stateEnable or Disable.

< nRF24L01 config register

< nRF24L01 config register

Definition at line 248 of file hal_nrf.c.

{
  config_t config;
  config.value = hal_nrf_read_reg (CONFIG);

    switch (int_source)
    {
        case HAL_NRF_MAX_RT:
            config.bits.mask_max_rt = irq_state ? 0U : 1U;
      break;
    case HAL_NRF_TX_DS:
      config.bits.mask_tx_ds = irq_state ? 0U : 1U;
      break;
    case HAL_NRF_RX_DR:
      config.bits.mask_rx_dr = irq_state ? 0U : 1U;
      break;
  }

  hal_nrf_write_reg (CONFIG, config.value);
}
void hal_nrf_activate_features ( void   )

Definition at line 620 of file hal_nrf.c.

{return;}
void hal_nrf_enable_dynamic_payload ( _Bool  enable )

Enables the dynamic packet length

Parameters:
enableWhether enable or disable dynamic packet length

< nRF24L01 Exclusive feature setup

< nRF24L01 Exclusive feature setup

Definition at line 631 of file hal_nrf.c.

{
  feature_t feature;
  feature.value = hal_nrf_read_reg (FEATURE);
  feature.bits.en_dpl = (enable) ? 1U : 0U;

  hal_nrf_write_reg (FEATURE, feature.value);
}
void hal_nrf_enable_ack_payload ( _Bool  enable )

Enables the ACK payload feature

Parameters:
enableWhether to enable or disable ACK payload

< nRF24L01 Exclusive feature setup

< nRF24L01 Exclusive feature setup

Definition at line 640 of file hal_nrf.c.

{
  feature_t feature;
  feature.value = hal_nrf_read_reg (FEATURE);
  feature.bits.en_ack_pay = (enable) ? 1U : 0U;

  hal_nrf_write_reg (FEATURE, feature.value);
}
void hal_nrf_enable_dynamic_ack ( _Bool  enable )

Enables the dynamic ack feature

Parameters:
enableWhether to enable or disable Dynamic ACK

< nRF24L01 Exclusive feature setup

< nRF24L01 Exclusive feature setup

Definition at line 649 of file hal_nrf.c.

{
  feature_t feature;
  feature.value = hal_nrf_read_reg (FEATURE);
  feature.bits.en_dyn_ack = (enable) ? 1U : 0U;

  hal_nrf_write_reg (FEATURE, feature.value);
}
void hal_nrf_setup_dynamic_payload ( uint8_t  setup )

Function for enabling dynmic payload size. The input parameter contains is a byte where the bit values tells weather the pipe should use dynamic payload size. For example if bit 0 is set then pipe 0 will accept dynamic payload size.

Parameters:
setupByte value telling for which pips(s) to enable dynamic payload size

< nRF24L01 Dynamic payload setup

Definition at line 623 of file hal_nrf.c.

{
  en_pipes_t dynpd;
  dynpd.value = setup & (uint8_t)~0xC0U;

  hal_nrf_write_reg (DYNPD, dynpd.value);
}
uint8_t hal_nrf_read_rx_payload_width ( void   )

Reads the payload width of the received ack payload

Returns:
Payload width of the received ack payload

< Read RX payload command

Definition at line 673 of file hal_nrf.c.

void hal_nrf_write_ack_payload ( uint8_t  pipe,
const uint8_t *  tx_pload,
uint8_t  length 
)

Write ack payload Writes the payload that will be transmitted with the ack on the given pipe.

Parameters:
pipePipe that transmits the payload
tx_ploadPointer to the payload data
lengthSize of the data to transmit

< Write ACK payload command

Definition at line 668 of file hal_nrf.c.

{
  hal_nrf_write_multibyte_reg(W_ACK_PAYLOAD | pipe, tx_pload, length);
}
uint8_t hal_nrf_get_clear_irq_flags ( void   )

Read then clears all interrupt flags. Use this function to get the interrupt flags and clear them in the same operation. Reduced radio interface activity and speed optimized.

Returns:
Interrupt_flags
Return values:
0x10Max Retransmit interrupt
0x20TX Data sent interrupt
0x40RX Data received interrupt

< nRF24L01 status register

< The value of bit 6

< The value of bit 5

< The value of bit 4

< The value of bit 6

< The value of bit 5

< The value of bit 4

Definition at line 269 of file hal_nrf.c.

{
  uint8_t retval;

  retval = hal_nrf_write_reg (STATUS, (BIT_6|BIT_5|BIT_4));

  return (retval & (BIT_6|BIT_5|BIT_4));
}
uint8_t hal_nrf_clear_irq_flags_get_status ( void   )

< nRF24L01 status register

< The value of bit 6

< The value of bit 5

< The value of bit 4

< The value of bit 6

< The value of bit 5

< The value of bit 4

< nRF24L01 status register

< The value of bit 3

< The value of bit 2

< The value of bit 1

< The value of bit 0

Definition at line 278 of file hal_nrf.c.

{
  uint8_t retval;

  // When RFIRQ is cleared (when calling write_reg), pipe information is unreliable (read again with read_reg)
  retval = hal_nrf_write_reg (STATUS, (BIT_6|BIT_5|BIT_4)) & (BIT_6|BIT_5|BIT_4);
  retval |= hal_nrf_read_reg (STATUS) & (BIT_3|BIT_2|BIT_1|BIT_0);

  return (retval);
}
void hal_nrf_clear_irq_flag ( hal_nrf_irq_source_t  int_source )

Clear one selected interrupt flag. Use this function to clear one spesific interrupt flag. Other interrupt flags are left unchanged.

Parameters:
int_sourceInterrupt source of which flag to clear

< nRF24L01 status register

Definition at line 290 of file hal_nrf.c.

{
  hal_nrf_write_reg (STATUS, SET_BIT(int_source));
}
void hal_nrf_set_crc_mode ( hal_nrf_crc_mode_t  crc_mode )

Set the CRC mode used by the radio. Use this function to set the CRC mode; CRC disabled, 1 or 2 bytes.

Parameters:
crc_modeCRC mode to use

< nRF24L01 config register

< nRF24L01 config register

Definition at line 223 of file hal_nrf.c.

{
  config_t config;
  config.value = hal_nrf_read_reg (CONFIG);

    switch (crc_mode)
    {
        case HAL_NRF_CRC_OFF:
            config.bits.en_crc = 0U;
            break;
        case HAL_NRF_CRC_8BIT:
            config.bits.en_crc = 1U;
            config.bits.crc0 = 0U;
            break;
        case HAL_NRF_CRC_16BIT:
            config.bits.en_crc = 1U;
            config.bits.crc0 = 1U;
            break;
        default:
            break;
    }

  hal_nrf_write_reg (CONFIG, config.value);
}
void hal_nrf_open_pipe ( hal_nrf_address_t  pipe_num,
_Bool  auto_ack 
)

Open radio pipe(s) and enable/ disable auto acknowledge. Use this function to open one or all pipes, with or without auto acknowledge.

Parameters:
pipe_numRadio pipe to open
auto_ackAuto_Ack ON/OFF
See also:
hal_nrf_address

< nRF24L01 enable RX addresses register

< nRF24L01 enable Auto-Acknowledge register

< The value of bit 6

< The value of bit 7

< The value of bit 6

< The value of bit 7

< nRF24L01 enable RX addresses register

< nRF24L01 enable Auto-Acknowledge register

Definition at line 300 of file hal_nrf.c.

{
  en_pipes_t en_rxaddr;
  en_pipes_t en_aa;
  en_rxaddr.value = hal_nrf_read_reg (EN_RXADDR);
  en_aa.value = hal_nrf_read_reg (EN_AA);

  switch(pipe_num)
  {
    case HAL_NRF_PIPE0:
    case HAL_NRF_PIPE1:
    case HAL_NRF_PIPE2:
    case HAL_NRF_PIPE3:
    case HAL_NRF_PIPE4:
    case HAL_NRF_PIPE5:
      en_rxaddr.value = en_rxaddr.value | SET_BIT(pipe_num);

      if(auto_ack)
      {
        en_aa.value = en_aa.value | SET_BIT(pipe_num);
      }
      else
      {
        en_aa.value = en_aa.value & (uint8_t)~SET_BIT(pipe_num);
      }
      break;

    case HAL_NRF_ALL:
      en_rxaddr.value = (uint8_t)(~(BIT_6|BIT_7));

      if(auto_ack)
      {
        en_aa.value = (uint8_t)(~(BIT_6|BIT_7));
      }
      else
      {
        en_aa.value = 0U;
      }
      break;

    case HAL_NRF_TX:
    default:
      break;
  }

  hal_nrf_write_reg (EN_RXADDR, en_rxaddr.value);
  hal_nrf_write_reg (EN_AA, en_aa.value);
}
void hal_nrf_close_pipe ( hal_nrf_address_t  pipe_num )

Close radio pipe(s). Use this function to close one pipe or all pipes.

Parameters:
pipe_numPipe# number to close

< nRF24L01 enable RX addresses register

< nRF24L01 enable Auto-Acknowledge register

< nRF24L01 enable RX addresses register

< nRF24L01 enable Auto-Acknowledge register

Definition at line 349 of file hal_nrf.c.

{
  en_pipes_t en_rxaddr;
  en_pipes_t en_aa;
  en_rxaddr.value = hal_nrf_read_reg (EN_RXADDR);
  en_aa.value = hal_nrf_read_reg (EN_AA);

  switch(pipe_num)
  {
    case HAL_NRF_PIPE0:
    case HAL_NRF_PIPE1:
    case HAL_NRF_PIPE2:
    case HAL_NRF_PIPE3:
    case HAL_NRF_PIPE4:
    case HAL_NRF_PIPE5:
      en_rxaddr.value = en_rxaddr.value & (uint8_t)~SET_BIT(pipe_num);
      en_aa.value = en_aa.value & (uint8_t)~SET_BIT(pipe_num);
      break;

    case HAL_NRF_ALL:
      en_rxaddr.value = 0U;
      en_aa.value = 0U;
      break;

    case HAL_NRF_TX:
    default:
      break;
  }

  hal_nrf_write_reg (EN_RXADDR, en_rxaddr.value);
  hal_nrf_write_reg (EN_AA, en_aa.value);
}
void hal_nrf_set_address ( const hal_nrf_address_t  address,
const uint8_t *  addr 
)

Set radio's RX address and TX address. Use this function to set a RX address, or to set the TX address. Beware of the difference for single and multibyte address registers.

Parameters:
addressWhich address to set
*addrBuffer from which the address is stored in

< Register write command

< nRF24L01 receive address data pipe0

< nRF24L01 receive address data pipe0

Definition at line 382 of file hal_nrf.c.

{
  switch(address)
  {
    case HAL_NRF_TX:
    case HAL_NRF_PIPE0:
    case HAL_NRF_PIPE1:
      hal_nrf_write_multibyte_reg(W_REGISTER + RX_ADDR_P0 + (uint8_t) address, addr, hal_nrf_get_address_width());
      break;
    case HAL_NRF_PIPE2:
    case HAL_NRF_PIPE3:
    case HAL_NRF_PIPE4:
    case HAL_NRF_PIPE5:
      hal_nrf_write_reg (RX_ADDR_P0 + (uint8_t) address, *addr);
      break;

    case HAL_NRF_ALL:
    default:
      break;
  }
}
uint8_t hal_nrf_get_address ( uint8_t  address,
uint8_t *  addr 
)

Get address for selected pipe. Use this function to get address for selected pipe.

Parameters:
addressWhich address to get, Pipe- or TX-address
*addrbuffer in which address bytes are written.

For pipes containing only LSB byte of address, this byte is returned in the
*addr buffer.
Returns:
Numbers of bytes copied to addr

< nRF24L01 receive address data pipe0

Definition at line 404 of file hal_nrf.c.

{
  switch (address)
  {
    case HAL_NRF_PIPE0:
    case HAL_NRF_PIPE1:
    case HAL_NRF_TX:
      return (uint8_t)hal_nrf_read_multibyte_reg (address, addr);
    default:
      *addr = hal_nrf_read_reg(RX_ADDR_P0 + address);
      return 1U;
  }
}
void hal_nrf_set_auto_retr ( uint8_t  retr,
uint16_t  delay 
)

Set auto acknowledge parameters. Use this function to set retransmit and retransmit delay parameters.

Parameters:
retrNumber of retransmit, 0 equ retransmit OFF
delayRetransmit delay in µs. Must be a

< nRF24L01 setup of automatic retransmission register

Definition at line 418 of file hal_nrf.c.

{
  setup_retr_t setup_retr;
  setup_retr.bits.ard = (uint8_t)(delay >> 8);
  setup_retr.bits.arc = retr;

  hal_nrf_write_reg (SETUP_RETR, setup_retr.value);
}
void hal_nrf_set_address_width ( hal_nrf_address_width_t  address_width )

Set radio's address width. Use this function to define the radio's address width, referes to both RX and TX.

Parameters:
address_widthAddress with in bytes

< nRF24L01 setup of address width register

Definition at line 427 of file hal_nrf.c.

{
  setup_aw_t setup_aw;
  setup_aw.value = 0U;
  setup_aw.bits.aw = (uint8_t)address_width - 2U;

  hal_nrf_write_reg (SETUP_AW, setup_aw.value);
}
uint8_t hal_nrf_get_address_width ( void   )

Gets the radio's address width.

Returns:
Address width

< nRF24L01 setup of address width register

Definition at line 436 of file hal_nrf.c.

{
  return hal_nrf_read_reg (SETUP_AW) + 2U;
}
void hal_nrf_set_rx_payload_width ( uint8_t  pipe_num,
uint8_t  pload_width 
)

Set payload width for selected pipe. Use this function to set the number of bytes expected on a selected pipe.

Parameters:
pipe_numPipe number to set payload width for
pload_widthnumber of bytes expected

< nRF24L01 # of bytes in rx payload for pipe0

Definition at line 441 of file hal_nrf.c.

{
  hal_nrf_write_reg (RX_PW_P0 + pipe_num, pload_width);
}
_Bool hal_nrf_get_irq_mode ( uint8_t  int_source )

Read current interrupt mode for selected interrupt source. Use this function to get the interrupt source's mode, either enabled or disabled.

Parameters:
int_sourceInterrupt source to get mode from
Returns:
Interrupt Mode
Return values:
FALSEInterrupt disabled
TRUEInterrupt enabled
uint8_t hal_nrf_get_irq_flags ( void   )

Read all interrupt flags. Use this function to get the interrupt flags. This function is similar to hal_nrf_get_clear_irq_flags with the exception that it does NOT clear the irq_flags.

Returns:
Interrupt_flags
Return values:
0x10Max Retransmit interrupt
0x20TX Data sent interrupt
0x40RX Data received interrupt

< The value of bit 6

< The value of bit 5

< The value of bit 4

Definition at line 295 of file hal_nrf.c.

{
  return hal_nrf_nop() & (BIT_6|BIT_5|BIT_4);
}
uint8_t hal_nrf_get_pipe_status ( uint8_t  pipe_num )

Get pipe status. Use this function to check status for a selected pipe.

Parameters:
pipe_numPipe number to check status for
Returns:
Pipe_Status
Return values:
0x00Pipe is closed, autoack disabled
0x01Pipe is open, autoack disabled
0x03Pipe is open, autoack enabled

< nRF24L01 enable RX addresses register

< nRF24L01 enable Auto-Acknowledge register

Definition at line 446 of file hal_nrf.c.

{
  en_pipes_t en_rxaddr;
  en_pipes_t en_aa;
  uint8_t en_rx_r, en_aa_r;

  en_rxaddr.value = hal_nrf_read_reg (EN_RXADDR);
  en_aa.value = hal_nrf_read_reg (EN_AA);

  switch (pipe_num)
  {
    case 0:
      en_rx_r = en_rxaddr.bits.pipe_0;
      en_aa_r = en_aa.bits.pipe_0;
      break;
    case 1:
      en_rx_r = en_rxaddr.bits.pipe_1;
      en_aa_r = en_aa.bits.pipe_1;
      break;
    case 2:
      en_rx_r = en_rxaddr.bits.pipe_2;
      en_aa_r = en_aa.bits.pipe_2;
      break;
    case 3:
      en_rx_r = en_rxaddr.bits.pipe_3;
      en_aa_r = en_aa.bits.pipe_3;
      break;
    case 4:
      en_rx_r = en_rxaddr.bits.pipe_4;
      en_aa_r = en_aa.bits.pipe_4;
      break;
    case 5:
      en_rx_r = en_rxaddr.bits.pipe_5;
      en_aa_r = en_aa.bits.pipe_5;
      break;
    default:
      en_rx_r = 0U;
      en_aa_r = 0U;
      break;
  }

  return (uint8_t)(en_aa_r << 1) + en_rx_r;
}
uint8_t hal_nrf_get_auto_retr_status ( void   )

Get auto retransmit parameters. Use this function to get the auto retransmit parameters, retrans count and retrans delay.

Returns:
AutoRetrans Parameters
Return values:
UpperNibbleRetransmit Delay
LowerNibbleRetransmit Count

< nRF24L01 transmit observe register

Definition at line 490 of file hal_nrf.c.

uint8_t hal_nrf_get_packet_lost_ctr ( void   )

Get packet lost counter Use this function to get the packet(s) counter.

Returns:
packet lost counter

< nRF24L01 transmit observe register

< The value of bit 7

< The value of bit 6

< The value of bit 5

< The value of bit 4

Definition at line 495 of file hal_nrf.c.

{
  return ((hal_nrf_read_reg(OBSERVE_TX) & (BIT_7|BIT_6|BIT_5|BIT_4)) >> 4);
}
uint8_t hal_nrf_get_rx_payload_width ( uint8_t  pipe_num )

Get RX payload width for selected pipe. Use this function to get the expected payload width for selected ppe number.

Parameters:
pipe_numPipe number to get payload width for
Returns:
Payload_Width in bytes

< nRF24L01 # of bytes in rx payload for pipe0

< nRF24L01 # of bytes in rx payload for pipe1

< nRF24L01 # of bytes in rx payload for pipe2

< nRF24L01 # of bytes in rx payload for pipe3

< nRF24L01 # of bytes in rx payload for pipe4

< nRF24L01 # of bytes in rx payload for pipe5

Definition at line 500 of file hal_nrf.c.

{
  uint8_t pw;

  switch (pipe_num)
  {
    case 0:
      pw = hal_nrf_read_reg (RX_PW_P0);
      break;
    case 1:
      pw = hal_nrf_read_reg (RX_PW_P1);
      break;
    case 2:
      pw = hal_nrf_read_reg (RX_PW_P2);
      break;
    case 3:
      pw = hal_nrf_read_reg (RX_PW_P3);
      break;
    case 4:
      pw = hal_nrf_read_reg (RX_PW_P4);
      break;
    case 5:
      pw = hal_nrf_read_reg (RX_PW_P5);
      break;
    default:
      pw = 0U;
      break;
  }

  return pw;
}
void hal_nrf_set_operation_mode ( hal_nrf_operation_mode_t  op_mode )

Set radio's operation mode. Use this function to enter PTX (primary TX) or PRX (primary RX).

Parameters:
op_modeOperation mode

< nRF24L01 config register

< nRF24L01 config register

Definition at line 189 of file hal_nrf.c.

{
  config_t config;
  config.value = hal_nrf_read_reg (CONFIG);

  if(op_mode == HAL_NRF_PRX)
  {
    config.bits.prim_rx = 1U;
  }
  else
  {
    config.bits.prim_rx = 0U;
  }

  hal_nrf_write_reg (CONFIG, config.value);
}
void hal_nrf_set_power_mode ( hal_nrf_pwr_mode_t  pwr_mode )

Set radio's power mode. Use this function to power_up or power_down radio.

Parameters:
pwr_modePOWER_UP or POWER_DOWN

< nRF24L01 config register

< nRF24L01 config register

Definition at line 206 of file hal_nrf.c.

{
  config_t config;
  config.value = hal_nrf_read_reg (CONFIG);

  if(pwr_mode == HAL_NRF_PWR_UP)
  {
    config.bits.pwr_up = 1U;
  }
  else
  {
    config.bits.pwr_up = 0U;
  }

  hal_nrf_write_reg (CONFIG, config.value);
}
void hal_nrf_set_rf_channel ( uint8_t  channel )

Set radio's RF channel. Use this function to select which RF channel to use.

Parameters:
channelRF channel

< nRF24L01 RF channel register

Definition at line 532 of file hal_nrf.c.

{
  rf_ch_t rf_ch;
  rf_ch.value = 0U;
  rf_ch.bits.rf_ch = channel;
  hal_nrf_write_reg (RF_CH, rf_ch.value);
}
void hal_nrf_set_output_power ( hal_nrf_output_power_t  power )

Set radio's TX output power. Use this function set the radio's TX output power.

Parameters:
powerRadio's TX output power

< nRF24L01 RF setup register

< nRF24L01 RF setup register

Definition at line 540 of file hal_nrf.c.

{
  rf_setup_t rf_setup;
  rf_setup.value = hal_nrf_read_reg (RF_SETUP);

  rf_setup.bits.rf_pwr = (uint8_t)power;

  hal_nrf_write_reg (RF_SETUP, rf_setup.value);
}
void hal_nrf_set_datarate ( hal_nrf_datarate_t  datarate )

Set radio's on-air datarate. Use this function to select radio's on-air datarate.

Parameters:
datarateOn-air datarate

< nRF24L01 RF setup register

< nRF24L01 RF setup register

Definition at line 550 of file hal_nrf.c.

{
  rf_setup_t rf_setup;
  rf_setup.value = hal_nrf_read_reg (RF_SETUP);

  switch (datarate)
  {
    case HAL_NRF_250KBPS:
      rf_setup.bits.rf_dr_low = 1U;
      rf_setup.bits.rf_dr_high = 0U;
      break;
    case HAL_NRF_1MBPS:
      rf_setup.bits.rf_dr_low = 0U;
      rf_setup.bits.rf_dr_high = 0U;
      break;
    case HAL_NRF_2MBPS:
    default:
      rf_setup.bits.rf_dr_low = 0U;
      rf_setup.bits.rf_dr_high = 1U;
      break;
  }

  hal_nrf_write_reg (RF_SETUP, rf_setup.value);
}
uint8_t hal_nrf_get_tx_fifo_status ( void   )

Get radio's TX FIFO status. Use this function to get the radio's TX FIFO status.

Returns:
TX FIFO status
Return values:
0x00TX FIFO NOT empty, but NOT full
0x01FIFO empty
0x02FIFO full

< nRF24L01 FIFO status register

< FIFO_STATUS register bit 5

< FIFO_STATUS register bit 4

Definition at line 595 of file hal_nrf.c.

{
  return ((hal_nrf_read_reg(FIFO_STATUS) & ((1U<<TX_FIFO_FULL)|(1U<<TX_EMPTY))) >> 4);
}
_Bool hal_nrf_tx_fifo_empty ( void   )

Check for TX FIFO empty. Use this function to check if TX FIFO is empty.

Returns:
TX FIFO empty bit
Return values:
FALSETX FIFO NOT empty
TRUETX FIFO empty

< nRF24L01 FIFO status register

< FIFO_STATUS register bit 4

Definition at line 585 of file hal_nrf.c.

{
  return (bool)((hal_nrf_read_reg(FIFO_STATUS) >> TX_EMPTY) & 0x01U);
}
_Bool hal_nrf_tx_fifo_full ( void   )

Check for TX FIFO full. Use this function to check if TX FIFO is full.

Returns:
TX FIFO full bit
Return values:
FALSETX FIFO NOT full
TRUETX FIFO full

< nRF24L01 FIFO status register

< FIFO_STATUS register bit 5

Definition at line 590 of file hal_nrf.c.

{
  return (bool)((hal_nrf_read_reg(FIFO_STATUS) >> TX_FIFO_FULL) & 0x01U);
}
uint8_t hal_nrf_get_rx_fifo_status ( void   )

Get radio's RX FIFO status. Use this function to get the radio's TX FIFO status.

Returns:
RX FIFO status
Return values:
0x00RX FIFO NOT empty, but NOT full
0x01RX FIFO empty
0x02RX FIFO full

< nRF24L01 FIFO status register

< FIFO_STATUS register bit 1

< FIFO_STATUS register bit 0

Definition at line 600 of file hal_nrf.c.

{
  return (hal_nrf_read_reg(FIFO_STATUS) & ((1U<<RX_FULL)|(1U<<RX_EMPTY)));
}
uint8_t hal_nrf_get_fifo_status ( void   )

< nRF24L01 FIFO status register

Definition at line 605 of file hal_nrf.c.

_Bool hal_nrf_rx_fifo_empty ( void   )

Check for RX FIFO empty. Use this function to check if RX FIFO is empty.

Reads STATUS register to check this, not FIFO_STATUS

Returns:
RX FIFO empty bit
Return values:
FALSERX FIFO NOT empty
TRUERX FIFO empty

< nRF24L01 FIFO status register

< FIFO_STATUS register bit 0

Definition at line 575 of file hal_nrf.c.

{
  return (bool)((hal_nrf_read_reg(FIFO_STATUS) >> RX_EMPTY) & 0x01U);
}
_Bool hal_nrf_rx_fifo_full ( void   )

Check for RX FIFO full. Use this function to check if RX FIFO is full.

Returns:
RX FIFO full bit
Return values:
FALSERX FIFO NOT full
TRUERX FIFO full

< nRF24L01 FIFO status register

< FIFO_STATUS register bit 1

Definition at line 580 of file hal_nrf.c.

{
  return (bool)((hal_nrf_read_reg(FIFO_STATUS) >> RX_FULL) & 0x01U);
}
uint8_t hal_nrf_get_transmit_attempts ( void   )

Get radio's transmit attempts status. Use this function to get number of retransmit attempts and number of packet lost.

Returns:
Retransmit attempts counters

< nRF24L01 transmit observe register

< The value of bit 3

< The value of bit 2

< The value of bit 1

< The value of bit 0

Definition at line 610 of file hal_nrf.c.

_Bool hal_nrf_get_carrier_detect ( void   )

Get the carrier detect flag. Use this function to get the carrier detect flag, used to detect stationary disturbance on selected RF channel.

Returns:
Carrier Detect
Return values:
FALSECarrier NOT Detected
TRUECarrier Detected

< nRF24L01 carrier detect register

Definition at line 615 of file hal_nrf.c.

{
  return (bool)(hal_nrf_read_reg(CD) & 0x01U);
}
uint8_t hal_nrf_get_rx_data_source ( void   )

Get RX data source. Use this function to read which RX pipe data was received on for current top level FIFO data packet.

Returns:
pipe number of current packet present

< The value of bit 3

< The value of bit 2

< The value of bit 1

Definition at line 683 of file hal_nrf.c.

{
  return ((hal_nrf_nop() & (BIT_3|BIT_2|BIT_1)) >> 1);
}
uint16_t hal_nrf_read_rx_payload ( uint8_t *  rx_pload )

Read RX payload. Use this function to read top level payload available in the RX FIFO.

Parameters:
*rx_ploadpointer to buffer in which RX payload are stored
Returns:
pipe number (MSB byte) and packet length (LSB byte)

Definition at line 678 of file hal_nrf.c.

void hal_nrf_write_tx_payload ( const uint8_t *  tx_pload,
uint8_t  length 
)

Write TX payload to radio. Use this function to write a packet of TX payload into the radio. length number of bytes, which are stored in *tx_pload.

Parameters:
*tx_ploadpointer to buffer in which TX payload are present
lengthnumber of bytes to write

< Write TX payload command

Definition at line 658 of file hal_nrf.c.

{
  hal_nrf_write_multibyte_reg(W_TX_PAYLOAD, tx_pload, length);
}
void hal_nrf_write_tx_payload_noack ( const uint8_t *  tx_pload,
uint8_t  length 
)

Write TX payload which do not require ACK. When transmitting a ACK is not required nor sent from the receiver. The payload will always be assumed as "sent".

Use this function to write a packet of TX payload into the radio. length number of bytes, which are stored in *tx_pload.

Parameters:
*tx_ploadpointer to buffer in which TX payload are present
lengthnumber of bytes to write

< Write ACK payload command

Definition at line 663 of file hal_nrf.c.

void hal_nrf_reuse_tx ( void   )

Reuse TX payload. Use this function to set that the radio is using the last transmitted payload for the next packet as well.

< Reuse TX payload command

Definition at line 688 of file hal_nrf.c.

_Bool hal_nrf_get_reuse_tx_status ( void   )

Get status of reuse TX function. Use this function to check if reuse TX payload is activated

Returns:
Reuse TX payload mode
Return values:
FALSENot activated
TRUEActivated

< FIFO_STATUS register bit 6

< FIFO_STATUS register bit 6

Definition at line 695 of file hal_nrf.c.

{
  return (bool)((hal_nrf_get_fifo_status() & (1U<<TX_REUSE)) >> TX_REUSE);
}
void hal_nrf_flush_rx ( void   )

Flush RX FIFO. Use this function to flush the radio's RX FIFO.

< Flush RX register command

Definition at line 700 of file hal_nrf.c.

void hal_nrf_flush_tx ( void   )

Flush TX FIFO. Use this function to flush the radio's TX FIFO.

< Flush TX register command

Definition at line 707 of file hal_nrf.c.

uint8_t hal_nrf_nop ( void   )

No Operation command. Use this function to receive the radio's status register.

Returns:
Status register

< No Operation command, used for reading status register

Definition at line 714 of file hal_nrf.c.

{
  uint8_t retval;

  CSN_LOW();
  retval = hal_nrf_rw(NOP);
  CSN_HIGH();

  return retval;
}
void hal_nrf_set_pll_mode ( _Bool  pll_lock )

Set radio's PLL mode. Use this function to either LOCK or UNLOCK the radio's PLL.

Parameters:
pll_lockPLL locked, TRUE or FALSE

< nRF24L01 RF setup register

< nRF24L01 RF setup register

Definition at line 725 of file hal_nrf.c.

{
  rf_setup_t rf_setup;
  rf_setup.value = hal_nrf_read_reg (RF_SETUP);
  rf_setup.bits.pll_lock = (pll_lock) ? 1U : 0U;

  hal_nrf_write_reg(RF_SETUP, rf_setup.value);
}
void hal_nrf_set_lna_gain ( _Bool  lna_gain )

Set radio's LNA gain mode. Use this function to either use HI current or LOW current mode for the radio.

Parameters:
lna_gainLNA gain mode
void hal_nrf_enable_continious_wave ( _Bool  enable )

Enables continuous carrier transmit. Use this function to enable or disable continuous carrier transmission.

Parameters:
enableEnable continuous carrier

< nRF24L01 RF setup register

< nRF24L01 RF setup register

Definition at line 734 of file hal_nrf.c.

{
  rf_setup_t rf_setup;
  rf_setup.value = hal_nrf_read_reg (RF_SETUP);
  rf_setup.bits.cont_wave = (enable ? 1U : 0U);

  hal_nrf_write_reg(RF_SETUP, rf_setup.value);
}
uint8_t hal_nrf_rw ( uint8_t  value )

Basis function, nrf_rw This function is used by the basis functions to exchange data with the data.

Parameters:
valueDatabyte to write
Returns:
Databyte from radio.

Definition at line 25 of file hal_nrf_hw.c.

{
  SPIRDAT = value;
  while(!(SPIRSTAT & (uint8_t)0x02U)) // wait for byte transfer finished
  {
  }
  return SPIRDAT;             // return SPI read value
}