nRF2401A (Trace Antenna) Component page progress

04 Oct 2013

Hello, This is my page for updating progress on the Component page for the nRF2401A(Trace Antenna). Since this is going to be the same library and probably the same component page as the chip antenna version I have joined Jas Strong in porting the Arduino Library across to the mbed. I have also created a library based on the work of Per Söderstam on his driver_nRF2401A class. I have published this as a Library and Hello World example here:

Import librarynRF2401A

Library for the nRF2401A Transceiver

and

Import programnRF2401A_Hello_World

Hello world example for the nRF2401A Library

I have only tested this with 2 LPC1768 mbeds so far, but have a LPC800-MAX and a FRDM-KL25Z to test it with too.

The hello world example is currently sending whatever data the receive buffer has every 500ms, but I have tried to use the attach function of the library and use a callback. However, when I do this I am entering the callback and then the mbed stops running. I think I have a problem returning as I my debug led is turning on. I am using 2 separate mbed and so only have RX defined. the code is:

include nRF2401A library with this

#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

DigitalOut  myled(LED1);
DigitalOut  debug(LED2);
#ifdef TX
nRF2401A    rf1(p10, p11, p12, p13, p14);
#endif
#ifdef RX
nRF2401A    rf2(p21, p22, p23, p24, p25);
#endif

Serial pc(USBTX, USBRX);
#ifdef RX
bool rx_recieved = false;
nRF2401A_rx_handler_t nRF2401A_rx ()
{
     //rf2.printDataPacket(pc);
     debug = !debug;
     rx_recieved = true;
     return;
}
#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);

#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.attachRXHandler(nRF2401A_rx(), 0);
#endif
#ifdef TX    
    rf1.flushControlPacket();
#endif
#ifdef RX
    rf2.flushControlPacket();
#endif
#ifdef TX   
    nRF2401A::address_t rf2_addr = {0x0, 0x0, 0x53, 0x53, 0x53};
    uint8_t msg[] = {0x01, 0x01, 0x01, 0x01};
    uint32_t *msg32 = (uint32_t *) msg;
#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);
    }
}

04 Oct 2013

anyone know why the code didn't work?

04 Oct 2013

Can you otherwise publish your code?

No idea why your tags don't work, if I copy it it does work, but of course it doesn't copy the original code and for some reason I cannot quote it either to get the original.

04 Oct 2013

ok Erik, I have commited and published to http://mbed.org/users/TheChrisyd/code/nRF2401A_Hello_World/

Chris

04 Oct 2013

Here are some formatting tips:

<<library http://mbed.org/users/TheChrisyd/code/nRF2401A/>>
&
<<program http://mbed.org/users/TheChrisyd/code/nRF2401A_Hello_World/>>

Import librarynRF2401A

Library for the nRF2401A Transceiver

Import programnRF2401A_Hello_World

Hello world example for the nRF2401A Library

Also, make sure <<code...>> doesnt have any leading or trailing spaces.

04 Oct 2013

Thanks Sam.

06 Oct 2013

OK. I've got it sorted. I'd not declared my function correctly so it wasn't being called by the callback, then called the function instead of passing the address in the attach call. This caused the function to run once. Then I assume go to a random memory location to run code when the callback did occur, although i'd have expected to see the flashing lights at that point..

Going to tidy up the code and try and remove some #ifdefs, then publish..

12 Oct 2013

Week 2 Update

I've tested the Library with the KL25Z and it's working nicely. It still needs some tidying up, but is working and the documentation is looking good.

I've had to change projects as I won't be able to get the Quadcopter I was going to borrow from the local Makerspace as the guy has gone away on business. I've decided to build on work I've done before and build a wireless controller for the Gameduino shield. To get me started with this I've added a component page for both the Gameduino and the on board accelerometer on the KL25Z. I've already had the accelerometer acting as a tilt switch and have translated this into joypad button presses and sent them to the receiving mbed. next step is to add the library to an existing game and decode the messages in to controller commands.

If anyone wants to give me some feedback on anything I've done so far or suggestions on additions, That would be great.

26 Oct 2013

Week 3 & 4 Update

I've added the wireless controller to space invaders for the Gameduino. This has made me hunt down a couple of bugs that we're still remaining in the code i ported across for space invaders from the Arduino. There's still one left, but haven't had chance to look into it yet. it's less important than the others. This also pointed out that the library had no way of reading the message received. I have added two functions to read this data and updated the documentation.

I've also updated the nRF2401A to operate better when going into standby. I've changed the state machine, so when going into standby from TX mode it waits until the transmission is finished. This still needs testing.

I've added a component page, with published programs for both sides of the wireless controller.

09 Feb 2014

Is this the same component as nRF24L01 (and nRF4L01+) ? I have the beginnings of a library at http://mbed.org/users/ianmcc/code/nRF24L01/

It isn't well developed yet, but there is a low-level interface and some drivers for a transmitter and receiver (but not yet transmit and receive at the same time).

My test code, for two nRF24L01 devices connected to the same MBED and passing packets from one to the other (which does work!) is

#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);
   }
}