embedded-software
reusable software modules for embedded systems
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
nRF24L01+ Network (geared for class projects)

Data Structures

union  nrfnet_address_t
 
struct  nrfnet_msg_t
 
struct  nrfnet_s
 

Macros

#define NRF24_CHANNEL_BRANCH_1   30
 
#define NRF24_CHANNEL_BRANCH_2   34
 
#define NRF24_CHANNEL_BRANCH_3   38
 
#define NRF24_CHANNEL_BRANCH_4   42
 
#define NRF24_CHANNEL_BRANCH_5   46
 
#define NRF24_CHANNEL_BRANCH_6   50
 
#define NRF24_ADDRESS_MASK   0x6C6C6C7800
 
#define NRF24_MIN_WINDOW_MS   8
 
#define NRF24_BRANCH_WINDOW_MS   7
 
#define NRF24_TICK_MS   2
 
#define NRF24_MISSING_NODE_TIMEOUT   100
 
#define NRFNET_MSG_BUFFER_LENGTH   16
 
#define nrf24_NetworkISRHandlerN(net)   nRF24_ISR(&net.radio)
 

Typedefs

typedef void(* nrf24_handler_fn_t )(uint8_t *data, uint8_t len, uint8_t from)
 
typedef struct nrfnet_s nrfnet_t
 

Enumerations

enum  nrf24_msg_id {
  SYSTEM_MSG = 0, CONTROL_MSG, SENSOR_MSG, CHAT_MSG,
  TEST_MSG, KILL_MSG, THIEF_MSG, LAST_MSG_ID
}
 
enum  nrf24_system_msg { NULL_MSG = 0, PING_MSG, PING_RESPONSE_MSG, SPAM_MSG }
 
enum  nrf24_control_msg { ONBOARD_LED, LINEAR_ACTUATOR, LAST_CONTROL_ID }
 
enum  nrf24_sensor_msg { TEMPERATURE_SENSOR, LAST_SENSOR_ID }
 
enum  nrf24_thief_msg {
  ARM_MSG, DISARM_MSG, TRIP_MSG, ACCESS_MSG,
  ERROR_MSG, DIFFICULTY_MSG, LAST_THIEF_ID
}
 
enum  nrf24_address {
  MASTER = 0x00, SCRUM_PUN = 0x08, BALL_TRAP, TOMS_PAD,
  NOODLE, MOUSE_TRAP = 0x10, ULTRASONIC = 0x18, DAN,
  CAM, JAKE, SUPREME = 0x20, BOT,
  SNEAK, LASER, SIMON, OGLAZERBOIZ = 0x28,
  OGLAZ2, LOCK_PICK, PIEZO, MIKE = 0x30,
  SORCE, MALONEY, MUHLBAIER, LAST_ADDRESS,
  ALL_ALL = 0x3F
}
 
enum  nrfstate_e { NRFNET_INITIALIZED = 0x00, NRFNET_NORMAL_STATE = 0x00, NRFNET_WAITING_FOR_MIN_WINDOW }
 
enum  nrfrole_e { ROLE_MASTER, ROLE_BRANCH, ROLE_LEAF }
 
enum  pipe_status_e { CHILD_INITIALIZED, CHILD_ACTIVE, CHILD_MISSING }
 

Functions

void nrf24_NetworkInit (void(*ce)(uint8_t), void(*csn)(uint8_t), uint8_t spi_channel)
 Initialize nRF24 Network Module. More...
 
void nrf24_NetworkInitN (nrfnet_t *net, void(*ce)(uint8_t), void(*csn)(uint8_t), uint8_t spi_channel, uint8_t node)
 
void nrf24_RegisterMsgHandler (enum nrf24_msg_id msg_id, nrf24_handler_fn_t fn_ptr)
 
void nrf24_RegisterMsgHandlerN (nrfnet_t *net, enum nrf24_msg_id msg_id, nrf24_handler_fn_t fn_ptr)
 
void nrf24_SendMsg (uint8_t to, enum nrf24_msg_id msg_id, uint8_t *data, uint8_t len)
 
void nrf24_SendMsgN (nrfnet_t *net, uint8_t to, enum nrf24_msg_id msg_id, uint8_t *data, uint8_t len)
 
void nrf24_RegisterControlHandler (enum nrf24_control_msg control_id, nrf24_handler_fn_t fn_ptr)
 
void nrf24_RegisterControlHandlerN (nrfnet_t *net, enum nrf24_control_msg control_id, nrf24_handler_fn_t fn_ptr)
 
void nrf24_RegisterSensorHandler (enum nrf24_sensor_msg sensor_id, nrf24_handler_fn_t fn_ptr)
 
void nrf24_RegisterSensorHandlerN (nrfnet_t *net, enum nrf24_sensor_msg sensor_id, nrf24_handler_fn_t fn_ptr)
 
void nrf24_NetworkISRHandler (void)
 
void nrf24_Ping (uint8_t to)
 
char * NameFromAddress (uint8_t address)
 
uint8_t AddressFromName (char *name)
 

Detailed Description

Version
0.1

Dependencies: nrf24.h spi.h task.h timing.h subsys.h uart.h

Default Pinouts:

MSP430F5529:

PIC32MX250F128B:

Created on April 7, 2015, 6:24 PM

Macro Definition Documentation

#define NRF24_ADDRESS_MASK   0x6C6C6C7800
#define NRF24_BRANCH_WINDOW_MS   7
#define NRF24_CHANNEL_BRANCH_1   30
#define NRF24_CHANNEL_BRANCH_2   34
#define NRF24_CHANNEL_BRANCH_3   38
#define NRF24_CHANNEL_BRANCH_4   42
#define NRF24_CHANNEL_BRANCH_5   46
#define NRF24_CHANNEL_BRANCH_6   50
#define NRF24_MIN_WINDOW_MS   8
#define NRF24_MISSING_NODE_TIMEOUT   100
#define nrf24_NetworkISRHandlerN (   net)    nRF24_ISR(&net.radio)
#define NRF24_TICK_MS   2
#define NRFNET_MSG_BUFFER_LENGTH   16

Typedef Documentation

typedef void(* nrf24_handler_fn_t)(uint8_t *data, uint8_t len, uint8_t from)

function pointer type for consuming certain msg_id's

typedef struct nrfnet_s nrfnet_t

Enumeration Type Documentation

Enumerator
MASTER 

Brainframe / Scrumshank Redemption.

SCRUM_PUN 

Branch 1 - ScrumPun.

BALL_TRAP 
TOMS_PAD 
NOODLE 
MOUSE_TRAP 

Branch 2 - RedBulls.

ULTRASONIC 

Branch 3 - SmartHomies.

DAN 
CAM 
JAKE 
SUPREME 

Branch 4 - TeamSupreme.

BOT 
SNEAK 
LASER 
SIMON 
OGLAZERBOIZ 

Branch 5 - Muhlbaier's Fav. Clinic.

OGLAZ2 
LOCK_PICK 
PIEZO 
MIKE 

Branch 6 - Scrumshank Redemption.

SORCE 
MALONEY 
MUHLBAIER 
LAST_ADDRESS 
ALL_ALL 
Enumerator
ONBOARD_LED 
LINEAR_ACTUATOR 
LAST_CONTROL_ID 

reserved name to determine number of control msgs supported

Enumerator
SYSTEM_MSG 

built-in / MM

CONTROL_MSG 

general control msg / max payload 5+ bytes

SENSOR_MSG 

general sensor msg / max payload 4+ bytes

CHAT_MSG 

built-in / Jon W.

TEST_MSG 

Used for testing the network.

KILL_MSG 

Used to remotely kill (reset) a node on the network.

THIEF_MSG 

Used to support the Theif class project.

LAST_MSG_ID 

reserved name to determine number of message IDs supported

Enumerator
TEMPERATURE_SENSOR 
LAST_SENSOR_ID 

reserved name to determine number of sensors supported

Enumerator
NULL_MSG 
PING_MSG 
PING_RESPONSE_MSG 
SPAM_MSG 
Enumerator
ARM_MSG 

Brainframe->Thing, data is difficulty.

DISARM_MSG 

Brainframe->Thing, data is difficulty.

TRIP_MSG 

Thing->Brainframe, data is score (1 barely tripped)

ACCESS_MSG 

Thing->Brainframe, data is score (1 great job)

ERROR_MSG 

Thing->Brainframe, data is error code (TBD)

DIFFICULTY_MSG 

Brainframe->Thing, data is difficulty.

LAST_THIEF_ID 

reserved name to determine number of messages supported

enum nrfrole_e
Enumerator
ROLE_MASTER 
ROLE_BRANCH 
ROLE_LEAF 
enum nrfstate_e
Enumerator
NRFNET_INITIALIZED 
NRFNET_NORMAL_STATE 
NRFNET_WAITING_FOR_MIN_WINDOW 
Enumerator
CHILD_INITIALIZED 
CHILD_ACTIVE 
CHILD_MISSING 

Function Documentation

uint8_t AddressFromName ( char *  name)
Parameters
namepointer to name to lookup
Returns
address network address

Here is the call graph for this function:

char* NameFromAddress ( uint8_t  address)

Convert network address to name

Parameters
addressaddress to convert to name
Returns
string pointer to name
void nrf24_NetworkInit ( void(*)(uint8_t)  ce,
void(*)(uint8_t)  csn,
uint8_t  spi_channel 
)

Initialize nRF24 Network Module.

Parameters
ceFunction pointer to Chip Enable signal function. If input to the function is 0 the CE line should output GND. If the input to the function is 1 the CE pin should output 3.3V
csnFunction pointer to Not Chip Select signal function. If input to the function is 0 the CSN line should output GND. If the input to the function is 1 the CSN pin should output 3.3V
spi_channelSPI channel number to be passed to the SPI Module

Here is the call graph for this function:

Here is the caller graph for this function:

void nrf24_NetworkInitN ( nrfnet_t net,
void(*)(uint8_t)  ce,
void(*)(uint8_t)  csn,
uint8_t  spi_channel,
uint8_t  node 
)

Here is the call graph for this function:

Here is the caller graph for this function:

void nrf24_NetworkISRHandler ( void  )

Here is the caller graph for this function:

void nrf24_Ping ( uint8_t  to)

Here is the call graph for this function:

void nrf24_RegisterControlHandler ( enum nrf24_control_msg  control_id,
nrf24_handler_fn_t  fn_ptr 
)

Register a control message Handler for a specific control ID

Same as nrf24_RegisterMsgHandler() except the Handler will be called when the message ID is CONTROL_MSG and the control_id (byte after msg ID, i.e. byte 4) matches control_id.

Parameters
control_idControl ID to register Handler for
fn_ptrPointer to Handler function

Here is the call graph for this function:

void nrf24_RegisterControlHandlerN ( nrfnet_t net,
enum nrf24_control_msg  control_id,
nrf24_handler_fn_t  fn_ptr 
)

Here is the caller graph for this function:

void nrf24_RegisterMsgHandler ( enum nrf24_msg_id  msg_id,
nrf24_handler_fn_t  fn_ptr 
)

Register a message Handler for a specific message ID

When a message with a message ID that matches msg_id is received the Handler function will be called with a data pointer to the remaining payload (data), the length of the remaining payload (len), and the from address (from).

Only one handler per message ID may be registered.

Handlers for SYSTEM_MSG, CONTROL_MSG, SENSOR_MSG, and CHAT_MSG are built-in but can be overridden.

Example:

void PongHandler(uint8_t * data, uint8_t len, uint8_t from) {
// implement pong handler
}
nrf24_RegisterMsgHandler(PONG_MSG, PongHandler);
Parameters
msg_idMessage ID to register Handler for
fn_ptrPointer to Handler function

Here is the call graph for this function:

Here is the caller graph for this function:

void nrf24_RegisterMsgHandlerN ( nrfnet_t net,
enum nrf24_msg_id  msg_id,
nrf24_handler_fn_t  fn_ptr 
)

Here is the caller graph for this function:

void nrf24_RegisterSensorHandler ( enum nrf24_sensor_msg  sensor_id,
nrf24_handler_fn_t  fn_ptr 
)

Register a sensor message Handler for a specific sensor ID

Same as nrf24_RegisterMsgHandler() except the Handler will be called when the message ID is SENSOR_MSG and the sensor_id (byte after msg ID, i.e. byte 4) matches sensor_id.

Parameters
sensor_idSensor ID to register Handler for
fn_ptrPointer to Handler function

Here is the call graph for this function:

void nrf24_RegisterSensorHandlerN ( nrfnet_t net,
enum nrf24_sensor_msg  sensor_id,
nrf24_handler_fn_t  fn_ptr 
)

Here is the caller graph for this function:

void nrf24_SendMsg ( uint8_t  to,
enum nrf24_msg_id  msg_id,
uint8_t *  data,
uint8_t  len 
)

Send a message over the nRF24 network

Parameters
toaddress to send message to (use enum nrf24_address for now)
msg_idMessage ID
datapointer to data payload (address bytes and message ID will be generated automatically, this pointer should point to the fourth byte of the payload).
lenlength to the data payload (min 0, max 29)

Here is the call graph for this function:

Here is the caller graph for this function:

void nrf24_SendMsgN ( nrfnet_t net,
uint8_t  to,
enum nrf24_msg_id  msg_id,
uint8_t *  data,
uint8_t  len 
)

Here is the caller graph for this function: