Teensy++ 2.0 seems to hang unless I close and re-open serial monitor.

Status
Not open for further replies.

JayStephenson

New member
I have a setup that uses a Teensy 3.0 to send data over an nRF24L01 to another Teensy++ 2.0 that receives it using the same type of nRF24L01. I'm using the Mirf libraries and the demo client and server programs and I'm seeing a strange issue. On the receiving teensy, it seems to hang unless I open the serial monitor, it will work for a bit, then stop receiving data again unless I close and re-open the serial monitor again. It's configured as usb type midi. I've tried removing all of the Serial stuff and it doesn't seem to help. Any ideas?

Thanks,
Jay
 
Can you get it to hang if you replace the nRF24L01 with some dummy code? In other words, with a small sample program that doesn't depend on the rest of the hardware.... something you could post here and I could try on a Teensy++ 2.0 to reproduce the problem.....
 
Can you get it to hang if you replace the nRF24L01 with some dummy code? In other words, with a small sample program that doesn't depend on the rest of the hardware.... something you could post here and I could try on a Teensy++ 2.0 to reproduce the problem.....

Thanks Paul, here is the code, basically the Mirf examples minus the comments. I added a count that gets printed out on the server side when it receives data so I can tell where it stops.

I'll try your suggestion and get back to you. BTW I'm on Windows 7 64 bit if that matters.

Jay


This is my ping_client code on teensy 3.0

Code:
#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>

void setup(){
  Serial.begin(9600);
  Mirf.cePin = 9;
  Mirf.csnPin = 10;

  Mirf.spi = &MirfHardwareSpi;
  Mirf.init();
  Mirf.setRADDR((byte *)"clie1");
  Mirf.payload = sizeof(unsigned long);
  Mirf.config();
  Serial.println("Beginning ... "); 
}

void loop(){
  unsigned long time = millis();
  Mirf.setTADDR((byte *)"serv1");
  Mirf.send((byte *)&time);

  while(Mirf.isSending()){
  }
  Serial.println("Finished sending");
  delay(10);
  while(!Mirf.dataReady()){
    //Serial.println("Waiting");
    if ( ( millis() - time ) > 1000 ) {
      Serial.println("Timeout on response from server!");
      return;
    }
  }

  Mirf.getData((byte *) &time);

  Serial.print("Ping: ");
  Serial.println((millis() - time));

  delay(1000);
} 

#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>

void setup(){
  Serial.begin(9600);
  Mirf.cePin = 9;
  Mirf.csnPin = 10;

  Mirf.spi = &MirfHardwareSpi;
  Mirf.init();
  Mirf.setRADDR((byte *)"clie1");
  Mirf.payload = sizeof(unsigned long);
  Mirf.config();
  Serial.println("Beginning ... "); 
}

void loop(){
  unsigned long time = millis();
  Mirf.setTADDR((byte *)"serv1");
  Mirf.send((byte *)&time);

  while(Mirf.isSending()){
  }
  Serial.println("Finished sending");
  delay(10);
  while(!Mirf.dataReady()){
    //Serial.println("Waiting");
    if ( ( millis() - time ) > 1000 ) {
      Serial.println("Timeout on response from server!");
      return;
    }
  }

  Mirf.getData((byte *) &time);

  Serial.print("Ping: ");
  Serial.println((millis() - time));

  delay(1000);
}


This is my ping_server code on teensy++ 2.0


Code:
#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>

void setup(){
  Serial.begin(9600);
  Mirf.spi = &MirfHardwareSpi;
  Mirf.init();
  Mirf.setRADDR((byte *)"serv1");
  Mirf.payload = sizeof(unsigned long);
  Mirf.config();
  Serial.println("Listening..."); 
}


int count;
void loop(){
  byte data[Mirf.payload];
  if(!Mirf.isSending() && Mirf.dataReady()){
    Serial.println("Got packet");
    Mirf.getData(data);
    count++;
    Mirf.setTADDR((byte *)"clie1");
    Mirf.send(data);
    Serial.println(count);
    Serial.println("Reply sent.");
  }
}
 
Putting an electrolytic cap on the 3.3v supply to the nRF24L01 appears to have solved it. It would stop receiving data and the Mirf.dataReady() never returned true.
 
Status
Not open for further replies.
Back
Top