Is SPI different on Nano and Teensy 3.1?

Status
Not open for further replies.

Blitter

Member
I have a Nano, and a Teensy 3.1
Both have the RF24L01+ modules wired to the same pins and are both running this RF receiver sketch:

Code:
#include <SPI.h>
#include <Wire.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <printf.h>

// D7      CE    (SPI)  RF24
// D8      CSN   (SPI)  RF24
// D11     MOSI  (SPI)  RF24
// D12     MISO  (SPI)  RF24
// D13     SCK   (SPI)  RF24

// RF 24
RF24 radio(7,8);
const uint64_t pipe = 0xE8E8F0F0E1LL; // Send and receive share the same pipe for now)
struct dataStruct{int command; int value;}myData;

void setup() 
{
  Serial.begin(9600);       
  Serial.println("Startup...");    
  
  // RF24 Radio Setup
  radio.begin();
  radio.setPALevel(RF24_PA_MAX);  
  radio.setRetries(15,15);  
  radio.setDataRate(RF24_250KBPS);
  radio.setRetries(0,2); // Retry 2 times with 250us delay between retries.  
  radio.openReadingPipe(1,pipe); 
  radio.openWritingPipe(pipe);  
  radio.startListening();  

  printf_begin();  
  radio.printDetails();  // dumps the radio data (to see if it is even connected)
}


void loop(void) 
{
  if (radio.available())
  {
    Serial.println("I see something...");  
    //radio.printDetails();  // dumps the radio data (to see if it is even connected)    
    GetRadioData();
  }
}

void GetRadioData(void)
{
  // Serial.println("Getting radio message");

   bool tx,fail,rx;
   radio.whatHappened(tx,fail,rx);                     // What happened?
   if (rx)
   {   
     while (radio.available()) // While there is data ready
     {                          
        radio.read(&myData, sizeof(myData));             // Get the payload
     }
   } 
    
   Serial.print("Command:");
   Serial.print(myData.command);
   Serial.println("");
   Serial.print("Value:");
   Serial.print(myData.value);
   Serial.println("");    
 }

Both are connected to RF24L01+ modules (same batch, same vendor)
When each receives the same data, they display different results. What did I do wrong?

Nano displays the radio.printDetails() from Setup() along with:
Code:
I see something...
Command:66
Value:89

Teensy won't display the radio.printDetail() and only displays:
Code:
I see something...
Command:5832770
Value:0


The (simplified) Sending code on the transmitting device looks like this:
Code:
    struct dataStruct{int command; int value;}myData;

    radio.stopListening();                              
    myData.command = 66;
    myData.value = 89;  
    radio.write( &myData, sizeof(myData) );   
    radio.startListening();

I'm guessing that the Teensy handles Serial.printLn() differently, or sees the data on the SPI differently? Any clues?
 
Last edited:
Found it. Looks like a classic 8-bit to 32-bit problem (Nano to Teensy)
https://forum.pjrc.com/threads/24940-Teensy-3-1-nrf24l01-issue

Also, the nondisplay of serial printing in Startup() was because I didn't give it enough time for Serial to initialize before calling Serial.begin(9600). This isn't needed for the slower 8-bit Nanos , but for the speedy Teensy 3.1, I need to call this first:
Code:
while (!Serial);
 
Last edited:
As far as the while to wait for Serial - if you ever try to run that without USB it will stay there forever with no sign of life.

I found something like this to work well it waits until 6 seconds after starting as written - including qBlink() blinking the LED to show it is ready:

https://forum.pjrc.com/threads/28526-Teensy3-1-losing-my-application?p=72095&viewfull=1#post72095

You'll see qBlink() uses the FAST Read and Write and in this case just toggles the current state, so you just call it when you want to see it change. Unless ON or OFF, faster calls are brighter.

Please post if you get the nRF24 working, I didn't right off and got distracted by another (ESP-8266) that I won't have for some time now it seems as I opted for the OAK on KickStarter - so 1 Beta unit in July and the rest September.
 
Status
Not open for further replies.
Back
Top