nRF24L01 driver

Dependents:   Nucleo_IOT1 wireless

Committer:
ianmcc
Date:
Wed Sep 14 14:43:13 2016 +0000
Revision:
6:952996e3abdb
Parent:
5:bb28775120e7
bug fixes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ianmcc 0:7313e63394c3 1 // A simple PTX driver for the nRF24L01+
ianmcc 0:7313e63394c3 2 // with fixed payload length
ianmcc 0:7313e63394c3 3
ianmcc 0:7313e63394c3 4 #ifndef NRF24L01P_PTX_H
ianmcc 0:7313e63394c3 5 #define NRF24L01P_PTX_H
ianmcc 0:7313e63394c3 6
ianmcc 0:7313e63394c3 7 #include "nRF24L01P.h"
ianmcc 0:7313e63394c3 8
ianmcc 0:7313e63394c3 9 class nRF24L01P_PTX
ianmcc 0:7313e63394c3 10 {
ianmcc 0:7313e63394c3 11 public:
ianmcc 0:7313e63394c3 12 nRF24L01P_PTX(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 transmitter power in dB. Valid values are -18, -12, -6, 0
ianmcc 0:7313e63394c3 25 void SetTransmitPower(int Power);
ianmcc 0:7313e63394c3 26
ianmcc 0:7313e63394c3 27 // Set the 40-bit destination address
ianmcc 0:7313e63394c3 28 void SetDestinationAddress(uint64_t Address);
ianmcc 0:7313e63394c3 29
ianmcc 0:7313e63394c3 30 // Power up ready to transmit. There is a delay of Tpd2stby_us
ianmcc 0:7313e63394c3 31 // after PowerUp() before a packet can be transmitted. This
ianmcc 0:7313e63394c3 32 // is handled automatically with a timer, so that TransmitPacket()
ianmcc 0:7313e63394c3 33 // will block until the device is ready.
ianmcc 0:7313e63394c3 34 void PowerUp();
ianmcc 0:7313e63394c3 35
ianmcc 0:7313e63394c3 36 // Powers down the device. PowerUp must be called before a packet can be transmitted.
ianmcc 0:7313e63394c3 37 void PowerDown();
ianmcc 0:7313e63394c3 38
ianmcc 0:7313e63394c3 39 // Returns true if the device is ready to transmit a packet, ie
ianmcc 0:7313e63394c3 40 // powered on and not busy
ianmcc 0:7313e63394c3 41 bool IsReadyTransmit();
ianmcc 0:7313e63394c3 42
ianmcc 0:7313e63394c3 43 // Does the actual transmit of a packet, in blocking mode.
ianmcc 0:7313e63394c3 44 // Returns 0 on success.
ianmcc 0:7313e63394c3 45 // Returns -1 if the packet wasn't successfully acknowledged.
ianmcc 0:7313e63394c3 46 int TransmitPacket(char* Buf, int Size);
ianmcc 0:7313e63394c3 47
ianmcc 5:bb28775120e7 48 // Transmits a packet in non-blocking mode.
ianmcc 5:bb28775120e7 49 // returns 0 if the packet was successful, -1 on some error (eg
ianmcc 5:bb28775120e7 50 // if the device isn't ready to transmit).
ianmcc 5:bb28775120e7 51 int TransmitPacketNonBlocking(char* Buf, int Size);
ianmcc 5:bb28775120e7 52
ianmcc 5:bb28775120e7 53 // For nonblocking mode, returns false if there is still a pending
ianmcc 5:bb28775120e7 54 // packet waiting to send. Returns true if the packet has been
ianmcc 5:bb28775120e7 55 // sent or there was some error (eg max retries was hit).
ianmcc 5:bb28775120e7 56 bool IsTransmitFinished();
ianmcc 5:bb28775120e7 57
ianmcc 5:bb28775120e7 58 // For nonblocking mode, complete the transmission process. If
ianmcc 5:bb28775120e7 59 // IsTransmitFinished() is false, then this call is blocking.
ianmcc 5:bb28775120e7 60 // returns 0 if the packet was sent successfully, -1 if it wasn't.
ianmcc 5:bb28775120e7 61 int TransmitComplete();
ianmcc 5:bb28775120e7 62
ianmcc 0:7313e63394c3 63 private:
ianmcc 0:7313e63394c3 64 void IntHandler();
ianmcc 0:7313e63394c3 65 void ReadyInitialize();
ianmcc 0:7313e63394c3 66 void ReadyStandby();
ianmcc 0:7313e63394c3 67
ianmcc 0:7313e63394c3 68 nRF24L01P& Device;
ianmcc 0:7313e63394c3 69 DigitalOut CE;
ianmcc 0:7313e63394c3 70 InterruptIn Int;
ianmcc 0:7313e63394c3 71 Timeout PowerOnTimer;
ianmcc 0:7313e63394c3 72 Timeout InitializeTimer;
ianmcc 0:7313e63394c3 73
ianmcc 0:7313e63394c3 74 int volatile Status;
ianmcc 0:7313e63394c3 75 };
ianmcc 0:7313e63394c3 76
ianmcc 0:7313e63394c3 77 #endif