Replies: 4 comments
-
Additionally I found in the RF24.cpp: bool RF24::begin(void)
#elif defined(XMEGA_D3) #elif defined(RF24_RP2) #else // using an Arduino platform || defined (LITTLEWIRE) That seems to as if there were provisions for SPI0 and SPI1. |
Beta Was this translation helpful? Give feedback.
-
This line shows it's using the value of PICO_DEFAULT_SPI to choose between spi1 and spi0 ;
If PICO_DEFAULT_SPI is true, it chooses spi1. So, somewhere, probably in the header file for that library (RF24.h), it might define PICO_DEFAULT_SPI, e.g. as
or
or
or similar. Depending on how it's defined, you can either override it, before RF24 radio(CE_PIN, CSN_PIN); or you might have to edit the header file (.h), after adding a local copy of the header and the .cpp to your project. Alternatively, it might be passed as an optional parameter to RF24 radio(CE_PIN, CSN_PIN); It's not possible to say without looking at the source code for at least RF24.h, and possibly also RF24.cpp. The function you're looking for is the constructor for that object, It's a function defined as part of the class, with the same name as the class. There can be more than one, with different parameters. So, in RF24.h, you'd expect to see something like:
or maybe two separate definitions for RF24(), one with the two parameters in your example, and one with three or more, giving you extra options. If either of those is how it works, you may just be able to add true as the third parameter, like this:
Here's a page that explains the constructor syntax more clearly: https://en.wikipedia.org/wiki/Constructor_(object-oriented_programming) This one is specific to C++: |
Beta Was this translation helpful? Give feedback.
-
@Andy2No, thank you for your answer! I had a look at the source of RF24.cpp. Although something like
I am using EarlePhilhower's core with Arduino IDE 2.21. Thank you again. |
Beta Was this translation helpful? Give feedback.
-
discussion closed |
Beta Was this translation helpful? Give feedback.
-
I wonder if it would be possible to use a library working already for SPI0 also with SPI1. I had a look at
https://community.platformio.org/t/change-pi-pico-serial-and-i2c-pins-and-use-both-i2c-ports/27902
and
https://community.platformio.org/t/change-pi-pico-serial-pins/28004/6
However, in these cases example programs are shown written from scratch. I do the programming in the Arduino IDE V2.2.1.
In my case I wanted to use the RF24 library with SPI1.So I wrote the following program:
`#include <pico.h>
#include <SPI.h>
#include <RF24.h>
// Pro Mini, Nano: MOSI:11 , MISO:12 , SCK:13
//#define CE_PIN 9
//#define CSN_PIN 10
// Pico (SPI0)
//#define CE_PIN 20
//#define CSN_PIN 17
// Pico (SPI1)
#define CE_PIN 9
#define CSN_PIN 13 // PIN_SPI1_SS ??
RF24 radio(CE_PIN, CSN_PIN); // (NRF_CE, NRF_CSN)
const byte address[6] = "1RF24"; // address / identifier
void setup()
{
// settings for SPI0, i.e. Pico (defaults)
// SCK0: 18, MOSI0: 19, MISO0: 16
//SPI.setRX(16); // MISO1
//SPI.setTX(19); // MOSI1
//SPI.setSCK(18); // SCK1
//SPI.begin();
// settings for SPI1, i.e. Pico (2nd SPI)
// SCK1: 10, MOSI1: 11, MISO1: 8
SPI1.setRX(8); // MISO1 PIN_SPI1_MISO
SPI1.setTX(11); // MOSI1 PIN_SPI1_MOSI
SPI1.setSCK(10); // SCK1 PIN_SPI1_SCK
SPI1.begin(); // spi1 bus?
radio.begin();
radio.openWritingPipe(address); // set the address
radio.stopListening(); // set as transmitter
}
void loop() {
const char text[] = "Hi Receiver"; // max. 32 bytes
radio.write(&text, sizeof(text));
delay(2000);
}
`
It runs nicely on Arduino Pro Mini, on Pico with SPI0, however, not with SPI1. If anybody could give me a hint how to pass SPI1, e.g. with the begin() statement, that would be greatly appreciated. And I think such an experience could be helpful in similar cases, too.
Beta Was this translation helpful? Give feedback.
All reactions