Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years, 4 months ago.
Sample code?
Do you have a working sample to test this library?
Question relating to:
1 Answer
10 years, 4 months ago.
A simple test that transmits a test payload (single character 'a') from one device (PTX) to another device (PRX) connected to the same SPI bus. The signals are set up for a FRDMKL25z, you might need to chamge them around.
#include "mbed.h" #include "nRF24L01P_PTX.h" #include "nRF24L01P_PRX.h" int main() { nRF24L01P Device(PTD2, PTD3, PTD1, PTD5); nRF24L01P_PTX PTX(Device, PTA13, PTD0); PTX.Initialize(); PTX.SetDataRate(2000); PTX.PowerUp(); nRF24L01P Receiver(PTD2, PTD3, PTD1, PTC7); nRF24L01P_PRX PRX(Receiver, PTA12, PTD4); printf("Initialize\r\n"); PRX.Initialize(); printf("SetDataRate\r\n"); PRX.SetDataRate(2000); printf("SetPayloadSize\r\n"); PRX.SetPayloadSize(1); printf("PowerUp\r\n"); PRX.PowerUp(); printf("StartReceive\r\n"); PRX.StartReceive(); printf("Loop\r\n"); while (1) { char c = 'a'; printf("Transmit\r\n"); int r = PTX.TransmitPacket(&c, 1); printf("%d\r\n", r); if (PRX.IsPacketReady()) { char d; int r = PRX.ReadPacket(&d); printf("Read %d %c\r\n", r, d); } wait_us(1000); } }
hi Ian. you used two nrf24l01+ module in your board? One Of Them For Receiver And On of Them for Transmiter?
posted by 19 Aug 2014Yes, for the test I used two modules on one mbed. It is very simple to run it on two mbed's, just split the code into two files, one containing the PTX stuff and the other containing the PRX stuff. My test board was a FRDM-KL25Z, you'll need to change the pin assignments for other hardware.
posted by 19 Aug 2014tanks Ian. who can i read mac address from nrf24l01? the nrf24l01, It is possible?has It a unique address?
posted by 20 Aug 2014The nRF24L01+ doesn't have a unique address built into it. See the datasheet at http://www.nordicsemi.com/eng/Products/2.4GHz-RF/nRF24L01P. You can set the channel and address to anything you like. The code sample uses the default channel and address.
You can change the channel in the PRX and PTX classes with the SetChannel() function. This should be set the same for both the PTX and the PRX.
You can set the receiver address in the PRX::SetAddress() function. The PTX should use the same address for the destination, using PTX::SetDestinationAddress().
The nRF24L01+ also allows for different 'pipes'. The nRF25L01 class exposes the basic functionality, but the PTX and PRX classes don't yet make use of it.
posted by 20 Aug 2014