nRF_API.h File Reference

This file manages the NRF24L01 RF device and provide low level driver access (based on SPI driver). More...

#include "config.h"

Include dependency graph for nRF_API.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define NRF_select()   (NRF_CS_PORT &= ~(1<<NRF_CS_PIN))
#define NRF_unselect()   (NRF_CS_PORT |= (1<<NRF_CS_PIN))
#define NRF_disable()   (NRF_CE_PORT &= ~(1<<NRF_CE_PIN))
#define NRF_enable()   (NRF_CE_PORT |= (1<<NRF_CE_PIN))
#define IDLE   0x00
#define MAX_RT   0x10
#define TX_DS   0x20
#define RX_DR   0x40
#define SPI_CFG   0x40
#define SPI_CTR   0x01
#define SPI_CLK   0x00
#define SPI0E   0x02
#define READ_REG   0x00
#define WRITE_REG   0x20
#define RD_RX_PLOAD   0x61
#define WR_TX_PLOAD   0xA0
#define FLUSH_TX   0xE1
#define FLUSH_RX   0xE2
#define REUSE_TX_PL   0xE3
#define NOP   0xFF
#define CONFIG   0x00
#define EN_AA   0x01
#define EN_RXADDR   0x02
#define SETUP_AW   0x03
#define SETUP_RETR   0x04
#define RF_CH   0x05
#define RF_SETUP   0x06
#define STATUS   0x07
#define OBSERVE_TX   0x08
#define CD   0x09
#define RX_ADDR_P0   0x0A
#define RX_ADDR_P1   0x0B
#define RX_ADDR_P2   0x0C
#define RX_ADDR_P3   0x0D
#define RX_ADDR_P4   0x0E
#define RX_ADDR_P5   0x0F
#define TX_ADDR   0x10
#define RX_PW_P0   0x11
#define RX_PW_P1   0x12
#define RX_PW_P2   0x13
#define RX_PW_P3   0x14
#define RX_PW_P4   0x15
#define RX_PW_P5   0x16
#define FIFO_STATUS   0x17
#define NRF_RX_DR   6
#define NRF_TX_DR   5
#define NRF_MAX_RT   4
#define NFR_read_reg(reg)   (NRF_Read(reg|READ_REG))
#define NFR_write_reg(reg, val)   (NRF_RW_Reg(reg|WRITE_REG,val))
#define NRF_init_tx()   (NRF_disable(),NFR_write_reg(CONFIG,0x0A))
#define NRF_init_rx()   (NRF_disable(),NFR_write_reg(CONFIG,0x0B),NRF_enable())
#define Is_not_NRF_IRQ()   ((NRF_IRQ_PORT & (1<<NRF_IRQ_PIN))? TRUE : FALSE)
#define Is_NRF_IRQ()   ((NRF_IRQ_PORT & (1<<NRF_IRQ_PIN))? FALSE : TRUE)
#define NRF_tx_buffer(buf, n)   (NRF_write_buf(WR_TX_PLOAD,buf,n))
#define NRF_rx_buffer(buf, n)   (NRF_read_buf(RD_RX_PLOAD,buf,n))
#define NRF_set_payload(pipe, n)   (NFR_write_reg(RX_PW_P##pipe,n))
#define NRF_set_channel(n)   (NFR_write_reg(RF_CH,n))
#define NRF_set_byte_addr(n)   (NFR_write_reg(SETUP_AW,n-2))
#define NRF_ack_RX_DR()   (NFR_write_reg(STATUS,(1<<NRF_RX_DR)))
#define NRF_ack_TX_DR()   (NFR_write_reg(STATUS,(1<<NRF_TX_DR)))
#define NRF_ack_MAX_RT()   (NFR_write_reg(STATUS,(1<<NRF_MAX_RT)))
#define NRF_ack_received()   (NRF_ack_RX_DR())
#define NRF_ack_transmit()   (NRF_ack_TX_DR())
#define NRF_ack_timeout()   (NRF_ack_MAX_RT())
#define NRF_flush_rx()   (NFR_write_reg(FLUSH_RX,0))
#define Is_NRF_RX_DR()   (NFR_read_reg(STATUS)&(1<<NRF_RX_DR) ? TRUE : FALSE)
#define Is_NRF_TX_DR()   (NFR_read_reg(STATUS)&(1<<NRF_TX_DR) ? TRUE : FALSE)
#define Is_NRF_MAX_RT()   (NFR_read_reg(STATUS)&(1<<NRF_MAX_RT) ? TRUE : FALSE)
#define Is_NRF_received()   (Is_NRF_RX_DR())
#define Is_NRF_transmit()   (Is_NRF_TX_DR())
#define Is_NRF_timeout()   (Is_NRF_MAX_RT())
#define NRF_Write_addr(reg, buf, n)   NRF_write_buf(reg+0x20,buf, n)

Functions

U8 SPI_RW (U8 byte)
U8 NRF_Read (U8 reg)
 NRF_ReadRead one byte from nRF24L01 register, 'reg'.
U8 NRF_RW_Reg (U8 reg, U8 value)
 NRF_RW_RegWrites value 'value' to register 'reg'.
U8 NRF_read_buf (U8 reg, U8 *pBuf, U8 bytes)
 NRF_read_bufReads 'bytes' of bytes from register 'reg', typically used to read RX payload, Rx/Tx address.
U8 NRF_write_buf (U8 reg, U8 *pBuf, U8 bytes)
 NRF_write_bufWrites contents of buffer '*pBuf' to nRF24L01, typically used to write TX payload, Rx/Tx address.


Detailed Description

This file manages the NRF24L01 RF device and provide low level driver access (based on SPI driver).

Original author: Runar Kjellhaug from Nordic RefDesign with Dallas MCU

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file nRF_API.h.


Define Documentation

 
#define NRF_select (  )     (NRF_CS_PORT &= ~(1<<NRF_CS_PIN))

Definition at line 77 of file nRF_API.h.

Referenced by NRF_Read(), NRF_read_buf(), NRF_RW_Reg(), and NRF_write_buf().

 
#define NRF_unselect (  )     (NRF_CS_PORT |= (1<<NRF_CS_PIN))

Definition at line 78 of file nRF_API.h.

Referenced by NRF_Read(), NRF_read_buf(), NRF_RW_Reg(), and NRF_write_buf().

 
#define NRF_disable (  )     (NRF_CE_PORT &= ~(1<<NRF_CE_PIN))

Definition at line 79 of file nRF_API.h.

Referenced by cdc_rf_task_init(), and NRF_write_buf().

 
#define NRF_enable (  )     (NRF_CE_PORT |= (1<<NRF_CE_PIN))

Definition at line 80 of file nRF_API.h.

Referenced by cdc_rf_task_init(), and NRF_write_buf().

#define IDLE   0x00

Definition at line 84 of file nRF_API.h.

#define MAX_RT   0x10

Definition at line 85 of file nRF_API.h.

#define TX_DS   0x20

Definition at line 86 of file nRF_API.h.

#define RX_DR   0x40

Definition at line 87 of file nRF_API.h.

#define SPI_CFG   0x40

Definition at line 89 of file nRF_API.h.

#define SPI_CTR   0x01

Definition at line 90 of file nRF_API.h.

#define SPI_CLK   0x00

Definition at line 91 of file nRF_API.h.

#define SPI0E   0x02

Definition at line 92 of file nRF_API.h.

#define READ_REG   0x00

Definition at line 96 of file nRF_API.h.

#define WRITE_REG   0x20

Definition at line 97 of file nRF_API.h.

#define RD_RX_PLOAD   0x61

Definition at line 98 of file nRF_API.h.

#define WR_TX_PLOAD   0xA0

Definition at line 99 of file nRF_API.h.

#define FLUSH_TX   0xE1

Definition at line 100 of file nRF_API.h.

#define FLUSH_RX   0xE2

Definition at line 101 of file nRF_API.h.

#define REUSE_TX_PL   0xE3

Definition at line 102 of file nRF_API.h.

#define NOP   0xFF

Definition at line 103 of file nRF_API.h.

#define CONFIG   0x00

Definition at line 106 of file nRF_API.h.

#define EN_AA   0x01

Definition at line 107 of file nRF_API.h.

#define EN_RXADDR   0x02

Definition at line 108 of file nRF_API.h.

#define SETUP_AW   0x03

Definition at line 109 of file nRF_API.h.

#define SETUP_RETR   0x04

Definition at line 110 of file nRF_API.h.

#define RF_CH   0x05

Definition at line 111 of file nRF_API.h.

#define RF_SETUP   0x06

Definition at line 112 of file nRF_API.h.

#define STATUS   0x07

Definition at line 113 of file nRF_API.h.

#define OBSERVE_TX   0x08

Definition at line 114 of file nRF_API.h.

#define CD   0x09

Definition at line 115 of file nRF_API.h.

#define RX_ADDR_P0   0x0A

Definition at line 116 of file nRF_API.h.

#define RX_ADDR_P1   0x0B

Definition at line 117 of file nRF_API.h.

#define RX_ADDR_P2   0x0C

Definition at line 118 of file nRF_API.h.

#define RX_ADDR_P3   0x0D

Definition at line 119 of file nRF_API.h.

#define RX_ADDR_P4   0x0E

Definition at line 120 of file nRF_API.h.

#define RX_ADDR_P5   0x0F

Definition at line 121 of file nRF_API.h.

#define TX_ADDR   0x10

Definition at line 122 of file nRF_API.h.

#define RX_PW_P0   0x11

Definition at line 123 of file nRF_API.h.

#define RX_PW_P1   0x12

Definition at line 124 of file nRF_API.h.

#define RX_PW_P2   0x13

Definition at line 125 of file nRF_API.h.

#define RX_PW_P3   0x14

Definition at line 126 of file nRF_API.h.

#define RX_PW_P4   0x15

Definition at line 127 of file nRF_API.h.

#define RX_PW_P5   0x16

Definition at line 128 of file nRF_API.h.

#define FIFO_STATUS   0x17

Definition at line 129 of file nRF_API.h.

#define NRF_RX_DR   6

Definition at line 132 of file nRF_API.h.

#define NRF_TX_DR   5

Definition at line 133 of file nRF_API.h.

#define NRF_MAX_RT   4

Definition at line 134 of file nRF_API.h.

#define NFR_read_reg ( reg   )     (NRF_Read(reg|READ_REG))

Definition at line 140 of file nRF_API.h.

#define NFR_write_reg ( reg,
val   )     (NRF_RW_Reg(reg|WRITE_REG,val))

Definition at line 141 of file nRF_API.h.

 
#define NRF_init_tx (  )     (NRF_disable(),NFR_write_reg(CONFIG,0x0A))

Definition at line 143 of file nRF_API.h.

Referenced by cdc_rf_task().

 
#define NRF_init_rx (  )     (NRF_disable(),NFR_write_reg(CONFIG,0x0B),NRF_enable())

Definition at line 144 of file nRF_API.h.

Referenced by cdc_rf_task(), and cdc_rf_task_init().

 
#define Is_not_NRF_IRQ (  )     ((NRF_IRQ_PORT & (1<<NRF_IRQ_PIN))? TRUE : FALSE)

Definition at line 146 of file nRF_API.h.

Referenced by cdc_rf_task().

 
#define Is_NRF_IRQ (  )     ((NRF_IRQ_PORT & (1<<NRF_IRQ_PIN))? FALSE : TRUE)

Definition at line 147 of file nRF_API.h.

Referenced by cdc_rf_task().

#define NRF_tx_buffer ( buf,
 )     (NRF_write_buf(WR_TX_PLOAD,buf,n))

Definition at line 150 of file nRF_API.h.

Referenced by cdc_rf_task().

#define NRF_rx_buffer ( buf,
 )     (NRF_read_buf(RD_RX_PLOAD,buf,n))

Definition at line 151 of file nRF_API.h.

Referenced by cdc_rf_task().

#define NRF_set_payload ( pipe,
 )     (NFR_write_reg(RX_PW_P##pipe,n))

Definition at line 153 of file nRF_API.h.

Referenced by cdc_rf_task_init().

#define NRF_set_channel (  )     (NFR_write_reg(RF_CH,n))

Definition at line 155 of file nRF_API.h.

#define NRF_set_byte_addr (  )     (NFR_write_reg(SETUP_AW,n-2))

Definition at line 156 of file nRF_API.h.

 
#define NRF_ack_RX_DR (  )     (NFR_write_reg(STATUS,(1<<NRF_RX_DR)))

Definition at line 158 of file nRF_API.h.

 
#define NRF_ack_TX_DR (  )     (NFR_write_reg(STATUS,(1<<NRF_TX_DR)))

Definition at line 159 of file nRF_API.h.

 
#define NRF_ack_MAX_RT (  )     (NFR_write_reg(STATUS,(1<<NRF_MAX_RT)))

Definition at line 160 of file nRF_API.h.

 
#define NRF_ack_received (  )     (NRF_ack_RX_DR())

Definition at line 161 of file nRF_API.h.

Referenced by cdc_rf_task().

 
#define NRF_ack_transmit (  )     (NRF_ack_TX_DR())

Definition at line 162 of file nRF_API.h.

Referenced by cdc_rf_task().

 
#define NRF_ack_timeout (  )     (NRF_ack_MAX_RT())

Definition at line 163 of file nRF_API.h.

Referenced by cdc_rf_task().

 
#define NRF_flush_rx (  )     (NFR_write_reg(FLUSH_RX,0))

Definition at line 165 of file nRF_API.h.

 
#define Is_NRF_RX_DR (  )     (NFR_read_reg(STATUS)&(1<<NRF_RX_DR) ? TRUE : FALSE)

Definition at line 167 of file nRF_API.h.

 
#define Is_NRF_TX_DR (  )     (NFR_read_reg(STATUS)&(1<<NRF_TX_DR) ? TRUE : FALSE)

Definition at line 168 of file nRF_API.h.

 
#define Is_NRF_MAX_RT (  )     (NFR_read_reg(STATUS)&(1<<NRF_MAX_RT) ? TRUE : FALSE)

Definition at line 169 of file nRF_API.h.

 
#define Is_NRF_received (  )     (Is_NRF_RX_DR())

Definition at line 171 of file nRF_API.h.

Referenced by cdc_rf_task().

 
#define Is_NRF_transmit (  )     (Is_NRF_TX_DR())

Definition at line 172 of file nRF_API.h.

Referenced by cdc_rf_task().

 
#define Is_NRF_timeout (  )     (Is_NRF_MAX_RT())

Definition at line 173 of file nRF_API.h.

Referenced by cdc_rf_task().

#define NRF_Write_addr ( reg,
buf,
 )     NRF_write_buf(reg+0x20,buf, n)

Definition at line 175 of file nRF_API.h.


Function Documentation

U8 SPI_RW ( U8  byte  ) 

U8 NRF_Read ( U8  reg  ) 

NRF_ReadRead one byte from nRF24L01 register, 'reg'.

Parameters:
reg,register to read
Returns:
reg_val, register value

Definition at line 57 of file nRF_API.c.

References NRF_select, NRF_unselect, and spi_rw().

00058 {
00059    U8 reg_val;
00060 
00061    NRF_select();
00062    spi_rw(reg);                                    // Select register to read from..
00063    reg_val = spi_rw(0);                            // ..then read registervalue
00064    NRF_unselect();                                 // CSN high, terminate SPI communication
00065    return(reg_val);                                // return register value
00066 }

Here is the call graph for this function:

U8 NRF_RW_Reg ( U8  reg,
U8  value 
)

NRF_RW_RegWrites value 'value' to register 'reg'.

Parameters:
'reg' register to write value 'value' to
Returns:
status byte

Definition at line 78 of file nRF_API.c.

References NRF_select, NRF_unselect, and spi_rw().

00079 {
00080    U8 status;
00081 
00082    NRF_select();           // CSN low, init SPI transaction
00083    status = spi_rw(reg);   // select register
00084    spi_rw(value);          // ..and write value to it..
00085    NRF_unselect();         // CSN high again
00086    return(status);         // return nRF24L01 status byte
00087 }

Here is the call graph for this function:

U8 NRF_read_buf ( U8  reg,
U8 pBuf,
U8  bytes 
)

NRF_read_bufReads 'bytes' of bytes from register 'reg', typically used to read RX payload, Rx/Tx address.

Parameters:
'register 'reg' to read,
buffer '*pBuf*' contains data to be stored
bytes,: number of data byte to write
Returns:
nRF24L01 status byte

Definition at line 128 of file nRF_API.c.

References NRF_select, NRF_unselect, and spi_rw().

00129 {
00130    U8 status,byte_ctr;
00131 
00132    NRF_select();                                     // Set CSN low, init SPI tranaction
00133    status = spi_rw(reg);                           // Select register to write to and read status byte
00134 
00135    for(byte_ctr=0;byte_ctr<bytes;byte_ctr++)
00136     pBuf[byte_ctr] = spi_rw(0);                   // Perform SPI_RW to read byte from nRF24L01
00137 
00138    NRF_unselect();                                     // Set CSN high again
00139 
00140    return(status);                                 // return nRF24L01 status byte
00141 }

Here is the call graph for this function:

U8 NRF_write_buf ( U8  reg,
U8 pBuf,
U8  bytes 
)

NRF_write_bufWrites contents of buffer '*pBuf' to nRF24L01, typically used to write TX payload, Rx/Tx address.

Parameters:
'register 'reg' to write,
buffer '*pBuf*' contains data to be written
bytes,: number of data byte to write
Returns:
nRF24L01 status byte

FIXE ME !!!!!! 10µs CE pulse required

Definition at line 101 of file nRF_API.c.

References FOSC, NRF_disable, NRF_enable, NRF_select, NRF_unselect, and spi_rw().

00102 {
00103    U8 status,byte_ctr;
00104    volatile U32 tempo;
00105 
00106    NRF_select();                                   // Set CSN low, init SPI tranaction
00107    status = spi_rw(reg);                           // Select register to write to and read status byte
00108    for(byte_ctr=0; byte_ctr<bytes; byte_ctr++)     // then write all byte in buffer(*pBuf)
00109    spi_rw(*pBuf++);
00110    NRF_unselect();                                 // Set CSN high again
00111    NRF_enable();
00112    for(tempo=0;tempo<FOSC/100;tempo++);     
00113    NRF_disable();
00114    return(status);                                 // return nRF24L01 status byte
00115 }

Here is the call graph for this function:


Generated on Mon May 5 15:58:04 2008 for ATMEL by  doxygen 1.5.1-p1