Skip to content

mokhwasomssi/stm32_hal_nrf24l01p

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

stm32_hal_nrf24l01p

Brief

nRF24L01+ is a single chip 2.4GHz transceiver.
TAG - nRF24L01+ SPI STM32 HAL

Library Features

  • 1:1 transaction
  • Static payload lengths (1 - 32bytes)
  • Use IRQ Pin

Dev Environment

STM32CubeMX

  • Project Manager image

  • SPI image

  • CSN, CE (GPIO_OUTPUT) image

    image

  • IRQ (GPIO_EXIT) image

    image

Example

nrf24l01p.h

  • 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

main.c

  • Only contain relative things

Transmitter

#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
}

Receiver

#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
}

Releases

No releases published

Packages

No packages published