unplugged USB cable leads to waitPacketSent failed

138 views
Skip to first unread message

Jake L. Tag

unread,
Feb 27, 2014, 10:02:37 AM2/27/14
to nrf24-...@googlegroups.com
Hello Mike and all who read this post,

I have connected two NRF24 modules to each its own arduino (duemilanove), and each arduino is connected to its own computer. One is loaded with nrf24_ping_client.ino, the other with nrf24_ping_server.ino. At first everything works as it should: ping is about 1 ms, range is through my entire house.

But then: I unplugged the USB-cable on one computer while the Arduino IDE is open and the arduino with the NRF is connected. This results in an error in the Arduino IDE (cannot find COM port and such). Usually no problem: close all Arduino IDE windows, reconnect USB cable, restart Arduino IDE. But then I get:

initialised
waitPacketSent failed
No reply from server
(repeatedly)

Reuploading the code to the arduino does not help. Restarting the computer does not help.

I uploaded the code for a poor mans scanner (http://forum.arduino.cc/index.php?topic=54795.0) to test my NRF: the module works. Then I upload the nrf24_ping_client code: it works again!

I do not understand. Until now disconnecting power to an Arduino and restarting it always returns it to the initial state, but now that does not seem the case. I hope someone can shed some light on this.

Attached the code for the poor mans scanner.

Cheers,

Jack



 
// <code>
#include <SPI.h>

// Poor Man's Wireless 2.4GHz Scanner
//
// uses an nRF24L01p connected to an Arduino
// 
// Cables are:
//     SS       -> 10
//     MOSI     -> 11
//     MISO     -> 12
//     SCK      -> 13
// 
// and CE       ->  9
//
// created March 2011 by Rolf Henkel
//

#define CE  9

// Array to hold Channel data
#define CHANNELS  64
int channel[CHANNELS];

// greyscale mapping 
int  line;
char grey[] = " .:-=+*aRW";

// nRF24L01P registers we need
#define _NRF24_CONFIG      0x00
#define _NRF24_EN_AA       0x01
#define _NRF24_RF_CH       0x05
#define _NRF24_RF_SETUP    0x06
#define _NRF24_RPD         0x09

// get the value of a nRF24L01p register
byte getRegister(byte r)
{
  byte c;
  
  PORTB &=~_BV(2);
  c = SPI.transfer(r&0x1F);
  c = SPI.transfer(0);  
  PORTB |= _BV(2);

  return(c);
}

// set the value of a nRF24L01p register
void setRegister(byte r, byte v)
{
  PORTB &=~_BV(2);
  SPI.transfer((r&0x1F)|0x20);
  SPI.transfer(v);
  PORTB |= _BV(2);
}
  
// power up the nRF24L01p chip
void powerUp(void)
{
  setRegister(_NRF24_CONFIG,getRegister(_NRF24_CONFIG)|0x02);
  delayMicroseconds(130);
}

// switch nRF24L01p off
void powerDown(void)
{
  setRegister(_NRF24_CONFIG,getRegister(_NRF24_CONFIG)&~0x02);
}

// enable RX 
void enable(void)
{
    PORTB |= _BV(1);
}

// disable RX
void disable(void)
{
    PORTB &=~_BV(1);
}

// setup RX-Mode of nRF24L01p
void setRX(void)
{
  setRegister(_NRF24_CONFIG,getRegister(_NRF24_CONFIG)|0x01);
  enable();
  // this is slightly shorter than
  // the recommended delay of 130 usec
  // - but it works for me and speeds things up a little...
  delayMicroseconds(100);
}

// scanning all channels in the 2.4GHz band
void scanChannels(void)
{
  disable();
  for( int j=0 ; j<200  ; j++)
  {
    for( int i=0 ; i<CHANNELS ; i++)
    {
      // select a new channel
      setRegister(_NRF24_RF_CH,(128*i)/CHANNELS);
      
      // switch on RX
      setRX();
      
      // wait enough for RX-things to settle
      delayMicroseconds(40);
      
      // this is actually the point where the RPD-flag
      // is set, when CE goes low
      disable();
      
      // read out RPD flag; set to 1 if 
      // received power > -64dBm
      if( getRegister(_NRF24_RPD)>0 )   channel[i]++;
    }
  }
}

// outputs channel data as a simple grey map
void outputChannels(void)
{
  int norm = 0;
  
  // find the maximal count in channel array
  for( int i=0 ; i<CHANNELS ; i++)
    if( channel[i]>norm ) norm = channel[i];
    
  // now output the data
  Serial.print('|');
  for( int i=0 ; i<CHANNELS ; i++)
  {
    int pos;
    
    // calculate grey value position
    if( norm!=0 ) pos = (channel[i]*10)/norm;
    else          pos = 0;
    
    // boost low values
    if( pos==0 && channel[i]>0 ) pos++;
    
    // clamp large values
    if( pos>9 ) pos = 9;
   
    // print it out
    Serial.print(grey[pos]);
    channel[i] = 0;
  }
  
  // indicate overall power
  Serial.print("| ");
  Serial.println(norm);
}

// give a visual reference between WLAN-channels and displayed data
void printChannels(void)
{
  // output approximate positions of WLAN-channels
  Serial.println(">      1 2  3 4  5  6 7 8  9 10 11 12 13  14                     <");
}

void setup()
{
  Serial.begin(57600);
  
  Serial.println("Starting Poor Man's Wireless 2.4GHz Scanner ...");
  Serial.println();

  // Channel Layout
  // 0         1         2         3         4         5         6
  // 0123456789012345678901234567890123456789012345678901234567890123
  //       1 2  3 4  5  6 7 8  9 10 11 12 13  14                     | 
  //
  Serial.println("Channel Layout");
  printChannels();
  
  // Setup SPI
  SPI.begin();
  SPI.setDataMode(SPI_MODE0);
  SPI.setClockDivider(SPI_CLOCK_DIV2);
  SPI.setBitOrder(MSBFIRST);
  
  // Activate Chip Enable
  pinMode(CE,OUTPUT);
  disable();
  
  // now start receiver
  powerUp();
  
  // switch off Shockburst
  setRegister(_NRF24_EN_AA,0x0);
  
  // make sure RF-section is set properly 
  // - just write default value... 
  setRegister(_NRF24_RF_SETUP,0x0F); 
  
  // reset line counter
  line = 0;
}

void loop() 
  // do the scan
  scanChannels();
  
  // output the result
  outputChannels();
  
  // output WLAN-channel reference every 12th line
  if( line++>12 )
  {
    printChannels();
    line = 0;
  }
}
// </code>

Jake L. Tag

unread,
Feb 27, 2014, 10:05:22 AM2/27/14
to nrf24-...@googlegroups.com
I might mention:

it responds in the same way if you disconnect and reconnect the Arduino to your computer, even if the Arduino IDE is closed.

Jack

Colin Cooper

unread,
Feb 27, 2014, 10:07:21 AM2/27/14
to nrf24-...@googlegroups.com
Was it the client you disconnected?  Have you restarted the server since then (could the server be locked up)?


--
You received this message because you are subscribed to the Google Groups "NRF24-Arduino" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nrf24-arduin...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Jake L. Tag

unread,
Feb 27, 2014, 10:26:52 AM2/27/14
to nrf24-...@googlegroups.com, cdcoo...@googlemail.com
It was the client I disconnected. I have never touched the server since, however: after uploading the poor mans scanner, followed by uploading the client side, the client works again! server side has not been touched.

To be sure I just tried it: restarting the server makes no difference. Moving the client to another computer: no difference.

I am truly puzzled...

Jack

Jake L. Tag

unread,
Feb 27, 2014, 1:40:30 PM2/27/14
to nrf24-...@googlegroups.com, cdcoo...@googlemail.com
I have been comparing codes between the poor mans scanner and the library. It appears that if I add:

    spiWriteRegister(NRF24_REG_01_EN_AA,B00000011);

to the library function

    boolean NRF24::init()

just before the last line

    return powerUpRx();

it all seems to work. If I disconnect the module in any way (remove it from the breadboard, disconnect arduino), whenever I reconnect or restart the system it will work again. I think what the line of code does is to enable ACK on data pipes 0 and 1. I'm reading the datasheet that comes with the NRF chip, but it's quite a read, so I can't say I fully understand all of it as of yet.

Now I'm wondering why at first the setup worked without this line, but the line is needed after a single disconnect...

Cheers,

Jack

Mike McCauley

unread,
Feb 27, 2014, 5:18:41 PM2/27/14
to nrf24-...@googlegroups.com, Jake L. Tag, cdcoo...@googlemail.com
Do you get the same behaviour if you reset he arduino with its reset button,
as opposed to powering it down?

Cheers.

On Thursday, February 27, 2014 07:26:52 AM Jake L. Tag wrote:
> It was the client I disconnected. I have never touched the server since,
> however: after uploading the poor mans scanner, followed by uploading the
> client side, the client works again! server side has not been touched.
>
> To be sure I just tried it: restarting the server makes no difference.
> Moving the client to another computer: no difference.
>
> I am truly puzzled...
>
> Jack
>
> On Thursday, February 27, 2014 4:07:21 PM UTC+1, Colin Cooper wrote:
> > Was it the client you disconnected? Have you restarted the server since
> > then (could the server be locked up)?
> >
> >
> > On 27 February 2014 15:02, Jake L. Tag <laserta...@gmail.com <javascript:>
> >> You received this message because you are subscribed to the Google Groups
> >> "NRF24-Arduino" group.
> >> To unsubscribe from this group and stop receiving emails from it, send an
> >> email to nrf24-arduin...@googlegroups.com <javascript:>.
> >> For more options, visit https://groups.google.com/groups/opt_out.
--
Mike McCauley VK4AMM mi...@airspayce.com
Airspayce Pty Ltd 9 Bulbul Place Currumbin Waters QLD 4223 Australia
http://www.airspayce.com
Phone +61 7 5598-7474 Fax +61 7 5598-7070

Mike McCauley

unread,
Feb 27, 2014, 5:21:55 PM2/27/14
to nrf24-...@googlegroups.com
Hello,

That is very odd, because the default power-up behaviour of the chip is
specified as having AA on P0 through P5 to be enabled.
> >>> You received this message because you are subscribed to the Google
> >>> Groups "NRF24-Arduino" group.
> >>> To unsubscribe from this group and stop receiving emails from it, send
> >>> an email to nrf24-arduin...@googlegroups.com.
> >>> For more options, visit https://groups.google.com/groups/opt_out.

Jake L. Tag

unread,
Feb 27, 2014, 5:28:08 PM2/27/14
to nrf24-...@googlegroups.com
Yes, pressing the reset button on the arduino gives the same behaviour.

The NRF I use is:


However, I have also used something like


but they both yield the same results.

The weird thing is: at first go everything functions, but after a disconnect it seems like the chip remembers not to turn it on, but I can not see sense in that.

Cheers,

Jack

Colin Cooper

unread,
Feb 27, 2014, 7:19:49 PM2/27/14
to nrf24-...@googlegroups.com
It might be interesting to add an spiReadRegister(NRF24_REG_01_EN_AA) at the start & log it somewhere, just to see what state is present at startup.

I did wonder if you might have a circuit powering to the module even when disconnected from usb, but if the issue happens with reset, I guess that isn't a possibility.

So my next thought is: could the server be refusing to send to the client because its MAX_RT flag is set?  Is there any way to schedule a periodic register dump on the server?

  Regards,
  Colin


--

Jake L. Tag

unread,
Feb 28, 2014, 3:40:13 AM2/28/14
to nrf24-...@googlegroups.com, cdcoo...@googlemail.com
A read of the register shows sometimes EN_AA is not set to 63, however 63 seems to be de default value.

I don't think there is any problem with the server, it keeps stable throughout the entire excercise.

However: I woke up this morning, added a line to read the register, everything works, I can't reproduce the error... even without extra code everything works. I'm flabbergasted.

Cheers,

Jack

Mike McCauley

unread,
Mar 2, 2014, 7:19:12 PM3/2/14
to nrf24-...@googlegroups.com, Jake L. Tag, cdcoo...@googlemail.com
Hello,

Testing the latest version here (1.10) I cant reproduce this problem.
ping_client fires up fine every time after reset or powerup.

Cheers.


On Friday, February 28, 2014 12:40:13 AM Jake L. Tag wrote:
> A read of the register shows sometimes EN_AA is not set to 63, however 63
> seems to be de default value.
>
> I don't think there is any problem with the server, it keeps stable
> throughout the entire excercise.
>
> However: I woke up this morning, added a line to read the register,
> everything works, *I can't reproduce the error...* even without extra code
> everything works. I'm flabbergasted.
>
> Cheers,
>
> Jack
>
> On Friday, February 28, 2014 1:19:49 AM UTC+1, Colin Cooper wrote:
> > It might be interesting to add an spiReadRegister(NRF24_REG_01_EN_AA) at
> > the start & log it somewhere, just to see what state is present at
> > startup.
> >
> > I did wonder if you might have a circuit powering to the module even when
> > disconnected from usb, but if the issue happens with reset, I guess that
> > isn't a possibility.
> >
> > So my next thought is: could the server be refusing to send to the client
> > because its MAX_RT flag is set? Is there any way to schedule a periodic
> > register dump on the server?
> >
> > Regards,
> > Colin
> >
> > On 27 February 2014 22:28, Jake L. Tag <laserta...@gmail.com <javascript:>
> >> email to nrf24-arduin...@googlegroups.com <javascript:>.

Jake L. Tag

unread,
Mar 8, 2014, 4:03:37 AM3/8/14
to nrf24-...@googlegroups.com, Jake L. Tag, cdcoo...@googlemail.com
Hello Mike,

thank you for your time, very kind. I have been testing for a week now a it still works :) I don't understand what went wrong initially. I will now incorporate the code into my project and see how it goes.

Cheers,

Jack
Reply all
Reply to author
Forward
0 new messages