Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: Is SPI different on Nano and Teensy 3.1?

  1. #1

    Is SPI different on Nano and Teensy 3.1?

    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 by Blitter; 06-05-2015 at 04:10 AM.

  2. #2
    Found it. Looks like a classic 8-bit to 32-bit problem (Nano to Teensy)
    https://forum.pjrc.com/threads/24940...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 by Blitter; 06-06-2015 at 07:03 AM.

  3. #3
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,931
    Nice work finding an answer there. If what you have is working don't break it and carry on, but believe the radio head libraries are generally used for the nrfs to get the full feature set

    http://www.airspayce.com/mikem/arduino/RadioHead/

  4. #4
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    11,929
    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...ll=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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •