0

[SOLVED] ItstyBitsy/Metro M4 - NRF24L01 - no SPI connection
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

[SOLVED] ItstyBitsy/Metro M4 - NRF24L01 - no SPI connection

by smerrett79 on Thu Jul 11, 2019 4:48 am

[SOLVED] - see post number three below - minor RF24 library edit required. Confirmed comms between Metro M4 and Nano clone, using NRF24L01s.

I have both the Itsy Bitsy M4 and the Metro M4 and I'm trying to get them to talk to the NRF24L01 radio modules. I have successfully used the TMRh20 RF24 library on a WEMOS SAMD21 Arduino Zero clone to get comms with another NRF24L01 running with an Arduino Nano clone. So I believe there shouldn't be a problem with the SAMD chip architecture per se. The main difference moving from the AVR to the SAMD21 was using SerialUSB instead of Serial (not relevant for the Adafruit M4 boards) and using the SPI ICSP header pins, rather than D11-D13 (which is still needed as far as I can tell on the M4s).

I have also tried using the Radiohead NRF24 library, to no avail. I have confirmed that the radio module is working by initialising it on the Nano with the following functions in the RF24 library:
Code: Select all | TOGGLE FULL SIZE
radio.isChipConnected()
radio.isPVariant()
radio.getChannel()

When I run any of these functions in my sketch on the M4s, I get 0 response to the first and no response to the others. Here's my test code in full:
Code: Select all | TOGGLE FULL SIZE
#include <SPI.h>
#include "RF24.h"

/****************** User Config ***************************/
/***      Set this radio as radio number 0 or 1         ***/
bool radioNumber = 0;
RF24 radio(9, 10);

void setup() {

  delay(5000);
  // put your setup code here, to run once:
  Serial.begin(115200);
  while (!Serial);
  Serial.println(F("RF24/examples/GettingStarted"));


  radio.begin();
  if (radio.isChipConnected()) {
    Serial.println("Radio started");
  }

  if (radioNumber) {
    radio.openWritingPipe(0xB00B1E50D2LL);
    radio.openReadingPipe(1, 0xB00B1E50C3LL);
  } else {
    radio.openWritingPipe(0xB00B1E50C3LL);
    radio.openReadingPipe(1, 0xB00B1E50D2LL);
  }

  if (radio.isPVariant()) {
    Serial.println("A + variant is connected");
  }

  Serial.println(radio.getChannel());

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

void loop() {
  // put your main code here, to run repeatedly:

}


I'm after any help or ideas about how to track down the source of this comms failure between board and radio. I have checked continuity between the M4 board pins and the radio module pins, so I don't believe there's a cable error (they are the same bundle of dupont jumper wires that I used for the successful check with the M0 board). I have also checked SPI header, power and CSN/CE connections match between code and between boards.

I've spent a full day and night on this so far and it's for work, so I'm pretty desperate! Thanks in advance for anyone who comments :)
Last edited by smerrett79 on Thu Jul 11, 2019 4:50 pm, edited 1 time in total.

smerrett79
 
Posts: 6
Joined: Sun Aug 30, 2015 9:46 pm

Re: ItstyBitsy/Metro M4 - NRF24L01 - no SPI connection

by smerrett79 on Thu Jul 11, 2019 5:12 am

Ok, I've just (for the first time - how have I not noticed before?!) seen this warning during compile:
Code: Select all | TOGGLE FULL SIZE
WARNING: library arduino_908031 claims to run on (avr, arm, x86, esp8266) architecture(s) and may be incompatible with your current board which runs on (samd) architecture(s).


I have already tried the SOFTSPI in RF24 library and the underlying DigitalIO.h doesn't play with the boards I'm using. I had a cursory attempt at defining a the M4 boards and SAMD pieces in there but failed somewhere in the pin definition template etc etc.

What's the fastest way to add M4 support to the RF24 library? Copy the "spixfer" way over from the Adafruit libraries or try to take advantage of the RF24Tiny way of doing things (separate config and spi class files)?

smerrett79
 
Posts: 6
Joined: Sun Aug 30, 2015 9:46 pm

Re: ItstyBitsy/Metro M4 - NRF24L01 - no SPI connection

by smerrett79 on Thu Jul 11, 2019 7:38 am

PROGRESS - M4 Metro can talk to the NRF24L01 (not tested Itsy Bitsy M4)

So, my workaround today involved noticing the different architecture files that are included with RF24 library for... ...different architectures. I thought I'd take a punt on the most similar one to the SAMD51, which is the Due, also being ARM.

In the RF24 library folder, you'll see a "utility" folder, with a bunch of folders named after chip/board types, e.g. "Due". In the Due folder, you'll find a file called "RF24_arch_config.h". For the ability to hack around with the contents, I copied the folder "Due" with the file "RF24_arch_config.h" in, pasted it into "Utility" folder and renamed the Due-copy folder as "SAMD". It turns out that I didn't need to hack around with the contents of "RF24_arch_config.h" in the SAMD folder, so you could just as well point to the Due folder.

However, I pointed to the SAMD folder. To do this, you need to go to the RF24 library folder and open "RF24_config.h" in a text editor that will allow you to resave it as a .h file (not a .txt file). Somewhere around line 60 you will see an #elif defined (TEENSYDUINO) preprocessor conditional. After that and before the #else, you need to add some text to point to the SAMD folder and the "RF24_arch_config.h" file contained in there. It looks like this:
Code: Select all | TOGGLE FULL SIZE
//Teensy 
#elif defined (TEENSYDUINO)

  #include "utility/Teensy/RF24_arch_config.h"
 
// M4 
#elif defined (SAMD_SERIES)

   #include "utility/SAMD/RF24_arch_config.h"
//Everything else
#else

This is messy and not tested for other SAMD chips - I'm being lazy here - but at least we are getting closer and this hack might help someone else. Thoughts and ideas would be very welcome still - I'm not done yet!

smerrett79
 
Posts: 6
Joined: Sun Aug 30, 2015 9:46 pm

Please be positive and constructive with your questions and comments.