TEENSY 4.1, proper SCK pin question

Status
Not open for further replies.

theDVSguy

Active member
Hello, Does anyone know the proper pin for the SCK line from a teensy 4.1 to an NRF24 module ?
I thought it was pin 13 but it seems when I use that pin the module works but I am getting errors but when I leave SCK unhooked from the Teensy, the nrf24 module looks offline .....here is the results I get below

nrf24 SCK - > 13 unplugged

13:33:15.886 -> RF24/examples/GettingStarted
13:33:15.886 -> *** PRESS 'T' to begin transmitting to the other node
13:33:15.886 -> SPI Speedz = 10 Mhz
13:33:15.886 -> STATUS = 0x00 RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=0 TX_FULL=0
13:33:15.886 -> RX_ADDR_P0-1 = 0x0000000000 0x0000000000
13:33:15.886 -> RX_ADDR_P2-5 = 0x00 0x00 0x00 0x00
13:33:15.886 -> TX_ADDR = 0x0000000000
13:33:15.886 -> RX_PW_P0-6 = 0x00 0x00 0x00 0x00 0x00 0x00
13:33:15.886 -> EN_AA = 0x00
13:33:15.886 -> EN_RXADDR = 0x00
13:33:15.886 -> RF_CH = 0x00
13:33:15.886 -> RF_SETUP = 0x00
13:33:15.886 -> CONFIG = 0x00
13:33:15.886 -> DYNPD/FEATURE = 0x00 0x00
13:33:15.886 -> Data Rate = 1MBPS
13:33:15.886 -> Model = nRF24L01
13:33:15.886 -> CRC Length = Disabled
13:33:15.886 -> PA Power = PA_MIN
13:33:15.886 -> Now sending
13:33:15.979 -> failed
13:33:15.979 -> Sent 7274202, Got response 0, Round-trip delay 100928 microseconds
13:33:17.011 -> Now sending
13:33:17.104 -> failed
13:33:17.104 -> Sent 8375444, Got response 0, Round-trip delay 95679 microseconds
13:33:18.089 -> Now sending
13:33:18.183 -> failed
13:33:18.183 -> Sent 9471437, Got response 0, Round-trip delay 95690 microseconds


nrf24 SCK - > 13 plugged

13:34:32.031 -> RF24/examples/GettingStarted
13:34:32.031 -> *** PRESS 'T' to begin transmitting to the other node
13:34:32.031 -> SPI Speedz = 10 Mhz
13:34:32.031 -> STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
13:34:32.031 -> RX_ADDR_P0-1 = 0x3a00000101 0x3130303030
13:34:32.031 -> RX_ADDR_P2-5 = 0xc3 0xc4 0xc5 0xc6
13:34:32.031 -> TX_ADDR = 0x3a00000101
13:34:32.031 -> RX_PW_P0-6 = 0x20 0x20 0x00 0x00 0x00 0x00
13:34:32.031 -> EN_AA = 0x00
13:34:32.031 -> EN_RXADDR = 0x02
13:34:32.031 -> RF_CH = 0x4c
13:34:32.031 -> RF_SETUP = 0x21
13:34:32.031 -> CONFIG = 0x0f
13:34:32.031 -> DYNPD/FEATURE = 0x00 0x00
13:34:32.031 -> Data Rate = 250KBPS
13:34:32.031 -> Model = nRF24L01+
13:34:32.031 -> CRC Length = 16 bits
13:34:32.031 -> PA Power = PA_MIN
13:34:32.031 -> Now sending
13:34:32.265 -> Failed, response timed out.
13:34:33.249 -> Now sending
13:34:33.437 -> Failed, response timed out.
13:34:34.468 -> Now sending
13:34:34.656 -> Failed, response timed out.
 
Also my pins are
CE = pin7
CSN = pin8
SCK = pin13
MO = pin11
MI = pin12
IRQ = no pin

Arduino Lib RF24 1.3.9
 
Last edited:
I'm pretty sure the problem is that the Tx and Rx aren't using the same addresses.
In both the Rx and Tx use this for the addresses:
Code:
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };

In the Rx:
Code:
  radio.openWritingPipe(pipes[0]);
  radio.openReadingPipe(1, pipes[1]);

and in Tx:
Code:
  radio.openWritingPipe(pipes[1]);
  radio.openReadingPipe(1, pipes[0]);

Pete
 
Thanks for the help but Im unclear.

I have this specified in both

byte addresses[][6] = {"00001"};

what do I need to edit in this ?

// Open a writing and reading pipe on each radio, with opposite addresses
if(radioNumber){
radio.openWritingPipe(addresses[1]);
radio.openReadingPipe(1,addresses[0]);
}else{
radio.openWritingPipe(addresses[0]);
radio.openReadingPipe(1,addresses[1]);
}

Thanks
 
If these are the details of my radio

18:08:20.653 -> SPI Speedz = 10 Mhz
18:08:20.653 -> STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
18:08:20.653 -> RX_ADDR_P0-1 = 0x3a00000001 0x3130303030
18:08:20.653 -> RX_ADDR_P2-5 = 0x00 0x00 0x00 0x71
18:08:20.653 -> TX_ADDR = 0x3a00000001
18:08:20.653 -> RX_PW_P0-6 = 0x20 0x20 0x00 0x00 0x00 0x00
18:08:20.653 -> EN_AA = 0x00
18:08:20.653 -> EN_RXADDR = 0x02
18:08:20.653 -> RF_CH = 0x4c
18:08:20.653 -> RF_SETUP = 0x71
18:08:20.653 -> CONFIG = 0x0f
18:08:20.653 -> DYNPD/FEATURE = 0x00 0x00
18:08:20.653 -> Data Rate = 250KBPS
18:08:20.653 -> Model = nRF24L01+
18:08:20.653 -> CRC Length = 16 bits
18:08:20.653 -> PA Power = PA_MIN


Should I change it to this ?

const uint64_t addresses[2] = { 0x3130303030LL, 0x3a00000001LL };
 
Here is my updated code


/*
* Getting Started example sketch for nRF24L01+ radios
* This is a very basic example of how to send data from one node to another
* Updated: Dec 2014 by TMRh20
*/

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


//#define RF24_MOSI 11
//#define RF24_MISO 12
//#define RF24_SCLK 14



/****************** User Config ***************************/
/*** Set this radio as radio number 0 or 1 ***/
bool radioNumber = 1;

/* Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 7 & 8 */
RF24 radio(7,8); // CE, CSN

/**********************************************************/



//const uint64_t addresses[2] = { 0x3130303030LL, 0x3a00000001LL };

const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
//byte addresses[][6] = {"00001"};
//byte addresses[][6] = {"1Node","2Node"};

// Used to control whether this node is sending or receiving

bool role = 0; // 0 = pong back , 1 = ping out

void setup() {

// Start the SPI buss
SPI.setClockDivider( SPI_CLOCK_DIV16 ); // Set SPI clock to 4.5MHz, similar to 16M Arduino
// use alternate SPI pins for nrf24
//SPI.setMOSI(26);
//SPI.setMISO(1);
//SPI.setSCK(14);
SPI.begin();


while(!Serial) ; // wait for arduino serial monitor
delay(2000); // WNG - println's below started working after I put in this delay
Serial.println("RF24/examples/GettingStarted");
Serial.println("*** PRESS 'T' to begin transmitting to the other node");

radio.begin();
//radio.setRetries(1,0);
//radio.setCRCLength(RF24_CRC_16);
radio.setAutoAck(false);
//radio.setPayloadSize(sizeof(int));
//radio.openReadingPipe(1,addresses);
//radio.startListening();

//radio.setAutoAck(false);



// Start the radio, again set ti min & slow as I'm guessing while testing theire really close to each oth
radio.setPALevel(RF24_PA_MIN); // RF24_PA_MIN ,RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX
radio.setDataRate( RF24_250KBPS ); // RF24_250KBPS, RF24_1MBPS, RF24_2MBPS




// Open a writing and reading pipe on each radio, with opposite addresses
if(radioNumber){
radio.openWritingPipe(pipes[1]);
radio.openReadingPipe(1,pipes[0]);
}else{
radio.openWritingPipe(pipes[0]);
radio.openReadingPipe(1,pipes[1]);
}

// Start the radio listening for data
radio.startListening();
radio.printDetails();
}

void loop() {


/****************** Ping Out Role ***************************/
if (role == 1) {

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


Serial.println(F("Now sending"));

unsigned long start_time = micros(); // Take the time, and send it. This will block until complete
if (!radio.write( &start_time, sizeof(unsigned long) )){
Serial.println(F("failed"));
}

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

unsigned long started_waiting_at = micros(); // Set up a timeout period, get the current microseconds
boolean timeout = false; // Set up a variable to indicate if a response was received or not

while ( ! radio.available() ){ // While nothing is received
if (micros() - started_waiting_at > 200000 ){ // If waited longer than 200ms, indicate timeout and exit while loop
timeout = true;
break;
}
}

if ( timeout ){ // Describe the results
Serial.println(F("Failed, response timed out."));
}else{
unsigned long got_time; // Grab the response, compare, and send to debugging spew
radio.read( &got_time, sizeof(unsigned long) );
unsigned long end_time = micros();

// Spew it
Serial.print(F("Sent "));
Serial.print(start_time);
Serial.print(F(", Got response "));
Serial.print(got_time);
Serial.print(F(", Round-trip delay "));
Serial.print(end_time-start_time);
Serial.println(F(" microseconds"));
}

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



/****************** Pong Back Role ***************************/

if ( role == 0 )

{
unsigned long got_time;

if( radio.available()){
// Variable for the received timestamp
while (radio.available()) { // While there is data ready
radio.read( &got_time, sizeof(unsigned long) ); // Get the payload
}

radio.stopListening(); // First, stop listening so we can talk
radio.write( &got_time, sizeof(unsigned long) ); // Send the final one back.
radio.startListening(); // Now, resume listening so we catch the next packets.

Serial.print(F("Sent response "));
Serial.println(got_time);
}
}




/****************** Change Roles via Serial Commands ***************************/

if ( Serial.available() )
{
char c = toupper(Serial.read());
if ( c == 'T' && role == 0 ){
Serial.println(F("sssss*** CHANGING TO TRANSMIT ROLE -- PRESS 'R' TO SWITCH BACK qqqqqqqqqqqqqqqq"));
role = 1; // Become the primary transmitter (ping out)

}else
if ( c == 'R' && role == 1 ){
Serial.println(F("sssssss*** CHANGING TO RECEIVE ROLE -- PRESS 'T' TO SWITCH BACK"));
role = 0; // Become the primary receiver (pong back)
radio.startListening();

}
}


} // Loop
 
Still getting this error

18:16:14.328 -> RF24/examples/GettingStarted
18:16:14.328 -> *** PRESS 'T' to begin transmitting to the other node
18:16:14.375 -> SPI Speedz = 10 Mhz
18:16:14.375 -> STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
18:16:14.375 -> RX_ADDR_P0-1 = 0xf0f0f0f0e1 0xf0f0f0f0d2
18:16:14.375 -> RX_ADDR_P2-5 = 0x00 0x00 0x00 0x71
18:16:14.375 -> TX_ADDR = 0xf0f0f0f0e1
18:16:14.375 -> RX_PW_P0-6 = 0x20 0x20 0x00 0x00 0x00 0x00
18:16:14.375 -> EN_AA = 0x00
18:16:14.375 -> EN_RXADDR = 0x02
18:16:14.375 -> RF_CH = 0x4c
18:16:14.375 -> RF_SETUP = 0x71
18:16:14.375 -> CONFIG = 0x0f
18:16:14.375 -> DYNPD/FEATURE = 0x00 0x00
18:16:14.375 -> Data Rate = 250KBPS
18:16:14.375 -> Model = nRF24L01+
18:16:14.375 -> CRC Length = 16 bits
18:16:14.375 -> PA Power = PA_MIN
18:16:17.640 -> sssss*** CHANGING TO TRANSMIT ROLE -- PRESS 'R' TO SWITCH BACK qqqqqqqqqqqqqqqq
18:16:17.640 -> Now sending
18:16:17.857 -> Failed, response timed out.
18:16:18.875 -> Now sending
18:16:19.045 -> Failed, response timed out.
18:16:20.064 -> sssssss*** CHANGING TO RECEIVE ROLE -- PRESS 'T' TO SWITCH BACK
18:16:21.918 -> sssss*** CHANGING TO TRANSMIT ROLE -- PRESS 'R' TO SWITCH BACK qqqqqqqqqqqqqqqq
18:16:21.918 -> Now sending
18:16:22.088 -> Failed, response timed out.
18:16:23.076 -> Now sending
18:16:23.308 -> Failed, response timed out.
18:16:24.280 -> Now sending
 
Another problem is that Tx and Rx don't set the payload size. The default payload size is 32 bytes but the code is only sending 4 bytes.
After the radio.begin() statement, add this line to both Tx and Rx:
Code:
  radio.setPayloadSize(sizeof(unsigned long));

I've got the code working here so if that one fix doesn't sort things out, I'll post the code I'm using.

Pete
P.S. FYI, I'm using a T3.2 and T4.1 for my testing
 
Ya I think my codes a dud ;( I tried it didnt work. I am trying to go from a T4.1 to Mega.....its killing me....I would totally appreciate a code set that you have confirmed works
and any suggestions that I might need to run it on both T4.1 and Mega.....totally appreciate the help el_supremo ;)
 
I'm using this code on both Teensys with slight modifications for the transmitter and receiver.

I set both of them to start up as a receiver (role = 0) and then type T in one of them to get things going. I've also slowed the message rate from one a second to one every five seconds to make it easier to keep track of them.

The radioNumber must be set to 1 in one of the processors and to 0 in the other. If you've wired the NRF24l01 the same way in both processors, no other changes should be required.

Once they are both uploaded, type T in one of them and it should send a message to the other every 5 seconds.
Code:
// Tx
/*
* Getting Started example sketch for nRF24L01+ radios
* This is a very basic example of how to send data from one node to another
* Updated: Dec 2014 by TMRh20
*/

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


//#define RF24_MOSI 11
//#define RF24_MISO 12
//#define RF24_SCLK 14



/****************** User Config ***************************/
/*** Set this radio as radio number 0 or 1 ***/
bool radioNumber = 1;

/* Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 7 & 8 */
RF24 radio(7,8); // CE, CSN

/************************************************** ********/



//const uint64_t addresses[2] = { 0x3130303030LL, 0x3a00000001LL };

const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
//byte addresses[][6] = {"00001"};
//byte addresses[][6] = {"1Node","2Node"};

// Used to control whether this node is sending or receiving

bool role = 0; // 0 = pong back , 1 = ping out

void setup()
{

  while(!Serial) ; // wait for arduino serial monitor
  delay(2000); // WNG - println's below started working after I put in this delay
  Serial.println("RF24/examples/GettingStarted");
  Serial.println("*** PRESS 'T' to begin transmitting to the other node");

  radio.begin();
  radio.setPayloadSize(sizeof(unsigned long));
  radio.setAutoAck(false);

// Start the radio, again set ti min & slow as I'm guessing while testing theire really close to each oth
  radio.setPALevel(RF24_PA_MIN); // RF24_PA_MIN ,RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX
  radio.setDataRate( RF24_250KBPS ); // RF24_250KBPS, RF24_1MBPS, RF24_2MBPS

// Open a writing and reading pipe on each radio, with opposite addresses
  if(radioNumber) {
    radio.openWritingPipe(pipes[1]);
    radio.openReadingPipe(1,pipes[0]);
  } else {
    radio.openWritingPipe(pipes[0]);
    radio.openReadingPipe(1,pipes[1]);
  }

// Start the radio listening for data
  radio.startListening();
  radio.printDetails();
}

void loop()
{
  /****************** Ping Out Role ***************************/
  if (role == 1) {
    radio.stopListening(); // First, stop listening so we can talk.

    Serial.println(F("Now sending"));

    unsigned long start_time = micros(); // Take the time, and send it. This will block until complete
    if (!radio.write( &start_time, sizeof(unsigned long) )) {
      Serial.println(F("failed"));
    }

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

    unsigned long started_waiting_at = micros(); // Set up a timeout period, get the current microseconds
    boolean timeout = false; // Set up a variable to indicate if a response was received or not

    while ( ! radio.available() ) { // While nothing is received
      if (micros() - started_waiting_at > 200000 ) { // If waited longer than 200ms, indicate timeout and exit while loop
        timeout = true;
        break;
      }
    }

    if ( timeout ) { // Describe the results
      Serial.println(F("Failed, response timed out."));
    } else {
      unsigned long got_time; // Grab the response, compare, and send to debugging spew
      radio.read( &got_time, sizeof(unsigned long) );
      unsigned long end_time = micros();

// Spew it
      Serial.print(F("Sent "));
      Serial.print(start_time);
      Serial.print(F(", Got response "));
      Serial.print(got_time);
      Serial.print(F(", Round-trip delay "));
      Serial.print(end_time-start_time);
      Serial.println(F(" microseconds"));
    }

// Try again 5s later
    delay(5000);
  }

  /****************** Pong Back Role ***************************/

  if ( role == 0 )
  {
    unsigned long got_time;

    if( radio.available()) {
// Variable for the received timestamp
      while (radio.available()) { // While there is data ready
        radio.read( &got_time, sizeof(unsigned long) ); // Get the payload
      }

      radio.stopListening(); // First, stop listening so we can talk
      radio.write( &got_time, sizeof(unsigned long) ); // Send the final one back.
      radio.startListening(); // Now, resume listening so we catch the next packets.

      Serial.print(F("Sent response "));
      Serial.println(got_time);
    }
  }

  /****************** Change Roles via Serial Commands ***************************/

  if ( Serial.available() ) {
    char c = toupper(Serial.read());
    if ( c == 'T' && role == 0 ) {
      Serial.println(F("sssss*** CHANGING TO TRANSMIT ROLE -- PRESS 'R' TO SWITCH BACK qqqqqqqqqqqqqqqq"));
      role = 1; // Become the primary transmitter (ping out)

    } else if ( c == 'R' && role == 1 ) {
      Serial.println(F("sssssss*** CHANGING TO RECEIVE ROLE -- PRESS 'T' TO SWITCH BACK"));
      role = 0; // Become the primary receiver (pong back)
      radio.startListening();

    }
  }
} // Loop

Pete
 
Thanks Pete.....so I did as you instructed...

I took 1 copy and am running it on the T4.1 as is....radio 1...
I took 1 copy and changed the ce,csn number and changed the radio to 0..
I hit T on the Mega...I have a blank screen
on the T4.1 I just have the radio details.....

not sure I am doing this correctly
 
You should have radio details on both screens unless the RF24 library for the Mega is different than the T4.1.
If it really does work for a few lines, i.e. the sender sometimes looks like this:
Code:
Now sending
Sent 5597214, Got response 5597214, Round-trip delay 1784 microseconds
Now sending
Sent 10599568, Got response 10599568, Round-trip delay 1786 microseconds
Now sending
Sent 15601923, Got response 15601923, Round-trip delay 1787 microseconds
and receiver looks like this:
Code:
Sent response 5597214
Sent response 10599568
Sent response 15601923
then maybe there's a loose wire.

Pete
 
Status
Not open for further replies.
Back
Top