9 years ago.

KL25Z RF24 sending data to Uno with RF24 woes.

Ok, I have a simple project in mind, send data with an RF24 module to an Uno. Easy right? Nope! I just need to send 6 values (left, right, up, down, fast, slow), but for the life of me I cannot get them to communicate with each other. I've been working four days on and off without avail, I'm tired of this, and I came here for help. This is probably a simple solution, right under my nose, but I cannot find it. I've set the KL25Z to output and the Uno to input, both pipes match, etc. Here is the code I am using on the Uno:

Arduino Uno's code

#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>
 
/*
This sketch receives strings from sending unit via nrf24 
and prints them out via serial.  The sketch waits until
it receives a specific value (2 in this case), then it 
prints the complete message and clears the message buffer.
*/
 
int msg[1];
RF24 radio(9,10);
const uint64_t pipe =  0x00F0F0F0F0;
int lastmsg = 1;
String theMessage = "";
void setup(void){
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(1,pipe);
  radio.startListening();
}
void loop(void){
  if (radio.available()){
    unsigned short rawMessage;

    bool done = false;  
     // done = radio.read(msg, 1); 
      char theChar = msg[0];
      if (msg[0] != 2){
        theMessage.concat(theChar);
        }
      else {
       Serial.println(theMessage);
       theMessage= "HI"; 
      }
   }
}

This is the code on the KL25Z:

KL25Z code

#include "mbed.h"
#include "nRF24L01P.h"
#include <string> 

Serial pc(USBTX, USBRX); // tx, rx

nRF24L01P my_nrf24l01p(PTD2, PTD3, PTD1, PTD13, PTD5, PTD0);    // mosi, miso, sck, csn, ce, irq

DigitalOut myled1(LED1);
DigitalOut myled2(LED2);
string theMessage;
char msg[1];
int main() {

// The nRF24L01+ supports transfers from 1 to 32 bytes, but Sparkfun's
//  "Nordic Serial Interface Board" (http://www.sparkfun.com/products/9019)
//  only handles 4 byte transfers in the ATMega code.
#define TRANSFER_SIZE   4



    my_nrf24l01p.powerUp();

    // Display the (default) setup of the nRF24L01+ chip
    pc.printf( "nRF24L01+ Frequency    : %d MHz\r\n",  my_nrf24l01p.getRfFrequency() );
    pc.printf( "nRF24L01+ Output power : %d dBm\r\n",  my_nrf24l01p.getRfOutputPower() );
      pc.printf( "nRF24L01+ Data Rate    : %d kbps\r\n", my_nrf24l01p.getAirDataRate() );
//  pc.printf( "nRF24L01+ TX Address   : 0x%010llX\r\n", my_nrf24l01p.getTxAddress() );
 //  pc.printf( "nRF24L01+ RX Address   : 0x%010llX\r\n", my_nrf24l01p.getRxAddress() );

    pc.printf( "Type keys to test transfers:\r\n  (transfers are grouped into %d characters)\r\n", TRANSFER_SIZE );

    my_nrf24l01p.powerUp();
    my_nrf24l01p.enable();
    my_nrf24l01p.setTxAddress(0x00F0F0F0F);
    while (1) {

        // If we've received anything over the host serial link...
  
     
     theMessage = "Hello there!";
  int messageSize = theMessage.length();
  for (int i = 0; i < messageSize; i++) {
    char charToSend[1];
    charToSend[0] = theMessage.at(i);
        my_nrf24l01p.write(0x00F0F0F0F,charToSend,1);
  }  
  msg[0] = 2; 
  radio.write(msg,1);
/*delay sending for a short period of time.  radio.powerDown()/radio.powerupp
//with a delay in between have worked well for this purpose(just using delay seems to
//interrupt the transmission start). However, this method could still be improved
as I still get the first character 'cut-off' sometimes. I have a 'checksum' function
on the receiver to verify the message was successfully sent.
*/
  radio.powerDown(); 
  delay(1000);
  radio.powerUp();

  
}

        

        

        // If we've received anything in the nRF24L01+...
     /*   if ( my_nrf24l01p.readable() ) {

            // ...read the data into the receive buffer
            rxDataCnt = my_nrf24l01p.read( NRF24L01P_PIPE_P0, rxData, sizeof( rxData ) );

            // Display the receive buffer contents via the host serial link
            for ( int i = 0; rxDataCnt > 0; rxDataCnt--, i++ ) {

                pc.putc( rxData[i] );
            }

            // Toggle LED2 (to help debug nRF24L01+ -> Host communication)
            myled2 = !myled2;
        }
    }*/
}

1 Answer

9 years ago.

Hi,

May be this is not crucial,
but I suggest you to use PTA13 instead of PTD13.

moto

I'll give it a whirl

posted by Keaton Burleson 07 Apr 2015

Ok, just tried, and same problem, serial monitor is empty, no data :*(

posted by Keaton Burleson 07 Apr 2015

Aw screw it, this KL25Z was a waste of $20, a lack of good libraries has ruined it for me. Unless anymore ideas are had, its off to the bin.

posted by Keaton Burleson 07 Apr 2015

Oh, I'm sorry that I could not be of any help.
If you decided to give up, rest is nothing but my memo(s).

I compiled your code with FRDM-KL25Z, I had to comment out
lines with radio. but otherwise compile was done and
first few messages were printed.
But as I do not have the RF board, I could not go farther.

Some other things I noticed is that IRQ won't be taken care of
with this setup, so it might be better to leave the IRQ position blank.

Then if you have access to an Oscilloscope check SCLK, MOSI
that SPI is doing its job as well as if cs/ce are asserted.
Meantime, probably double checking connections between
FRDM-KL25Z and the FR board will be a good idea.
There could be a lot to do to track the problem down,
but let's call it a day for now ;-)

moto

posted by Motoo Tanaka 07 Apr 2015

moto, I'm trying to stick with it since my other idea isn't panning out very well. I don't have an Oscilloscope, but I'll do some more work later today on the issue.

posted by Keaton Burleson 07 Apr 2015