audio shield + SPI pins

Status
Not open for further replies.

kkokddu

New member
HI, I am using teensy 3.5 with audio shield. Plus, I added "nRF24L01 wireless module" to control some audio parameters as wireless.

I have already soldered audio shield, so I have to use different extra pins at the back side, and soldered some jumper wires as below;

pin #46(SCK), #45(MISO), #44(MOSI), #43(CSN), #42(CE)...

but this wiring gives me an error, 'radio' doesn't begin.

here is my code at the beginning part..

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

byte adr[][6] = {"node1","node2"};

bool radioNum = 0; // 1 or 0

RF24 radio(42, 43);

I think SPI pins at the back side doesn't recognize the module(nRF24L01), any help??
 
You could share the SPI bus with the Audio shield. Note, on the 3.x processor, the audio library enables the SPI processing using pins MOSI (7), MISO (12), and SCLK (14). With well behaved devices, you can share the SPI bus, using a different CS pin for each device. You likely will need a pull-up resistor on your CS pin (resistor between the pin and 3.3v, usually 2.2k).

Here is a paper on SPI devices:

If you aren't actually using the SD card or the flash memory on the audio shield, then you may not need the pull-up resistor or worry about tri-stating the MISO pin.

The pins you selected are the 2nd SPI bus. Unless the library has provision for multiple SPI buses, you will likely need to clone the library, and rename it something else. In the library change all SPI to SPI2.
 
Thanks for your reply..

But I don't get any improvements from your suggestion - change from SPI to SPI2.

the code below is one of library example that I tried :

Code:
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>

RF24 radio(42,43);                    // nRF24L01(+) radio attached using Getting Started board 

RF24Network network(radio);          // Network uses that radio

const uint16_t this_node = 01;        // Address of our node in Octal format
const uint16_t other_node = 00;       // Address of the other node in Octal format

const unsigned long interval = 2000; //ms  // How often to send 'hello world to the other unit

unsigned long last_sent;             // When did we last send?
unsigned long packets_sent;          // How many have we sent already


struct payload_t {                  // Structure of our payload
  unsigned long ms;
  unsigned long counter;
};

void setup(void)
{
  Serial.begin(115200);
  Serial.println("RF24Network/examples/helloworld_tx/");
 
  SPI2.begin();
  SPI2.setMOSI(44);
  SPI2.setMISO(45);
  SPI2.setSCK(46);
  radio.begin();
  network.begin(/*channel*/ 90, /*node address*/ this_node);
}

void loop() {
  
  network.update();                          // Check the network regularly

  
  unsigned long now = millis();              // If it's time to send a message, send it!
  if ( now - last_sent >= interval  )
  {
    last_sent = now;

    Serial.print("Sending...");
    payload_t payload = { last_sent, packets_sent++ };
    RF24NetworkHeader header(/*to node*/ other_node);
    bool ok = network.write(header,&payload,sizeof(payload));
    if (ok){
      Serial.println("ok.");
      Serial.print(payload.ms);
      Serial.println(payload.counter);
    }
    else{
      Serial.println("failed.");
    }
  }
}

On the serial monitor, every line prints out "sending.. ok" with proper 'payload', but on the other side (which i am using nano with same nRF24L01 module), nothing happens.
 
Note, you have clone the RF24Network and RF24 libraries and change ALL references from SPI to SPI2. Typically you would use a different name (such as RF24_SPI2), copy the contents for the RadioHead direction into there, and then change all of the SPI invocations.

I am not familiar with the RF24 library, but there might be an option to change which SPI bus to use in the constructor. This would be a lot simpler than cloning the library.
 
Status
Not open for further replies.
Back
Top