nRF24L01 driver
Dependents: Nucleo_IOT1 wireless
nRF24L01P_PTX.h@0:7313e63394c3, 2013-08-11 (annotated)
- Committer:
- ianmcc
- Date:
- Sun Aug 11 11:58:05 2013 +0000
- Revision:
- 0:7313e63394c3
- Child:
- 5:bb28775120e7
Initial
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:7313e63394c3 | 48 | private: |
ianmcc | 0:7313e63394c3 | 49 | void IntHandler(); |
ianmcc | 0:7313e63394c3 | 50 | void ReadyInitialize(); |
ianmcc | 0:7313e63394c3 | 51 | void ReadyStandby(); |
ianmcc | 0:7313e63394c3 | 52 | |
ianmcc | 0:7313e63394c3 | 53 | nRF24L01P& Device; |
ianmcc | 0:7313e63394c3 | 54 | DigitalOut CE; |
ianmcc | 0:7313e63394c3 | 55 | InterruptIn Int; |
ianmcc | 0:7313e63394c3 | 56 | Timeout PowerOnTimer; |
ianmcc | 0:7313e63394c3 | 57 | Timeout InitializeTimer; |
ianmcc | 0:7313e63394c3 | 58 | |
ianmcc | 0:7313e63394c3 | 59 | int volatile Status; |
ianmcc | 0:7313e63394c3 | 60 | }; |
ianmcc | 0:7313e63394c3 | 61 | |
ianmcc | 0:7313e63394c3 | 62 | #endif |