This is a work in progress for an NRF2401P
Dependents: NRF_receiver sender locker4 Weather_Station_Ofiicial ... more
About
This is a simple library to drive the nRF24l01+.
Hardware
This uses the commonly available breakout. The connections are shown below
Software
Use case: For a simple transmitter
tx code snipet
#include "NRF2401P.h" int main() { * * long long addr1=0xAB00CD; // setup address - any 5 byte number - same as RX * int channel =0x12; // [0-126] setup channel, must be same as RX * bool txOK; * char msg[32]; * char ackData[32]; * char len; * * // Setup * NRF2401P nrf1(PTD6,PTD7, PTD5,PTD4, PTC12); //mosi, miso, sclk, csn, ce) * nrf1.quickTxSetup(channel, addr1); // sets nrf24l01+ as transmitter * * // transmit * strcpy (msg, "Hello"); * txOK= nrf1.transmitData(msg,strlen(msg)); * * // read ack data if available * if (nrf1.isAckData()) { * len= nrf1.getRxData(ackData); // len is number of bytes in ackData * } *}
Use case: For a simple receiver
rx code snipet
#include "NRF2401P.h" *int main(){ * * long long addr1=0xAB00CD; // setup address - any 5 byte number - same as TX * int channel =0x12; // [0-126] setup channel, must be same as TX * bool txOK; * char msg[32]; * char ackData[32]; * char len; * * // Setup * NRF2401P nrf1(PTD6,PTD7, PTD5,PTD4, PTC12); //mosi, miso, sclk, csn, ce) * nrf1.quickRxSetup(channel, addr1); // sets nrf24l01+ as receiver, using pipe 1 * * // set ack data * sprintf(ackData,"Ack data"); * nrf1.acknowledgeData(ackData, strlen(ackData),1); // ack for pipe 1 * * // receive * while (! nrf1.isRxData()); // note this blocks until RX data * len= nrf1.getRxData(msg); // gets the message, len is length of msg * *}
Diff: NRF2401P.h
- Revision:
- 15:9998698cb041
- Parent:
- 5:7e253c677a1f
--- a/NRF2401P.h Fri Jun 12 09:55:02 2015 +0000 +++ b/NRF2401P.h Thu Jun 18 20:54:25 2015 +0000 @@ -95,11 +95,11 @@ NRF2401P (PinName mosi, PinName miso, PinName sclk, PinName _csn, PinName _ce); - char acknowledgeData( char *data, char width, char pipe); + void acknowledgeData( char *data, char width, char pipe); char checkStatus(); - bool clearStatus(); - bool flushRx(); - bool flushTx(); + void clearStatus(); + void flushRx(); + void flushTx(); char getRxData(char * buffer); char getRxWidth(); bool isAckData(); @@ -108,26 +108,26 @@ void quickRxSetup(int channel,long long addr); void quickTxSetup(int channel,long long addr); char readReg(char address, char *data); - char testReceive(); - char testTransmit(); + void testReceive(); + void testTransmit(); bool transmitData( char *data, char width ); - bool setAddressWidth(char width); - char setChannel(char chan); + void setAddressWidth(char width); + void setChannel(char chan); void setDynamicPayload(); - bool setPwrUp(); - char setRadio(char speed,char power); - char setRxAddress(char *address, char pipe); - char setRxAddress(long long address, char pipe); + void setPwrUp(); + void setRadio(char speed,char power); + void setRxAddress(char *address, char pipe); + void setRxAddress(long long address, char pipe); bool setRxMode(); - char setTxAddress(char *address); - char setTxAddress(long long address); + void setTxAddress(char *address); + void setTxAddress(long long address); bool setTxMode(); void setTxRetry(char delay, char numTries); void start(); char * statusString(); - char writeReg(char address, char *data, char width); - char writeReg(char address, char data); + void writeReg(char address, char *data, char width); + void writeReg(char address, char data); void scratch();