3.4.8. nrf24l01 — Wireless communication

NRF24L01 is a wireless communication module.

../../../_images/sku_149483_2.jpg

Source code: src/drivers/network/nrf24l01.h, src/drivers/network/nrf24l01.c


Functions

int nrf24l01_module_init(void)

Initialize NRF24L01 module. This function must be called before calling any other function in this module.

The module will only be initialized once even if this function is called multiple times.

Return
zero(0) or negative error code.

int nrf24l01_init(struct nrf24l01_driver_t *self_p, struct spi_device_t *spi_p, struct pin_device_t *cs_p, struct pin_device_t *ce_p, struct exti_device_t *exti_p, uint32_t address)

Initialize given driver object from given configuration.

Return
zero(0) or negative error code.
Parameters
  • self_p: Driver object to be initialized.
  • spi_p: SPI device.
  • cs_p: Chip select pin device.
  • ce_p: CE pin device.
  • exti_p: External interrupt flagdevice.
  • address: 4 MSB:s of RX pipes. LSB is set to 0 through 5 for the 6 pipes.

int nrf24l01_start(struct nrf24l01_driver_t *self_p)

Starts the NRF24L01 device using given driver object.

Return
zero(0) or negative error code.
Parameters
  • self_p: Initialized driver object.

int nrf24l01_stop(struct nrf24l01_driver_t *self_p)

Stops the NRF24L01 device referenced by driver object.

Return
zero(0) or negative error code.
Parameters
  • self_p: Initialized driver object.

ssize_t nrf24l01_read(struct nrf24l01_driver_t *self_p, void *buf_p, size_t size)

Read data from the NRF24L01 device.

Return
Number of received bytes or negative error code.
Parameters
  • self_p: Initialized driver object.
  • buf_p: Buffer to read into.
  • size: Number of bytes to read (must be 32).

ssize_t nrf24l01_write(struct nrf24l01_driver_t *self_p, uint32_t address, uint8_t pipe, const void *buf_p, size_t size)

Write data to the NRF24L01 device.

Return
number of sent bytes or negative error code.
Parameters
  • self_p: Initialized driver object.
  • address: 4 MSB:s of TX address.
  • pipe: LSB of TX address.
  • buf_p: Buffer to write.
  • size: Number of bytes to write (must be 32).

struct nrf24l01_driver_t

Public Members

struct spi_driver_t spi
struct exti_driver_t exti
struct pin_driver_t ce
struct queue_t irqchan
struct queue_t chin
struct thrd_t *thrd_p
uint32_t address
char irqbuf[8]
char chinbuf[32]
char stack[256]