NRF24L+ STM8 Compatible Library
|
This file contains the NRF24 library headers. More...
#include "stm8s.h"
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... | |
This file contains the NRF24 library headers.
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.
#define ARC 0 |
#define ARC_CNT 0 |
#define ARD 4 |
#define AW 0 |
#define CD 0x09 |
#define CONFIG 0x00 |
#define CRCO 2 |
#define DYNPD 0x1C |
#define EN_AA 0x01 |
#define EN_CRC 3 |
#define EN_RXADDR 0x02 |
#define ENAA_P0 0 |
#define ENAA_P1 1 |
#define ENAA_P2 2 |
#define ENAA_P3 3 |
#define ENAA_P4 4 |
#define ENAA_P5 5 |
#define ERX_P0 0 |
#define ERX_P1 1 |
#define ERX_P2 2 |
#define ERX_P3 3 |
#define ERX_P4 4 |
#define ERX_P5 5 |
#define FEATURE 0x1D |
#define FIFO_FULL 5 |
#define FIFO_STATUS 0x17 |
#define FLUSH_RX 0xE2 |
#define FLUSH_TX 0xE1 |
#define LNA_HCURR 0 |
#define LNA_HCURR 0 |
#define MASK_MAX_RT 4 |
#define MASK_RX_DR 6 |
#define MASK_TX_DS 5 |
#define MAX_RT 4 |
#define mirf_ADDR_LEN 5 |
#define mirf_CONFIG ((1 << MASK_TX_DS) | (1 << EN_CRC) | (0 << CRCO)) |
#define NOP 0xFF |
#define OBSERVE_TX 0x08 |
#define PLL_LOCK 4 |
#define PLOS_CNT 4 |
#define PRIM_RX 0 |
#define PWR_UP 1 |
#define R_REGISTER 0x00 |
#define R_RX_PAYLOAD 0x61 |
#define REGISTER_MASK 0x1F |
#define REUSE_TX_PL 0xE3 |
#define RF_CH 0x05 |
#define RF_DR_HIGH 3 |
#define RF_DR_HIGH 3 |
#define RF_DR_LOW 5 |
#define RF_DR_LOW 5 |
#define RF_PWR 1 |
#define RF_PWR_HIGH 2 |
#define RF_PWR_LOW 1 |
#define RF_SETUP 0x06 |
#define RPD 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 RX_DR 6 |
#define RX_EMPTY 0 |
#define RX_FULL 1 |
#define RX_P_NO 1 |
#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 SETUP_AW 0x03 |
#define SETUP_RETR 0x04 |
#define STATUS 0x07 |
#define TX_ADDR 0x10 |
#define TX_DS 5 |
#define TX_EMPTY 4 |
#define TX_FULL 0 |
#define TX_REUSE 6 |
#define W_REGISTER 0x20 |
#define W_TX_PAYLOAD 0xA0 |
#define W_TX_PAYLOAD_NO_ACK 0xB0 |
enum rf24_crclength_e |
enum rf24_datarate_e |
enum rf24_pa_dbm_e |
void Nrf24_addRADDR | ( | uint8_t | pipe, |
uint8_t | adr | ||
) |
Add more device addresses to recieve (NOT TESTED).
pipe | Selected pipe (2-5). |
adr | The reciving address. |
void Nrf24_ceHi | ( | ) |
Set CE High.
void Nrf24_ceLow | ( | ) |
Set CE Low.
void Nrf24_config | ( | bool * | PTX | ) |
This sends the necessary registers to the NRF. Initially on RX mode.
PTX | A pointer to a boolean that stores the state of the NRF (TRUE == TX). |
void Nrf24_configRegister | ( | uint8_t | reg, |
uint8_t | value | ||
) |
Clocks only one byte into the given MiRF register.
reg | Register to change |
value | Value to set |
bool Nrf24_dataReady | ( | ) |
Checks if data is available for reading.
void Nrf24_flushRx | ( | ) |
Flushes RX FIFO.
void Nrf24_getData | ( | uint8_t * | data | ) |
Reads NRF payload bytes into data array.
data | An array to store the data based on NRF_PAYLOAD_SIZE |
uint8_t Nrf24_getDataPipe | ( | ) |
Get pipe number for reading.
uint8_t Nrf24_getStatus | ( | ) |
Get the status of the NRF.
void Nrf24_init | ( | ) |
This function initializes the CE/CS Pins and SPI.
bool Nrf24_isSend | ( | int | timeout, |
bool * | PTX | ||
) |
Test if Sending has finished or retry is over.
timeout | How long to timeout in ms |
PTX | The boolean holding the RX/TX state of the NRF |
bool Nrf24_isSending | ( | bool * | PTX | ) |
Test if chip is still sending. When sending has finished return chip to listening.
PTX | The boolean holding the RX/TX state of the NRF |
void Nrf24_powerDown | ( | ) |
Power down the NRF.
void Nrf24_powerUpRx | ( | bool * | PTX | ) |
Starts up the NRF to be RX, the default.
PTX | The boolean holding the RX/TX state of the NRF |
void Nrf24_powerUpTx | ( | bool * | PTX | ) |
Sets the NRF to TX mode.
PTX | The boolean holding the RX/TX state of the NRF |
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.
reg | The register to read |
value | The array to store the value |
len | The length of the register |
bool Nrf24_rxFifoEmpty | ( | ) |
Checks if FIFO is empty.
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.
value | The value to send, length based on NRF_PAYLOAD_SIZE |
PTX | A bool containing the RX/TX state of the NRF |
void Nrf24_SetOutputRF_PWR | ( | uint8_t | val | ) |
Set TX Power.
val | 0=-18dBm,1=-12dBm,2=-6dBm,3=0dBm |
ErrorStatus Nrf24_setRADDR | ( | uint8_t * | adr | ) |
Sets the recieving address (5) bytes!
adr | Pointer to the address. |
void Nrf24_setRetransmitDelay | ( | uint8_t | val | ) |
Set Auto Retransmit Delay.
val | 0=250us, 1=500us, ... 15=4000us |
void Nrf24_SetSpeedDataRates | ( | uint8_t | val | ) |
Select between the high speed data rates.
val | 0=1Mbps (Recommended), 1=2Mbps, 2=250Kbps |
ErrorStatus Nrf24_setTADDR | ( | uint8_t * | adr | ) |
Sets the transmitting device address.
adr | The address (5 Byte) to write. |
bool Nrf24_txFifoEmpty | ( | ) |
void Nrf24_writeRegister | ( | uint8_t | reg, |
uint8_t * | value, | ||
uint8_t | len | ||
) |
Writes an array of bytes into inte the MiRF registers.
reg | Register to write |
value | Array containing the value to store |
len | Length of the register |
void spi_csnHi | ( | ) |
Set CSN High.
void spi_csnLow | ( | ) |
Set CSN Low.
bool spi_read_byte | ( | uint8_t * | Datain, |
uint8_t | DataLength | ||
) |
Reads data from MISO.
Datain | The uint8_t to be written to. |
DataLength | The length of the data |
uint8_t spi_transfer | ( | uint8_t | address | ) |
An SPI "transfer", used in this library to simply send an address or command to the NRF.
address | The byte to be sent. |
bool spi_write_byte | ( | uint8_t * | Dataout, |
uint8_t | DataLength | ||
) |
This function writes data to MOSI. It checks if it is being used.
Dataout | A uint8_t Array |
DataLength | The length of the Array |