nRFBareRadio is a library to use the Radio peripheral in a nRF51 or nRF52 Nordic microcontroller in "bare" mode transmitting raw packets, instead of the usual BLE protocols.

Embed: (wiki syntax)

« Back to documentation index

nRFBareRadio.h File Reference

nRFBareRadio.h File Reference

nRFBareRadio is a library to use the Radio peripheral in a nRF51 or nRF52 Nordic microcontroller in "bare" mode transmitting raw packets, instead of the usual BLE protocols. More...

Go to the source code of this file.

Data Structures

struct  RadioAddress
 RadioAddress is a struct type for storing transmit and receive addresses, being used as argument to configure a radio. More...
class  RadioConfig
 RadioConfig holds various setup parameters, being used as argument to configure a radio. More...
class  BareRadio
 BareRadio represents and controls the RADIO peripheral in a nRF51 or nRF52 Nordic microcontroller. More...

Typedefs

typedef struct RadioAddress RadioAddress
 RadioAddress is a struct type for storing transmit and receive addresses, being used as argument to configure a radio.

Detailed Description

nRFBareRadio is a library to use the Radio peripheral in a nRF51 or nRF52 Nordic microcontroller in "bare" mode transmitting raw packets, instead of the usual BLE protocols.

Author:
Fernando Cosentino
Uses some code from a version by Manuel Caballero (https://os.mbed.com/users/mcm/)

Transmitter example:

  #include "mbed.h"
  #include "nRFBareRadio.h"

  #ifdef TARGET_NRF52
  DigitalOut led1(P0_17); // nRF52
  #else
  DigitalOut led1(P0_21); // nRF51
  #endif

  int main(void) {
      int i = 0;
      char buffer[32]; 

      // Address object
      RadioAddress address = {0xC0, 0x55, 0x42, 0xBB, 0xC2};

      // Configuration object
      RadioConfig config;
      config.frequency = 10; // 2400 + 10
      // change other config parameters here if you please
   
      // Radio object
      BareRadio radio;
      radio.Setup(RADIO_MODE_TX, address, config); // This is a transmitter

      // Main loop
      while(1) {
          // Put some data in the buffer     
          sprintf(buffer, "Value = %d\n", i++);
          // Transmit the buffer
          radio.Transmit(buffer);
          // Toggle the LED and wait a bit
          led1 = !led1;
          wait(1.0);
      }
  }

Receiver example:

  #include "mbed.h"
  #include "nRFBareRadio.h"

  #ifdef TARGET_NRF52
  Serial pc(P0_6, P0_8);  // nRF52
  DigitalOut led1(P0_17); // nRF52
  #else
  Serial pc(P0_9, P0_11); // nRF51
  DigitalOut led1(P0_21); // nRF51
  #endif

  int main(void) {
      int i = 0;
      char buffer[32]; 

      // Address object
      RadioAddress address = {0xC0, 0x55, 0x42, 0xBB, 0xC2};

      // Configuration object
      RadioConfig config;
      config.frequency = 10; // 2400 + 10
      // change other config parameters here if you please
   
      // Radio object
      BareRadio radio;
      radio.Setup(RADIO_MODE_RX, address, config); // This is a receiver

      // Main loop
      while(1) {
          // Did we receive a packet?
          if (radio.Receive(buffer)) {
              // Print the packet since the transmitter is sending a string
              pc.printf(buffer);
              // Toggle the LED
              led1 = !led1;
          }
      }
  }

Definition in file nRFBareRadio.h.


Typedef Documentation

typedef struct RadioAddress RadioAddress

RadioAddress is a struct type for storing transmit and receive addresses, being used as argument to configure a radio.