Library for the (decidedly not as good as the 24L01+) Nordic 2401A radio.

Fork of Nrf2401 by Heroic Robotics

Committer:
heroic
Date:
Fri Sep 20 20:55:24 2013 +0000
Revision:
0:db163b6f1592
Child:
1:049f6cb8b160
Establishing commit.  Ported to mbed.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
heroic 0:db163b6f1592 1 /*
heroic 0:db163b6f1592 2 * Nrf2401A.h
heroic 0:db163b6f1592 3 * A simplistic interface for using Sparkfun's Nrf2401A breakout boards with Arduino
heroic 0:db163b6f1592 4 *
heroic 0:db163b6f1592 5 * Ported to mbed by Jas Strong <jasmine@heroicrobotics.com>
heroic 0:db163b6f1592 6 *
heroic 0:db163b6f1592 7 * Original code for http://labs.ideo.com by Jesse Tane March 2009
heroic 0:db163b6f1592 8 *
heroic 0:db163b6f1592 9 * License:
heroic 0:db163b6f1592 10 * --------
heroic 0:db163b6f1592 11 * This is free software. You can redistribute it and/or modify it under
heroic 0:db163b6f1592 12 * the terms of Creative Commons Attribution 3.0 United States License.
heroic 0:db163b6f1592 13 * To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/us/
heroic 0:db163b6f1592 14 * or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
heroic 0:db163b6f1592 15 *
heroic 0:db163b6f1592 16 * Original version Notes:
heroic 0:db163b6f1592 17 * -----------------------
heroic 0:db163b6f1592 18 * For documentation on how to use this library, please visit http://www.arduino.cc/playground/Main/InterfacingWithHardware
heroic 0:db163b6f1592 19 * Pin connections should be as follows for Arduino:
heroic 0:db163b6f1592 20 *
heroic 0:db163b6f1592 21 * DR1 = 2 (digital pin 2)
heroic 0:db163b6f1592 22 * CE = 3
heroic 0:db163b6f1592 23 * CS = 4
heroic 0:db163b6f1592 24 * CLK = 5
heroic 0:db163b6f1592 25 * DAT = 6
heroic 0:db163b6f1592 26 *
heroic 0:db163b6f1592 27 */
heroic 0:db163b6f1592 28
heroic 0:db163b6f1592 29 #include "mbed.h"
heroic 0:db163b6f1592 30
heroic 0:db163b6f1592 31 #define NRF2401_BUFFER_SIZE 25
heroic 0:db163b6f1592 32
heroic 0:db163b6f1592 33 class Nrf2401
heroic 0:db163b6f1592 34 {
heroic 0:db163b6f1592 35 public:
heroic 0:db163b6f1592 36
heroic 0:db163b6f1592 37 // properties
heroic 0:db163b6f1592 38
heroic 0:db163b6f1592 39 volatile unsigned char data[NRF2401_BUFFER_SIZE];
heroic 0:db163b6f1592 40 volatile unsigned int remoteAddress;
heroic 0:db163b6f1592 41 volatile unsigned int localAddress;
heroic 0:db163b6f1592 42 volatile unsigned char dataRate;
heroic 0:db163b6f1592 43 volatile unsigned char channel;
heroic 0:db163b6f1592 44 volatile unsigned char power;
heroic 0:db163b6f1592 45 volatile unsigned char mode;
heroic 0:db163b6f1592 46
heroic 0:db163b6f1592 47 // methods
heroic 0:db163b6f1592 48
heroic 0:db163b6f1592 49 Nrf2401(PinName n_DR1, PinName n_CE, PinName n_SC, PinName n_CLK, PinName n_DAT);
heroic 0:db163b6f1592 50 void rxMode(unsigned char messageSize=0);
heroic 0:db163b6f1592 51 void txMode(unsigned char messageSize=0);
heroic 0:db163b6f1592 52 void write(unsigned char dataByte);
heroic 0:db163b6f1592 53 void write(unsigned char* dataBuffer=0);
heroic 0:db163b6f1592 54 void read(unsigned char* dataBuffer=0);
heroic 0:db163b6f1592 55 bool available(void);
heroic 0:db163b6f1592 56
heroic 0:db163b6f1592 57 // you shouldn't need to use anything below this point..
heroic 0:db163b6f1592 58 private:
heroic 0:db163b6f1592 59 volatile unsigned char payloadSize;
heroic 0:db163b6f1592 60 volatile unsigned char configuration[15];
heroic 0:db163b6f1592 61 void configure(void);
heroic 0:db163b6f1592 62 void loadConfiguration(bool modeSwitchOnly=false);
heroic 0:db163b6f1592 63 void loadByte(unsigned char byte);
heroic 0:db163b6f1592 64
heroic 0:db163b6f1592 65 DigitalOut _ce, _cs, _clk;
heroic 0:db163b6f1592 66 DigitalIn _dr1;
heroic 0:db163b6f1592 67 DigitalInOut _dat;
heroic 0:db163b6f1592 68 };