nRF24L01+ is a single chip 2.4GHz transceiver.
TAG - nRF24L01+
SPI
STM32 HAL
- 1:1 transaction
- Static payload lengths (1 - 32bytes)
- Use IRQ Pin
- STM32CubeIDE
- STM32 HAL driver
- STM32F411
- nRF24L01+ Module (NRF24L01+PA+LNA 2.4GHz Wireless RF Transceiver Module)
- SPI2, PB13 (CSN), PB12 (CE), PA8 (IRQ), Payload length 8
/* 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
- Only contain relative things
#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
}