nrf24L01Plus.h File Reference

Nordic driver. More...

#include <stdbool.h>
#include "utilities.h"
#include "bio.h"
#include "ssp0.h"
Include dependency graph for nrf24L01Plus.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define NORDIC_EXCHANGE_SPI(byte)   ssp0_exchange_byte(byte)
 
#define NORDIC_EXCHANGE_MULTI_BYTE(ptr, len)   ssp0_exchange_data(ptr, len)
 
#define NORDIC_LOCK_SPI()
 
#define NORDIC_UNLOCK_SPI()
 
#define NORDIC_DELAY_US(us)   delay_us(us)
 
#define NORDIC_CS_ENABLE()   board_io_nordic_cs()
 
#define NORDIC_CS_DISABLE()   board_io_nordic_ds()
 
#define NORDIC_CE_HIGH()   board_io_nordic_ce_high()
 
#define NORDIC_CE_LOW()   board_io_nordic_ce_low()
 
#define NORDIC_INT_SIGNAL()   (!board_io_nordic_irq_sig()) /* Signal is active low */
 

Functions

void nordic_init (unsigned char payload, unsigned short mhz, unsigned short bitrate_kbps)
 
bool nordic_is_air_free ()
 
void nordic_rx_to_Stanby1 ()
 
void nordic_standby1_to_rx ()
 
void nordic_standby1_to_tx_mode1 ()
 
void nordic_standby1_to_tx_mode2 ()
 
void nordic_tx_mode2_to_standby1_through_power_down ()
 
bool nordic_is_tx_fifo_full ()
 
bool nordic_is_tx_fifo_empty ()
 
void nordic_clear_all_intr_flags ()
 Clears all interrupt flags to de-assert interrupt signal. More...
 
void nordic_queue_tx_fifo (char *data, unsigned short length)
 
void nordic_mode1_send_single_packet (char *data, unsigned short length)
 
bool nordic_is_packet_sent ()
 
void nordic_clear_packet_sent_flag ()
 Clears the Tx Packet sent flag. More...
 
bool nordic_is_max_retries_reached ()
 
void nordic_clear_max_retries_flag ()
 Clears the Max retries reached flag. More...
 
void nordic_flush_tx_fifo ()
 Flushes(clears) the TX FIFO Data. More...
 
bool nordic_is_packet_available ()
 
void nordic_clear_packet_available_flag ()
 Clears the RX Packet Received Flag. More...
 
char nordic_read_rx_fifo (char *data, unsigned short length)
 
void nordic_flush_rx_fifo ()
 Flushes(clears) the RX FIFO Data. More...
 
void nordic_set_intr_signals (bool rx, bool tx, bool maxTransmissions)
 
char nordic_get_intr_reg_status (void)
 
void nordic_set_crc (unsigned char length)
 
void nordic_power_up ()
 Powers up the Nordic Chip. More...
 
void nordic_power_down ()
 Powers down the Nordic chip (uses few nano-amps in power-down) More...
 
void nordic_set_channel (unsigned short MHz)
 
void nordic_set_continous_carrier_transmit (bool enable)
 Enables or disables continuous carrier transmission. More...
 
void nordic_set_air_data_rate (unsigned short kbps)
 
void nordic_set_power_level (unsigned char powerLevel)
 
void nordic_set_auto_transmit_options (unsigned short txDelayUs, unsigned char retries)
 
char nordic_get_lost_packet_cnt (bool clear)
 
char nordic_get_retransmit_count ()
 
void nordic_set_payload_for_pipe (unsigned char pipeNumber, unsigned char payload)
 
void nordic_set_addr_width (unsigned short width)
 
void nordic_set_tx_address (char *address, unsigned short length)
 
void nordic_set_rx_pipe0_addr (char *address, unsigned short length)
 
void nordic_set_rx_pipe1_addr (char *address, unsigned short length)
 
void nordic_set_auto_ack_for_pipes (bool pipe0, bool pipe1, bool pipe2, bool pipe3, bool pipe4, bool pipe5)
 
void nordic_enable_pipes (bool pipe0, bool pipe1, bool pipe2, bool pipe3, bool pipe4, bool pipe5)
 
void nordic_set_rx_pipe2_lsb_addr (char address)
 
void nordic_set_rx_pipe3_lsb_addr (char address)
 
void nordic_set_rx_pipe4_lsb_addr (char address)
 
void nordic_set_rx_pipe5_lsb_addr (char address)
 

Detailed Description

Nordic driver.

Example Code for a Nordic:
// Initialize and send a packet:
nordic_init(32, 2450, 250);
nordic_queue_tx_fifo(arrayData, 32);
// Wait for packet to be sent
while(!nordic_intr_signal());
// Optionally switch to RX Mode to receive data:
while(!nordic_intr_signal());
nordic_read_rx_fifo(arrayData, 32);
}

Macro Definition Documentation

#define NORDIC_CE_HIGH ( )    board_io_nordic_ce_high()
#define NORDIC_CE_LOW ( )    board_io_nordic_ce_low()
#define NORDIC_CS_DISABLE ( )    board_io_nordic_ds()
#define NORDIC_CS_ENABLE ( )    board_io_nordic_cs()
#define NORDIC_DELAY_US (   us)    delay_us(us)
#define NORDIC_EXCHANGE_MULTI_BYTE (   ptr,
  len 
)    ssp0_exchange_data(ptr, len)
#define NORDIC_EXCHANGE_SPI (   byte)    ssp0_exchange_byte(byte)
#define NORDIC_INT_SIGNAL ( )    (!board_io_nordic_irq_sig()) /* Signal is active low */
#define NORDIC_LOCK_SPI ( )
#define NORDIC_UNLOCK_SPI ( )

Function Documentation

void nordic_clear_all_intr_flags ( )

Clears all interrupt flags to de-assert interrupt signal.

void nordic_clear_max_retries_flag ( )

Clears the Max retries reached flag.

void nordic_clear_packet_available_flag ( )

Clears the RX Packet Received Flag.

void nordic_clear_packet_sent_flag ( )

Clears the Tx Packet sent flag.

void nordic_enable_pipes ( bool  pipe0,
bool  pipe1,
bool  pipe2,
bool  pipe3,
bool  pipe4,
bool  pipe5 
)

Enables or disables the pipes

Parameters
pipe0,pipe1,pipe2,pipe3,pipe4,pipe5Set to true, to enable the pipe.
void nordic_flush_rx_fifo ( )

Flushes(clears) the RX FIFO Data.

void nordic_flush_tx_fifo ( )

Flushes(clears) the TX FIFO Data.

char nordic_get_intr_reg_status ( void  )
Returns
the interrupt status register (not the interrupt signal).
char nordic_get_lost_packet_cnt ( bool  clear)

Gets the total number of lost packets.

Parameters
clearIf true, clears the count
Returns
The total lost packets 0-15
char nordic_get_retransmit_count ( )

Gets the total number of retransmissions.

Note
The count is cleared when new transmission starts.
void nordic_init ( unsigned char  payload,
unsigned short  mhz,
unsigned short  bitrate_kbps 
)

Initializes the chip to begin data exchange. Enables only Pipe0, sets default address for the Pipe and disables Enhanced Shockburst.

Parameters
payloadThe payload per packet 1-32
mhzThe channel number from 2402-2525
bitrate_kbpsCan only be 250, 1000, or 2000
Postcondition
Rx interrupt is reflected on interrupt signal, but not Tx
bool nordic_is_air_free ( )
Returns
TRUE if the nordic finds that the air is free to send data over the wireless medium
Warning
This hasn't been fully tested.
bool nordic_is_max_retries_reached ( )
Returns
True if max retries reached while transmitting packet in enhanced shockburst mode.
bool nordic_is_packet_available ( )
Returns
True if an RX Packet is available.
bool nordic_is_packet_sent ( )
Returns
True if a TX Packet was sent.
bool nordic_is_tx_fifo_empty ( )
Returns
True if TX FIFO is fully empty.
bool nordic_is_tx_fifo_full ( )
Returns
True if TX FIFO is Full
void nordic_mode1_send_single_packet ( char *  data,
unsigned short  length 
)

Sends the data in the Tx FIFO.

Postcondition
Returns back to Standby-1 after sending the data.
void nordic_power_down ( )

Powers down the Nordic chip (uses few nano-amps in power-down)

void nordic_power_up ( )

Powers up the Nordic Chip.

void nordic_queue_tx_fifo ( char *  data,
unsigned short  length 
)

Queues Data on the TX Fifo (FIFO can hold 3 Packets)

Precondition
TX Fifo must not be FULL
Parameters
dataThe char array data pointer
lengthThe length of the data
Note
In Tx Mode-2 data is sent automatically. In Tx Mode-1 you must use nordic_mode1_send_single_packet()
char nordic_read_rx_fifo ( char *  data,
unsigned short  length 
)

Dequeues Data from the RX Fifo

Precondition
RX Fifo must contain data
Parameters
dataThe char array data pointer
lengthThe length of the data
Returns
The data pipe data was received on (0-5)
void nordic_rx_to_Stanby1 ( )

Puts Nordic from Rx Mode to Standby-1 Mode. Standby-1 Mode can be used to send single Tx Packets and return to Rx easily.

void nordic_set_addr_width ( unsigned short  width)

Sets the width of the address.

Parameters
widthThe address width, must be 3-5
Note
Lower increases data throughput, higher might catch other wireless traffic.
void nordic_set_air_data_rate ( unsigned short  kbps)

Sets the over-the-air data-rate

Parameters
kbpsMust be 250, 1000, or 2000
Note
Lower data rate yields longer range, but potentially decreases delivery rate.
void nordic_set_auto_ack_for_pipes ( bool  pipe0,
bool  pipe1,
bool  pipe2,
bool  pipe3,
bool  pipe4,
bool  pipe5 
)

Sets the auto-ack (enhanced shockburst for the pipes)

Parameters
pipe0,pipe1,pipe2,pipe3,pipe4,pipe5Set to true, to enable auto-ack on the pipe.
void nordic_set_auto_transmit_options ( unsigned short  txDelayUs,
unsigned char  retries 
)

Sets the Enhanced Shockburst auto-transmit options

Parameters
txDelayUsThe delay in uS from 250 - 4000 for retransmission
retriesThe number of retries 1-15
void nordic_set_channel ( unsigned short  MHz)

Sets the Channel Number in Mhz

Warning
Be careful with FCC restricted range!
Parameters
MHzMust be between 2400 - 2525
void nordic_set_continous_carrier_transmit ( bool  enable)

Enables or disables continuous carrier transmission.

void nordic_set_crc ( unsigned char  length)

Sets the length of the CRC of over-the-air packets

Parameters
lengthMust be 0, 1, or 2. Use 0 to disable CRC checking
void nordic_set_intr_signals ( bool  rx,
bool  tx,
bool  maxTransmissions 
)

Sets the triggers that enable the Interrupt Pin

Parameters
rx,tx,maxTransmissionsIf true, interrupt pin will trigger upon these detections.
Note
These are all enabled by default at power-up
void nordic_set_payload_for_pipe ( unsigned char  pipeNumber,
unsigned char  payload 
)

Sets the payload for the pipes.

Parameters
pipeNumberThe pipe number from 0-5
payloadThe payload 0-32 (0 means pipe not used)
void nordic_set_power_level ( unsigned char  powerLevel)

Sets the power level of the chip

Parameters
powerLevelMust be 0-3 with 3 being the highest
void nordic_set_rx_pipe0_addr ( char *  address,
unsigned short  length 
)

Sets the reciver's Pipe 0 Address.

Parameters
addressThe char array of address.
lengthThe length of address, must be same as what was set at nordic_setAddressWidth()
void nordic_set_rx_pipe1_addr ( char *  address,
unsigned short  length 
)

Sets the reciver's Pipe 1 Address.

Parameters
addressThe char array of address.
lengthThe length of address, must be same as what was set at nordic_setAddressWidth()
void nordic_set_rx_pipe2_lsb_addr ( char  address)

Sets the last byte of the address of Pipe2-Pipe5

Note
The top bytes are the same as Pipe1's address.
Parameters
addressThe last byte of this pipe's address.
void nordic_set_rx_pipe3_lsb_addr ( char  address)
void nordic_set_rx_pipe4_lsb_addr ( char  address)
void nordic_set_rx_pipe5_lsb_addr ( char  address)
void nordic_set_tx_address ( char *  address,
unsigned short  length 
)

Sets the address of the transmitter.

Parameters
addressThe char array of address.
lengthThe length of address, must be same as what was set at nordic_setAddressWidth()
void nordic_standby1_to_rx ( )

Puts Nordic from Standby-1 Mode to Rx Mode.

Note
To change from Rx to Tx mode, you must use nordic_RxTo_Stanby1() first!
void nordic_standby1_to_tx_mode1 ( )

Puts Nordic from Standby-1 Mode to Tx Mode-1.

Note
Tx Mode-1 is recommended for low throughput data transfers with Software ACKs since this mode can more easily transition to Rx Mode.
void nordic_standby1_to_tx_mode2 ( )

Puts Nordic from Standby-1 Mode to Tx Mode-2

Note
Tx Mode-2 is recommended for high throughput data transfers since this mode can send multiple packets in "Tx Mode" without going to Standby. The only compromise is that you must use nordic_TxMode2_toStandby1_throughPowerDown() to transition back to Rx. Also, Nordic uses more power in this mode compared to Mode-1.
void nordic_tx_mode2_to_standby1_through_power_down ( )

This transitions from Tx Mode-2 to Standby-1 without sending a packet. This powers-down nordic, then powers it up, which takes about 150uS