NRF24L+ STM8 Compatible Library
Macros | Enumerations | Functions
mirf.h File Reference

This file contains the NRF24 library headers. More...

#include "stm8s.h"
Include dependency graph for mirf.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#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 DYNPD   0x1C
 
#define FEATURE   0x1D
 
#define MASK_RX_DR   6
 
#define MASK_TX_DS   5
 
#define MASK_MAX_RT   4
 
#define EN_CRC   3
 
#define CRCO   2
 
#define PWR_UP   1
 
#define PRIM_RX   0
 
#define ENAA_P5   5
 
#define ENAA_P4   4
 
#define ENAA_P3   3
 
#define ENAA_P2   2
 
#define ENAA_P1   1
 
#define ENAA_P0   0
 
#define ERX_P5   5
 
#define ERX_P4   4
 
#define ERX_P3   3
 
#define ERX_P2   2
 
#define ERX_P1   1
 
#define ERX_P0   0
 
#define AW   0
 
#define ARD   4
 
#define ARC   0
 
#define RF_DR_LOW   5
 
#define PLL_LOCK   4
 
#define RF_DR_HIGH   3
 
#define RF_PWR   1
 
#define LNA_HCURR   0
 
#define RX_DR   6
 
#define TX_DS   5
 
#define MAX_RT   4
 
#define RX_P_NO   1
 
#define TX_FULL   0
 
#define PLOS_CNT   4
 
#define ARC_CNT   0
 
#define TX_REUSE   6
 
#define FIFO_FULL   5
 
#define TX_EMPTY   4
 
#define RX_FULL   1
 
#define RX_EMPTY   0
 
#define R_REGISTER   0x00
 
#define W_REGISTER   0x20
 
#define REGISTER_MASK   0x1F
 
#define R_RX_PAYLOAD   0x61
 
#define W_TX_PAYLOAD   0xA0
 
#define FLUSH_TX   0xE1
 
#define FLUSH_RX   0xE2
 
#define REUSE_TX_PL   0xE3
 
#define NOP   0xFF
 
#define LNA_HCURR   0
 
#define RPD   0x09
 
#define W_TX_PAYLOAD_NO_ACK   0xB0
 
#define RF_DR_LOW   5
 
#define RF_DR_HIGH   3
 
#define RF_PWR_LOW   1
 
#define RF_PWR_HIGH   2
 
#define mirf_ADDR_LEN   5
 
#define mirf_CONFIG   ((1 << MASK_TX_DS) | (1 << EN_CRC) | (0 << CRCO))
 

Enumerations

enum  rf24_pa_dbm_e {
  RF24_PA_MIN = 0 , RF24_PA_LOW , RF24_PA_HIGH , RF24_PA_MAX ,
  RF24_PA_ERROR
}
 
enum  rf24_datarate_e { RF24_1MBPS = 0 , RF24_2MBPS , RF24_250KBPS }
 
enum  rf24_crclength_e { RF24_CRC_DISABLED = 0 , RF24_CRC_8 , RF24_CRC_16 }
 

Functions

void Nrf24_init ()
 This function initializes the CE/CS Pins and SPI. More...
 
bool spi_write_byte (uint8_t *Dataout, uint8_t DataLength)
 This function writes data to MOSI. It checks if it is being used. More...
 
bool spi_read_byte (uint8_t *Datain, uint8_t DataLength)
 Reads data from MISO. More...
 
uint8_t spi_transfer (uint8_t address)
 An SPI "transfer", used in this library to simply send an address or command to the NRF. More...
 
void spi_csnLow ()
 Set CSN Low. More...
 
void spi_csnHi ()
 Set CSN High. More...
 
void Nrf24_config (bool *PTX)
 This sends the necessary registers to the NRF. Initially on RX mode. More...
 
ErrorStatus Nrf24_setRADDR (uint8_t *adr)
 Sets the recieving address (5) bytes! More...
 
ErrorStatus Nrf24_setTADDR (uint8_t *adr)
 Sets the transmitting device address. More...
 
void Nrf24_addRADDR (uint8_t pipe, uint8_t adr)
 Add more device addresses to recieve (NOT TESTED). More...
 
bool Nrf24_dataReady ()
 Checks if data is available for reading. More...
 
uint8_t Nrf24_getDataPipe ()
 Get pipe number for reading. More...
 
bool Nrf24_isSend (int timeout, bool *PTX)
 Test if Sending has finished or retry is over. More...
 
bool Nrf24_isSending (bool *PTX)
 Test if chip is still sending. When sending has finished return chip to listening. More...
 
void Nrf24_send (uint8_t *value, bool *PTX)
 Sends a data package to the default address. Be sure to send the correct amount of bytes as configured as payload on the receiver. More...
 
bool Nrf24_rxFifoEmpty ()
 Checks if FIFO is empty. More...
 
bool Nrf24_txFifoEmpty ()
 
void Nrf24_getData (uint8_t *data)
 Reads NRF payload bytes into data array. More...
 
uint8_t Nrf24_getStatus ()
 Get the status of the NRF. More...
 
void Nrf24_configRegister (uint8_t reg, uint8_t value)
 Clocks only one byte into the given MiRF register. More...
 
void Nrf24_readRegister (uint8_t reg, uint8_t *value, uint8_t len)
 Reads an array of bytes from the given start position in the MiRF registers. More...
 
void Nrf24_writeRegister (uint8_t reg, uint8_t *value, uint8_t len)
 Writes an array of bytes into inte the MiRF registers. More...
 
void Nrf24_powerUpRx (bool *PTX)
 Starts up the NRF to be RX, the default. More...
 
void Nrf24_powerUpTx (bool *PTX)
 Sets the NRF to TX mode. More...
 
void Nrf24_powerDown ()
 Power down the NRF. More...
 
void Nrf24_SetOutputRF_PWR (uint8_t val)
 Set TX Power. More...
 
void Nrf24_SetSpeedDataRates (uint8_t val)
 Select between the high speed data rates. More...
 
void Nrf24_setRetransmitDelay (uint8_t val)
 Set Auto Retransmit Delay. More...
 
void Nrf24_ceHi ()
 Set CE High. More...
 
void Nrf24_ceLow ()
 Set CE Low. More...
 
void Nrf24_flushRx ()
 Flushes RX FIFO. More...
 

Detailed Description

This file contains the NRF24 library headers.

Author
nopnop2002, nicogutz
Version
V1
Date
9-December-2023

MIT License Copyright (c) 2020 nopnop2002 Copyright (c) 2023 nicogutz

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Macro Definition Documentation

◆ ARC

#define ARC   0

◆ ARC_CNT

#define ARC_CNT   0

◆ ARD

#define ARD   4

◆ AW

#define AW   0

◆ CD

#define CD   0x09

◆ CONFIG

#define CONFIG   0x00

◆ CRCO

#define CRCO   2

◆ DYNPD

#define DYNPD   0x1C

◆ EN_AA

#define EN_AA   0x01

◆ EN_CRC

#define EN_CRC   3

◆ EN_RXADDR

#define EN_RXADDR   0x02

◆ ENAA_P0

#define ENAA_P0   0

◆ ENAA_P1

#define ENAA_P1   1

◆ ENAA_P2

#define ENAA_P2   2

◆ ENAA_P3

#define ENAA_P3   3

◆ ENAA_P4

#define ENAA_P4   4

◆ ENAA_P5

#define ENAA_P5   5

◆ ERX_P0

#define ERX_P0   0

◆ ERX_P1

#define ERX_P1   1

◆ ERX_P2

#define ERX_P2   2

◆ ERX_P3

#define ERX_P3   3

◆ ERX_P4

#define ERX_P4   4

◆ ERX_P5

#define ERX_P5   5

◆ FEATURE

#define FEATURE   0x1D

◆ FIFO_FULL

#define FIFO_FULL   5

◆ FIFO_STATUS

#define FIFO_STATUS   0x17

◆ FLUSH_RX

#define FLUSH_RX   0xE2

◆ FLUSH_TX

#define FLUSH_TX   0xE1

◆ LNA_HCURR [1/2]

#define LNA_HCURR   0

◆ LNA_HCURR [2/2]

#define LNA_HCURR   0

◆ MASK_MAX_RT

#define MASK_MAX_RT   4

◆ MASK_RX_DR

#define MASK_RX_DR   6

◆ MASK_TX_DS

#define MASK_TX_DS   5

◆ MAX_RT

#define MAX_RT   4

◆ mirf_ADDR_LEN

#define mirf_ADDR_LEN   5

◆ mirf_CONFIG

#define mirf_CONFIG   ((1 << MASK_TX_DS) | (1 << EN_CRC) | (0 << CRCO))

◆ NOP

#define NOP   0xFF

◆ OBSERVE_TX

#define OBSERVE_TX   0x08

◆ PLL_LOCK

#define PLL_LOCK   4

◆ PLOS_CNT

#define PLOS_CNT   4

◆ PRIM_RX

#define PRIM_RX   0

◆ PWR_UP

#define PWR_UP   1

◆ R_REGISTER

#define R_REGISTER   0x00

◆ R_RX_PAYLOAD

#define R_RX_PAYLOAD   0x61

◆ REGISTER_MASK

#define REGISTER_MASK   0x1F

◆ REUSE_TX_PL

#define REUSE_TX_PL   0xE3

◆ RF_CH

#define RF_CH   0x05

◆ RF_DR_HIGH [1/2]

#define RF_DR_HIGH   3

◆ RF_DR_HIGH [2/2]

#define RF_DR_HIGH   3

◆ RF_DR_LOW [1/2]

#define RF_DR_LOW   5

◆ RF_DR_LOW [2/2]

#define RF_DR_LOW   5

◆ RF_PWR

#define RF_PWR   1

◆ RF_PWR_HIGH

#define RF_PWR_HIGH   2

◆ RF_PWR_LOW

#define RF_PWR_LOW   1

◆ RF_SETUP

#define RF_SETUP   0x06

◆ RPD

#define RPD   0x09

◆ RX_ADDR_P0

#define RX_ADDR_P0   0x0A

◆ RX_ADDR_P1

#define RX_ADDR_P1   0x0B

◆ RX_ADDR_P2

#define RX_ADDR_P2   0x0C

◆ RX_ADDR_P3

#define RX_ADDR_P3   0x0D

◆ RX_ADDR_P4

#define RX_ADDR_P4   0x0E

◆ RX_ADDR_P5

#define RX_ADDR_P5   0x0F

◆ RX_DR

#define RX_DR   6

◆ RX_EMPTY

#define RX_EMPTY   0

◆ RX_FULL

#define RX_FULL   1

◆ RX_P_NO

#define RX_P_NO   1

◆ RX_PW_P0

#define RX_PW_P0   0x11

◆ RX_PW_P1

#define RX_PW_P1   0x12

◆ RX_PW_P2

#define RX_PW_P2   0x13

◆ RX_PW_P3

#define RX_PW_P3   0x14

◆ RX_PW_P4

#define RX_PW_P4   0x15

◆ RX_PW_P5

#define RX_PW_P5   0x16

◆ SETUP_AW

#define SETUP_AW   0x03

◆ SETUP_RETR

#define SETUP_RETR   0x04

◆ STATUS

#define STATUS   0x07

◆ TX_ADDR

#define TX_ADDR   0x10

◆ TX_DS

#define TX_DS   5

◆ TX_EMPTY

#define TX_EMPTY   4

◆ TX_FULL

#define TX_FULL   0

◆ TX_REUSE

#define TX_REUSE   6

◆ W_REGISTER

#define W_REGISTER   0x20

◆ W_TX_PAYLOAD

#define W_TX_PAYLOAD   0xA0

◆ W_TX_PAYLOAD_NO_ACK

#define W_TX_PAYLOAD_NO_ACK   0xB0

Enumeration Type Documentation

◆ rf24_crclength_e

CRC Length. How big (if any) of a CRC is included.

For use with setCRCLength()

Enumerator
RF24_CRC_DISABLED 
RF24_CRC_8 
RF24_CRC_16 

◆ rf24_datarate_e

Data rate. How fast data moves through the air.

For use with setDataRate()

Enumerator
RF24_1MBPS 
RF24_2MBPS 
RF24_250KBPS 

◆ rf24_pa_dbm_e

Power Amplifier level.

For use with setPALevel()

Enumerator
RF24_PA_MIN 
RF24_PA_LOW 
RF24_PA_HIGH 
RF24_PA_MAX 
RF24_PA_ERROR 

Function Documentation

◆ Nrf24_addRADDR()

void Nrf24_addRADDR ( uint8_t  pipe,
uint8_t  adr 
)

Add more device addresses to recieve (NOT TESTED).

Parameters
pipeSelected pipe (2-5).
adrThe reciving address.
Here is the call graph for this function:

◆ Nrf24_ceHi()

void Nrf24_ceHi ( )

Set CE High.

Here is the caller graph for this function:

◆ Nrf24_ceLow()

void Nrf24_ceLow ( )

Set CE Low.

Here is the caller graph for this function:

◆ Nrf24_config()

void Nrf24_config ( bool *  PTX)

This sends the necessary registers to the NRF. Initially on RX mode.

Parameters
PTXA pointer to a boolean that stores the state of the NRF (TRUE == TX).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Nrf24_configRegister()

void Nrf24_configRegister ( uint8_t  reg,
uint8_t  value 
)

Clocks only one byte into the given MiRF register.

Parameters
regRegister to change
valueValue to set
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Nrf24_dataReady()

bool Nrf24_dataReady ( )

Checks if data is available for reading.

Returns
TRUE if ready
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Nrf24_flushRx()

void Nrf24_flushRx ( )

Flushes RX FIFO.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Nrf24_getData()

void Nrf24_getData ( uint8_t *  data)

Reads NRF payload bytes into data array.

Parameters
dataAn array to store the data based on NRF_PAYLOAD_SIZE
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Nrf24_getDataPipe()

uint8_t Nrf24_getDataPipe ( )

Get pipe number for reading.

Returns
The pipe number
Here is the call graph for this function:

◆ Nrf24_getStatus()

uint8_t Nrf24_getStatus ( )

Get the status of the NRF.

Returns
STATUS register value
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Nrf24_init()

void Nrf24_init ( )

This function initializes the CE/CS Pins and SPI.

Here is the caller graph for this function:

◆ Nrf24_isSend()

bool Nrf24_isSend ( int  timeout,
bool *  PTX 
)

Test if Sending has finished or retry is over.

Parameters
timeoutHow long to timeout in ms
PTXThe boolean holding the RX/TX state of the NRF
Returns
When sending has finished return TRUE When maximum number of TX retries return FALSE
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Nrf24_isSending()

bool Nrf24_isSending ( bool *  PTX)

Test if chip is still sending. When sending has finished return chip to listening.

Parameters
PTXThe boolean holding the RX/TX state of the NRF
Returns
TRUE if is sending
Here is the call graph for this function:

◆ Nrf24_powerDown()

void Nrf24_powerDown ( )

Power down the NRF.

Here is the call graph for this function:

◆ Nrf24_powerUpRx()

void Nrf24_powerUpRx ( bool *  PTX)

Starts up the NRF to be RX, the default.

Parameters
PTXThe boolean holding the RX/TX state of the NRF
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Nrf24_powerUpTx()

void Nrf24_powerUpTx ( bool *  PTX)

Sets the NRF to TX mode.

Parameters
PTXThe boolean holding the RX/TX state of the NRF
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Nrf24_readRegister()

void Nrf24_readRegister ( uint8_t  reg,
uint8_t *  value,
uint8_t  len 
)

Reads an array of bytes from the given start position in the MiRF registers.

Parameters
regThe register to read
valueThe array to store the value
lenThe length of the register
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Nrf24_rxFifoEmpty()

bool Nrf24_rxFifoEmpty ( )

Checks if FIFO is empty.

Returns
True if empty
Here is the call graph for this function:

◆ Nrf24_send()

void Nrf24_send ( uint8_t *  value,
bool *  PTX 
)

Sends a data package to the default address. Be sure to send the correct amount of bytes as configured as payload on the receiver.

Parameters
valueThe value to send, length based on NRF_PAYLOAD_SIZE
PTXA bool containing the RX/TX state of the NRF
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Nrf24_SetOutputRF_PWR()

void Nrf24_SetOutputRF_PWR ( uint8_t  val)

Set TX Power.

Parameters
val0=-18dBm,1=-12dBm,2=-6dBm,3=0dBm
Here is the call graph for this function:

◆ Nrf24_setRADDR()

ErrorStatus Nrf24_setRADDR ( uint8_t *  adr)

Sets the recieving address (5) bytes!

Parameters
adrPointer to the address.
Returns
SUCCESS if it worked.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Nrf24_setRetransmitDelay()

void Nrf24_setRetransmitDelay ( uint8_t  val)

Set Auto Retransmit Delay.

Parameters
val0=250us, 1=500us, ... 15=4000us
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Nrf24_SetSpeedDataRates()

void Nrf24_SetSpeedDataRates ( uint8_t  val)

Select between the high speed data rates.

Parameters
val0=1Mbps (Recommended), 1=2Mbps, 2=250Kbps
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Nrf24_setTADDR()

ErrorStatus Nrf24_setTADDR ( uint8_t *  adr)

Sets the transmitting device address.

Parameters
adrThe address (5 Byte) to write.
Returns
SUCESS if it worked.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Nrf24_txFifoEmpty()

bool Nrf24_txFifoEmpty ( )

◆ Nrf24_writeRegister()

void Nrf24_writeRegister ( uint8_t  reg,
uint8_t *  value,
uint8_t  len 
)

Writes an array of bytes into inte the MiRF registers.

Parameters
regRegister to write
valueArray containing the value to store
lenLength of the register
Here is the call graph for this function:
Here is the caller graph for this function:

◆ spi_csnHi()

void spi_csnHi ( )

Set CSN High.

Here is the caller graph for this function:

◆ spi_csnLow()

void spi_csnLow ( )

Set CSN Low.

Here is the caller graph for this function:

◆ spi_read_byte()

bool spi_read_byte ( uint8_t *  Datain,
uint8_t  DataLength 
)

Reads data from MISO.

Parameters
DatainThe uint8_t to be written to.
DataLengthThe length of the data
Returns
TRUE if successful.
Here is the caller graph for this function:

◆ spi_transfer()

uint8_t spi_transfer ( uint8_t  address)

An SPI "transfer", used in this library to simply send an address or command to the NRF.

Parameters
addressThe byte to be sent.
Returns
The data recieved (not actually used anywhere).
Here is the caller graph for this function:

◆ spi_write_byte()

bool spi_write_byte ( uint8_t *  Dataout,
uint8_t  DataLength 
)

This function writes data to MOSI. It checks if it is being used.

Parameters
DataoutA uint8_t Array
DataLengthThe length of the Array
Returns
TRUE if it worked
Here is the caller graph for this function: