nRF24L01 driver

Dependents:   Nucleo_IOT1 wireless

Committer:
ianmcc
Date:
Wed Sep 14 14:43:13 2016 +0000
Revision:
6:952996e3abdb
Parent:
0:7313e63394c3
bug fixes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ianmcc 0:7313e63394c3 1 // A simple PRX driver for the nRF24L01+
ianmcc 0:7313e63394c3 2 // for polling mode with fixed payload length
ianmcc 0:7313e63394c3 3
ianmcc 0:7313e63394c3 4 #ifndef NRF24L01P_PRX_H
ianmcc 0:7313e63394c3 5 #define NRF24L01P_PRX_H
ianmcc 0:7313e63394c3 6
ianmcc 0:7313e63394c3 7 #include "nRF24L01P.h"
ianmcc 0:7313e63394c3 8
ianmcc 0:7313e63394c3 9 class nRF24L01P_PRX
ianmcc 0:7313e63394c3 10 {
ianmcc 0:7313e63394c3 11 public:
ianmcc 0:7313e63394c3 12 nRF24L01P_PRX(nRF24L01P& Device_, PinName CE_, PinName Int_);
ianmcc 0:7313e63394c3 13
ianmcc 0:7313e63394c3 14 // Initialize the device for transmitting. There must be a delay of
ianmcc 0:7313e63394c3 15 // at least 100ms from initial power on before this function is called.
ianmcc 0:7313e63394c3 16 void Initialize();
ianmcc 0:7313e63394c3 17
ianmcc 0:7313e63394c3 18 // Set the channel number, 0 .. 125
ianmcc 0:7313e63394c3 19 void SetChannel(int Channel);
ianmcc 0:7313e63394c3 20
ianmcc 0:7313e63394c3 21 // sets the data rate in Kbps, valid values are 250 (nRF24L01+ only), 1000, 2000
ianmcc 0:7313e63394c3 22 void SetDataRate(int Rate);
ianmcc 0:7313e63394c3 23
ianmcc 0:7313e63394c3 24 // Set the 40-bit address
ianmcc 0:7313e63394c3 25 void SetAddress(uint64_t Address);
ianmcc 0:7313e63394c3 26
ianmcc 0:7313e63394c3 27 // Set the expected payload size
ianmcc 0:7313e63394c3 28 void SetPayloadSize(int Size);
ianmcc 0:7313e63394c3 29
ianmcc 0:7313e63394c3 30 // Power up ready to enter receive mode. There is a delay of Tpd2stby_us
ianmcc 0:7313e63394c3 31 // after PowerUp() before receiving can start.
ianmcc 0:7313e63394c3 32 void PowerUp();
ianmcc 0:7313e63394c3 33
ianmcc 0:7313e63394c3 34 // Powers down the device. PowerUp must be called before a packet can be transmitted.
ianmcc 0:7313e63394c3 35 void PowerDown();
ianmcc 0:7313e63394c3 36
ianmcc 0:7313e63394c3 37 // Start listening for packets.
ianmcc 0:7313e63394c3 38 void StartReceive();
ianmcc 0:7313e63394c3 39
ianmcc 0:7313e63394c3 40 // Stop listening for packets.
ianmcc 0:7313e63394c3 41 void StopReceive();
ianmcc 0:7313e63394c3 42
ianmcc 0:7313e63394c3 43 // returns true if there is a packet ready to read
ianmcc 0:7313e63394c3 44 bool IsPacketReady();
ianmcc 0:7313e63394c3 45
ianmcc 0:7313e63394c3 46 // PRECONDITION: IsPacketReady().
ianmcc 0:7313e63394c3 47 // Reads the packet into the given buffer.
ianmcc 0:7313e63394c3 48 // Returns the size of the packet.
ianmcc 0:7313e63394c3 49 int ReadPacket(char* Buf);
ianmcc 0:7313e63394c3 50
ianmcc 0:7313e63394c3 51 private:
ianmcc 0:7313e63394c3 52 void IntHandler();
ianmcc 0:7313e63394c3 53 void ReadyInitialize();
ianmcc 0:7313e63394c3 54 void ReadyStandby();
ianmcc 0:7313e63394c3 55
ianmcc 0:7313e63394c3 56 nRF24L01P& Device;
ianmcc 0:7313e63394c3 57 DigitalOut CE;
ianmcc 0:7313e63394c3 58 InterruptIn Int;
ianmcc 0:7313e63394c3 59 Timeout PowerOnTimer;
ianmcc 0:7313e63394c3 60 Timeout InitializeTimer;
ianmcc 0:7313e63394c3 61
ianmcc 0:7313e63394c3 62 int volatile Status;
ianmcc 0:7313e63394c3 63 int PayloadSize;
ianmcc 0:7313e63394c3 64 };
ianmcc 0:7313e63394c3 65
ianmcc 0:7313e63394c3 66 #endif