Hi there,
I could do it for you, but better you find the exact syntax, What you have there will NOT work for a Nordic MCU … (your trying to use SILK_numbers & pin macro’s) you need GPIO numbers You want lowest level, you need to use bare metal components.
This Does compile
#include <Arduino.h>
#include <SPI.h>
// Your connector pins
#define SCK_PIN D11
#define MISO_PIN D12
#define MOSI_PIN D13
#define CS_PIN D14
void setup() {
Serial.begin(115200);
while (!Serial) { /* wait for USB */ }
// Show the resolved numeric GPIOs (if you’re curious)
Serial.print("SCK="); Serial.println(SCK_PIN);
Serial.print("MISO="); Serial.println(MISO_PIN);
Serial.print("MOSI="); Serial.println(MOSI_PIN);
Serial.print("CS="); Serial.println(CS_PIN);
// Chip-select is just a normal GPIO. Don’t pass it into SPI begin.
pinMode(CS_PIN, OUTPUT);
digitalWrite(CS_PIN, HIGH); // inactive
// Configure SPI1 to use your pins, then start it
#if defined(SPI1)
SPI1.setPins(SCK_PIN, MISO_PIN, MOSI_PIN); // <-- the important bit
SPI1.begin();
Serial.println("SPI1 started.");
#else
Serial.println("ERROR: This board/core doesn't define SPI1.");
#endif
}
void loop() {
#if defined(SPI1)
// Example transaction @ 8 MHz, mode 0
SPI1.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE0));
digitalWrite(CS_PIN, LOW);
uint8_t whoami = SPI1.transfer(0x9F); // example byte
// ... more transfers as needed ...
digitalWrite(CS_PIN, HIGH);
SPI1.endTransaction();
Serial.print("Got byte: 0x"); Serial.println(whoami, HEX);
delay(500);
#endif
}
I have both Scenarios covered, Both MCU’s ESP32 and Nrf52840
Note the Syntax , and for example pin macro’s and Class defines
is most proper.
SPIClass SPI_2(NRF_SPIM2, D9, D8, D10); // MISO, SCK, MOSI
check here where I use 2 SPI interfaces, you have to explicitly spell it out for the compiler.
and
YES
for like the 3rd time
Good Stuff , though tricky to track but it’s there.
HTH
GL Pj
post some code of what it is you want to do.
Notes that save headaches
- Use
setPins(...)
+begin()
, notSPI1.begin(SCK,MISO,MOSI,CS)
. Passing pins tobegin()
only exists on some cores;setPins
works on the Adafruit/Seeed nRF52 cores. - CS is not part of the SPI peripheral. Always
pinMode()
/digitalWrite()
it yourself. - Verifying pin mapping: If you really need raw GPIO numbers, just
Serial.println(D11)
etc., or open your board’svariants/*/pins_arduino.h
to see exactly which nRF port/pin each Dx maps to. - Check that SPI1 exists: Some variants only expose
SPI
(SPIM0). IfSPI1
isn’t defined, you’ll need to either useSPI
or create anotherSPIClass
bound toNRF_SPIM1
(varies by core; sticking withSPI1
when available is easier).