chipKIT® Development Platform

Inspired by Arduino™

Problem with MajenkoLibraries/nrf24l01

Created Sun, 03 May 2015 06:52:26 +0000 by Seniorlemuren


Seniorlemuren

Sun, 03 May 2015 06:52:26 +0000

I a trying to communicate between 2 Uno32. I have connect like this:

1 GND to GND 2 VCC to 3.3V 3 CE to pin 9 4 CSN to pin 10 5 SCK to pin 13 6 MOSI to pin 11 7 MISO to pin 12 8 IRQ to pin 1 // now changed to pin #2

I use the demoprogram blinkReceiver:

#include <nrf24l01.h>

DSPI0 spi;

// SPI port DSPI0, NCS is pin 10, CE is pin 9 and the interrupt is INT1
nrf24l01 rf(spi, 10, 9, 1);

void setup() {
    // Join mesh number 1, with my address 10,0,0,2 on channel 0.
	rf.begin(1, 10,0,0,2, 0);
	pinMode(PIN_LED1, OUTPUT);
}

void loop() {
	uint8_t buf[32];
	if (rf.available()) {
		rf.readPacket(buf);
		digitalWrite(PIN_LED1, buf[0]);
	}
}

and blinkSender:

#include <nrf24l01.h>

DSPI0 spi;

// SPI port DSPI0, NCS is pin 10, CE is pin 9 and the interrupt is INT1
nrf24l01 rf(spi, 10, 9, 1);

void setup() {
	spi.begin();
    // Join mesh number 1, with my address 10,0,0,1 on channel 0.
	rf.begin(1, 10,0,0,1, 0);
}

void loop() {
    // Packets are 32 bytes in size.
	uint8_t buffer[32];

    // We want to talk to 10,0,0,2 on mesh 1.
	uint8_t dest[5] = {1, 10,0,0,2 };

	buffer[0] = 1;
	rf.queuePacket(dest, buffer);
	delay(100);
	buffer[0] = 0;
	rf.queuePacket(dest, buffer);
	delay(1000);	
}

Both sketches compiled whitout error. I have tried all combinations of master slave settings on the boards but nothing seems to happen. The LED1 is lightning on one of the board whole time and not on the other.

I have tested the nrf24l01 with Arduino Uno against the terminal and all its working. What have I done wrong?


majenko

Sun, 03 May 2015 08:28:11 +0000

You're confusing the interrupt number with a pin number. You need to check the manual for the UNO32 to look which pin INT1 is connected to.

External Interrupts: Pin 38 (INT0), Pin 2 (INT1), Pin 7 (INT2), Pin 8 (INT3), Pin 35 (INT4)

So the IRQ pin needs to be connected to pin 2 to use interrupt number 1.

Also on the UNO32 you cannot use both SPI (which uses pin 13 for the clock) and LED 1 (which is connected to pin 13) at the same time. You will have to use PIN_LED2 instead to stop them interfering.


Seniorlemuren

Sun, 03 May 2015 10:04:50 +0000

Ok Thank you for helping me. I have now change the LED to PIN_LED2 in the blinkReceiver and mowed the IRQ to pin 2 and I put PIN_LED2 HIGH and LOW in blinkSender for check if the loop is running. It is not. The PIN_LED1 on the blinkReceiver is on the whole time after reset and nothing happen.

Is ther some example I could use to just check one of the board against the monitor to se if its working, just like a have done with the Arduino board there i use this chield:

Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 version 2 as published by the Free Software Foundation.
 */

/**
 * Example for Getting Started with nRF24L01+ radios. 
 *
 * This is an example of how to use the RF24 class.  Write this sketch to two 
 * different nodes.  Put one of the nodes into 'transmit' mode by connecting 
 * with the serial monitor and sending a 'T'.  The ping node sends the current 
 * time to the pong node, which responds by sending the value back.  The ping 
 * node can then see how long the whole cycle took.
 */

#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"

//
// Hardware configuration
//

// Set up nRF24L01 radio on SPI bus plus pins 9 & 10 

RF24 radio(9,10);

//
// Topology
//

// Radio pipe addresses for the 2 nodes to communicate.
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };

//
// Role management
//
// Set up role.  This sketch uses the same software for all the nodes
// in this system.  Doing so greatly simplifies testing.  
//

// The various roles supported by this sketch
typedef enum { role_ping_out = 1, role_pong_back } role_e;

// The debug-friendly names of those roles
const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"};

// The role of the current running sketch
role_e role = role_pong_back;

void setup(void)
{
  //
  // Print preamble
  //

  Serial.begin(57600);
  printf_begin();
  printf("\n\rRF24/examples/GettingStarted/\n\r");
  printf("ROLE: %s\n\r",role_friendly_name[role]);
  printf("*** PRESS 'T' to begin transmitting to the other node\n\r");

  //
  // Setup and configure rf radio
  //

  radio.begin();

  // optionally, increase the delay between retries & # of retries
  radio.setRetries(15,15);

  // optionally, reduce the payload size.  seems to
  // improve reliability
  //radio.setPayloadSize(8);

  //
  // Open pipes to other nodes for communication
  //

  // This simple sketch opens two pipes for these two nodes to communicate
  // back and forth.
  // Open 'our' pipe for writing
  // Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading)

  //if ( role == role_ping_out )
  {
    //radio.openWritingPipe(pipes[0]);
    radio.openReadingPipe(1,pipes[1]);
  }
  //else
  {
    //radio.openWritingPipe(pipes[1]);
    //radio.openReadingPipe(1,pipes[0]);
  }

  //
  // Start listening
  //

  radio.startListening();

  //
  // Dump the configuration of the rf unit for debugging
  //

  radio.printDetails();
}

void loop(void)
{
  //
  // Ping out role.  Repeatedly send the current time
  //

  if (role == role_ping_out)
  {
    // First, stop listening so we can talk.
    radio.stopListening();

    // Take the time, and send it.  This will block until complete
    unsigned long time = millis();
    printf("Now sending %lu...",time);
    bool ok = radio.write( &time, sizeof(unsigned long) );
    
    if (ok)
      printf("ok...");
    else
      printf("failed.\n\r");

    // Now, continue listening
    radio.startListening();

    // Wait here until we get a response, or timeout (250ms)
    unsigned long started_waiting_at = millis();
    bool timeout = false;
    while ( ! radio.available() && ! timeout )
      if (millis() - started_waiting_at > 200 )
        timeout = true;

    // Describe the results
    if ( timeout )
    {
      printf("Failed, response timed out.\n\r");
    }
    else
    {
      // Grab the response, compare, and send to debugging spew
      unsigned long got_time;
      radio.read( &got_time, sizeof(unsigned long) );

      // Spew it
      printf("Got response %lu, round-trip delay: %lu\n\r",got_time,millis()-got_time);
    }

    // Try again 1s later
    delay(1000);
  }

  //
  // Pong back role.  Receive each packet, dump it out, and send it back
  //

  if ( role == role_pong_back )
  {
    // if there is data ready
    if ( radio.available() )
    {
      // Dump the payloads until we've gotten everything
      unsigned long got_time;
      bool done = false;
      while (!done)
      {
        // Fetch the payload, and see if this was the last one.
        done = radio.read( &got_time, sizeof(unsigned long) );

        // Spew it
        printf("Got payload %lu...",got_time);

	// Delay just a little bit to let the other unit
	// make the transition to receiver
	delay(20);
      }

      // First, stop listening so we can talk
      radio.stopListening();

      // Send the final one back.
      radio.write( &got_time, sizeof(unsigned long) );
      printf("Sent response.\n\r");

      // Now, resume listening so we catch the next packets.
      radio.startListening();
    }
  }

  //
  // Change roles
  //

  if ( Serial.available() )
  {
    char c = toupper(Serial.read());
    if ( c == 'T' && role == role_pong_back )
    {
      printf("*** CHANGING TO TRANSMIT ROLE -- PRESS 'R' TO SWITCH BACK\n\r");

      // Become the primary transmitter (ping out)
      role = role_ping_out;
      radio.openWritingPipe(pipes[0]);
      radio.openReadingPipe(1,pipes[1]);
    }
    else if ( c == 'R' && role == role_ping_out )
    {
      printf("*** CHANGING TO RECEIVE ROLE -- PRESS 'T' TO SWITCH BACK\n\r");
      
      // Become the primary receiver (pong back)
      role = role_pong_back;
      radio.openWritingPipe(pipes[1]);
      radio.openReadingPipe(1,pipes[0]);
    }
  }
}
// vim:cin:ai:sts=2 sw=2 ft=cpp

majenko

Sun, 03 May 2015 11:11:08 +0000

It sounds like it may be failing to communicate with the module. There's a bit in the transmission routine that waits until it's finished transmitting the last packet before it sends the next packet. That transmitting status is changed by the interrupt routine, so if the interrupt isn't getting picked up it will never exit the previous transmission state.

That could be because of the interrupt not being caught, or because the module isn't being properly communicated within the first place.

Double check all your wiring, and if you can, post a picture of it on here so I can double-check it.


Seniorlemuren

Sun, 03 May 2015 12:51:35 +0000

Thank you. I have checked the wiring and it is as I listed it in my first post. (changed IRQ to pin 2). Anyway. Is it Ok that the sender should be strapped as Master and the receiver as Slave? I have tried all possibility's), could that have done some corruption to the board if it was wrong strapped?

Another thing I thought of was when I installed the library nrf24l01 and tried to compile the example I have the error missing the DSPI.h file. I found that library in the map "mpide/hardware/pic32/libraries/DSPI" so I copied the map DSPI to the MPIDE/libraries. Then the error disappeared. Could that DSPI library be some wrong version?

I think it would have been fine with a program snippet where I could ping data from nrf24l01 to the Serial Monitor. It is easier to test one device at a time. Unfortunately, I do not know how to write such a program, but I must continue studying and learn.

[attachment=0]chipkit32_board.jpg[/attachment] [attachment=1]nrf24l01_1.jpg[/attachment] [attachment=2]nrf24l01_2.jpg[/attachment]


majenko

Sun, 03 May 2015 13:02:51 +0000

They should all be set to SPI Master. The SPI mode is to do with the UNO32 (master) talking to the nRF module (slave).