NRF24L+ STM8 Compatible Library
|
This file contains the NRF24 library ported to the STM8 using SDCC. More...
Macros | |
#define | NRF_CHANNEL_NR 114 |
Channel Number for the NRF, must be the same in all devices. More... | |
#define | NRF_PAYLOAD_SIZE 32 |
Payload size for the NRF, must be the same in all devices. More... | |
#define | CE_PIN_LETTER GPIOC |
Pin letter the NRF CE is connected to. More... | |
#define | CE_PIN_NUMBER GPIO_PIN_4 |
Pin number the NRF CE is connected to. More... | |
#define | CSN_PIN_LETTER GPIOC |
Pin letter the NRF CSN is connected to. More... | |
#define | CSN_PIN_NUMBER GPIO_PIN_3 |
Pin number the NRF CSN is connected to. More... | |
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_csnHi () |
Set CSN High. More... | |
void | spi_csnLow () |
Set CSN Low. 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_rxFifoEmpty () |
Checks if FIFO is empty. More... | |
void | Nrf24_getData (uint8_t *data) |
Reads NRF payload bytes into data array. 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_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_isSending (bool *PTX) |
Test if chip is still sending. When sending has finished return chip to listening. More... | |
bool | Nrf24_isSend (int timeout, bool *PTX) |
Test if Sending has finished or retry is over. More... | |
uint8_t | Nrf24_getStatus () |
Get the status of the NRF. More... | |
void | Nrf24_powerUpRx (bool *PTX) |
Starts up the NRF to be RX, the default. More... | |
void | Nrf24_flushRx () |
Flushes RX FIFO. More... | |
void | Nrf24_powerUpTx (bool *PTX) |
Sets the NRF to TX mode. More... | |
void | Nrf24_ceHi () |
Set CE High. More... | |
void | Nrf24_ceLow () |
Set CE Low. 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... | |
This file contains the NRF24 library ported to the STM8 using SDCC.
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 CE_PIN_LETTER GPIOC |
Pin letter the NRF CE is connected to.
#define CE_PIN_NUMBER GPIO_PIN_4 |
Pin number the NRF CE is connected to.
#define CSN_PIN_LETTER GPIOC |
Pin letter the NRF CSN is connected to.
#define CSN_PIN_NUMBER GPIO_PIN_3 |
Pin number the NRF CSN is connected to.
#define NRF_CHANNEL_NR 114 |
Channel Number for the NRF, must be the same in all devices.
#define NRF_PAYLOAD_SIZE 32 |
Payload size for the NRF, must be the same in all devices.
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. |
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 |