=====================================================================================
This library provides functions to interface the NRF24L01+ transceiver module using STM32 HAL (Hardware Abstraction Layer). It supports features such as dynamic payload length (DPL), automatic acknowledgment (ACK), and various data rates.
-
Dynamic Payload Length (DPL)
-
Automatic Acknowledgment (ACK)
-
Configurable Data Rates (250 kbps, 1 Mbps, 2 Mbps)
-
CRC Configuration (1-byte or 2-byte)
-
RF signal power control (n18dbm, n12dbm, n6dbm, _0dbm)
-
RF channel selection
-
Pipes control, such as: address changing, closiing/opening pipes
-
Simple APIs for Transmitting and Receiving Data
-
STM32 microcontroller
-
NRF24L01+ transceiver module
-
STlink programmer
-
STM32CubeIDE
-
STM32CubeMX
-
STM32CubeProgrammer
- VCC to 3.3V
- GND to GND
- CE to GPIO_PIN_x (Configurable)
- CSN to GPIO_PIN_x (Configurable)
- SCK to SPI_SCK_PIN
- MOSI to SPI_MOSI_PIN
- MISO to SPI_MISO_PIN
- IRQ (optional) to GPIO_PIN_x (Configurable)
Open NRF24_conf.h and select SPI port, CE and CS GPIO pins and CS and CE pins relevant GPIO ports.
csn_high();
HAL_Delay(5);
ce_low();
nrf24_init();
nrf24_auto_ack_all(auto_ack);
nrf24_en_ack_pld(disable);
nrf24_en_dyn_ack(disable);
nrf24_dpl(disable);
nrf24_set_crc(no_crc, _1byte);
nrf24_tx_pwr(_0dbm);
nrf24_data_rate(_250kbps);
nrf24_set_channel(74);
nrf24_set_addr_width(5);
nrf24_set_rx_dpl(0, disable);
nrf24_set_rx_dpl(1, disable);
nrf24_set_rx_dpl(2, disable);
nrf24_set_rx_dpl(3, disable);
nrf24_set_rx_dpl(4, disable);
nrf24_set_rx_dpl(5, disable);
nrf24_pipe_pld_size(0, PLD_S);
nrf24_auto_retr_delay(0);
nrf24_auto_retr_limit(15);
uint8_t addr[5] = { 0x53, 0x13, 0x01, 0x75, 0x82 };
nrf24_open_tx_pipe(addr);
nrf24_open_rx_pipe(0, addr);
ce_high();
If you want to return register in it's own default value commenting function, with which set value, and after compiling code does not solves this problem because nrf24 memorises most of register configurations even if you power off module. Therefore you must write even default values in this register.
For example if you had enabled crc with "nrf24_set_crc(en_crc, _2byte)" and you want to disable at begining of program you should write new values with "nrf24_set_crc(no_crc, _1byte)" because as i mentioned nrf24 does not returns in default values even after powering off.
nrf24_dpl(enable);
nrf24_set_rx_dpl(pipe, enable);
nrf24_dpl(disable);
nrf24_set_rx_dpl(pipe, disable);
nrf24_auto_ack_all(auto_ack);
nrf24_auto_ack_all(no_auto_ack);
nrf24_auto_ack(pipe, auto_ack);
nrf24_auto_ack(pipe, no_auto_ack);
nrf24_auto_retr_delay(0);
nrf24_auto_retr_limit(15);
nrf24_auto_ack_all(auto_ack);
nrf24_en_ack_pld(enable);
nrf24_auto_retr_delay(0);
nrf24_auto_retr_limit(15);
nrf24_auto_ack_all(auto_ack);
nrf24_en_ack_pld(disable);
nrf24_auto_retr_delay(0);
nrf24_auto_retr_limit(15);
nrf24_set_crc(en_crc, _1byte);
//First argument can be set as en_crc, which enables CRC, or no_crc, which disables CRC.
//As second argument can be used _1byte or _2byte.
nrf24_tx_pwr(_0dbm);
//Can be set used:
// n18dbm = 0 -> MIN
// n12dbm = 1
// n6dbm = 2
// _0dbm = 3 -> MAX
nrf24_data_rate(_250kbps);
//Can be set used:
// _1mbps = 0
// _2mbps = 1
// _250kbps = 2
nrf24_set_channel(90);
//Can be used from 0 to 126 which is equivalent of 2400mhz to 2525mhz.
//1 = 1mhz
nrf24_pipe_pld_size(pipe, payload_size);
//pipe can be from 0 to 5
//payload_size can be from 1 to 32
nrf24_auto_retr_delay(0);
//Can be set from 0 to 15.
nrf24_auto_retr_limit(15);
//Can be set from 0 to 15
uint8_t dataT[PLD_SIZE] = {"Hello"};
nrf24_transmit(dataT, sizeof(dataT));
nrf24_auto_ack_all(auto_ack);
nrf24_en_ack_pld(enable);
//and other configurations as well
uint8_t dataT[PLD_SIZE] = {"Hello"};
uint8_t tx_ack_pld[PLD_SIZE];
uint8_t val = nrf24_transmit(dataT, sizeof(dataT));
if(val == 0){
nrf24_receive(tx_ack_pld, sizeof(tx_ack_pld));
}
nrf24_auto_ack_all(auto_ack);
nrf24_en_ack_pld(enable);
nrf24_en_dyn_ack(enable);
//and other configurations as well
uint8_t dataT[PLD_SIZE] = {"Hello"};
nrf24_transmit_no_ack(dataT, sizeof(dataT));
nrf24_transmit(dataT, sizeof(dataT));
if(irq == 1){
uint8_t stat = nrf24_r_status();
if(stat & (1 << TX_DS)){
nrf24_receive(tx_ack_pld, sizeof(tx_ack_pld));
}else if(stat & (1 << MAX_RT)){
nrf24_flush_tx();
nrf24_clear_rx_dr();
}
irq = 0;
}
uint8_t dataR[PLD_SIZE];
nrf24_listen();
if(nrf24_data_available()){
nrf24_receive(dataR, sizeof(dataR));
}
nrf24_auto_ack_all(auto_ack);
nrf24_en_ack_pld(enable);
//and other configurations as well
uint8_t dataR[PLD_SIZE];
uint8_t rx_ack_pld[PLD_SIZE] = {"OK"}
nrf24_listen();
if(nrf24_data_available()){
nrf24_receive(dataR, sizeof(dataR));
nrf24_transmit_rx_ack_pld(0, rx_ack_pld, sizeof(rx_ack_pld));
}
if(irq == 1){
uint8_t stat = nrf24_r_status();
if(stat & (1 << RX_DR)){
nrf24_receive(dataR, sizeof(dataR));
nrf24_transmit_rx_ack_pld(0, rx_ack_pld, sizeof(rx_ack_pld));
}
irq = 0;
}