Hello world example for the nRF2401A Library

Dependencies:   mbed nRF2401A

main.cpp

Committer:
TheChrisyd
Date:
2013-10-06
Revision:
3:34ae527e9d41
Parent:
2:440c95f796ac
Child:
4:aa6866d2014a

File content as of revision 3:34ae527e9d41:

#include "mbed.h"
#include "nRF2401A.h"

// comment these out depending on the job of the mbed. If your only using one mbed leave both uncommented.
#define TX
#define RX

Serial pc(USBTX, USBRX);
DigitalOut  myled(LED1);

#ifdef TX
nRF2401A    rf1(p10, p11, p12, p13, p14);
#endif

#ifdef RX
nRF2401A    rf2(p21, p22, p23, p24, p25);

bool rx_recieved = false;

void nRF2401A_rx (void *arg) 
{
     rx_recieved = true;
}
#endif
int main() 
{
    wait(0.005);
    pc.printf("Hello nRF2401A\n\r");
    
#ifdef TX    
    rf1.setDataPayloadLength(4 << 3)
       .setAddress(0x0, 0x0, 0xa6, 0xa6, 0xa6, 3 << 3)
       .setCRCMode(nRF2401A::NO_CRC)
       .setDataRate(nRF2401A::BIT_RATE_250KBITS)
       .setChannel(0x02);
       
    rf1.printControlPacket(pc);
    rf1.flushControlPacket();
    
    nRF2401A::address_t rf2_addr = {0x0, 0x0, 0x53, 0x53, 0x53};
    uint8_t msg[] = {0x01, 0x01, 0x01, 0x01};
    uint32_t *msg32 = (uint32_t *) msg;
#endif

#ifdef RX   
    rf2.setDataPayloadLength(4 << 3)
       .setAddress(0x0, 0x0, 0x53, 0x53, 0x53, 3 << 3)
       .setCRCMode(nRF2401A::NO_CRC)
       .setDataRate(nRF2401A::BIT_RATE_250KBITS)
       .setChannel(0x02);
       
    rf2.printControlPacket(pc);
    rf2.flushControlPacket();   
    rf2.attachRXHandler(&nRF2401A_rx, 0);
#endif
      
    while(1) 
    {
    
#ifdef TX             
        rf1.sendMsg(rf2_addr, 3 << 3, msg, 4 << 3);
        *msg32 += 1;
#endif

        myled = 1;
        wait(0.25);
        
#ifdef RX  
        if (rx_recieved)
        {      
            rf2.printDataPacket(pc);
            rx_recieved = false;
        }
#endif 
      
        myled = 0;
        wait(0.25);
    }
}