nRF24L01+ is a single chip 2.4GHz transceiver.
TAG - nRF24L01+
SPI
STM32 HAL
nRF24L01+ Module (NRF24L01+PA+LNA 2.4GHz Wireless RF Transceiver Module)
Pinout
Name | Description | |
---|---|---|
VCC, GND | Power Supply, 1.9V - 3.6V | |
MOSI, MISO, SCK, CSN | SPI | |
CE | Chip Enable | |
IRQ | Interrupt Pin, Active Low |
Project Manager
SPI
CSN, CE (GPIO_OUTPUT)
IRQ (GPIO_EXIT)
/* User Configurations */
#define NRF24L01P_SPI (&hspi2)
#define NRF24L01P_SPI_CS_PIN_PORT GPIOB
#define NRF24L01P_SPI_CS_PIN_NUMBER GPIO_PIN_13
#define NRF24L01P_CE_PIN_PORT GPIOB
#define NRF24L01P_CE_PIN_NUMBER GPIO_PIN_12
#define NRF24L01P_IRQ_PIN_PORT GPIOA
#define NRF24L01P_IRQ_PIN_NUMBER GPIO_PIN_8
#define NRF24L01P_PAYLOAD_LENGTH 8 // 1 - 32bytes
#include "nrf24l01p.h"
// data array to be sent
uint8_t tx_data[NRF24L01P_PAYLOAD_LENGTH] = {0, 1, 2, 3, 4, 5, 6, 7};
// for rx interrupt
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin);
int main(void)
{
nrf24l01p_tx_init(2500, _1Mbps);
while (1)
{
// change tx datas
for(int i= 0; i < 8; i++)
tx_data[i]++;
// transmit
nrf24l01p_tx_transmit(tx_data);
HAL_Delay(100);
}
}
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if(GPIO_Pin == NRF24L01P_IRQ_PIN_NUMBER)
nrf24l01p_tx_irq(); // clear interrupt flag
}
#include "nrf24l01p.h"
// data array to be read
uint8_t rx_data[NRF24L01P_PAYLOAD_LENGTH] = { 0, };
// for tx interrupt
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin);
int main(void)
{
nrf24l01p_rx_init(2500, _1Mbps);
while (1)
{
// Nothing to do
HAL_Delay(100);
}
}
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if(GPIO_Pin == NRF24L01P_IRQ_PIN_NUMBER)
nrf24l01p_rx_receive(rx_data); // read data when data ready flag is set
}