Arduino uno rf24 SoftSPI

Dear,

I’m using the RF24 library and I have to use the SOFTSPI for a custom ATMEGA328 board. Before going to the custom board I want to test the SOFTSPI on an Arduino Uno. I altered an example code of the website HowToMechatronics.com to use SOFTSPI for the receiver. This works, if I leave the MISO,MOSI and SCK pin to default SPI pins, see code in attachment. If I change for example the SCK pin to pin 4 of the Arduino Uno, the radio.available will trigger constantly and no text will be printed.

Does this mean that the code is not using the SOFTSPI?

Can anyone suggest a solution for this problem?

Thank you very much in advance!

ExampleReceiverCode.ino (791 Bytes)

For short programs please include the code in your Post using the code button </>
codeButton.png

so your code 
looks like this

and is easy to copy to a text editor See How to use the Forum

I have to use the SOFTSPI for a custom ATMEGA328 board

Why? That seems strange considering how it easy it is to use the hardware SPI.

Can you also post a version of the program that works properly using hardware SPI.

...R

Thanks for your reply.

I have to use the SOFTSPI because of the hardware spi pins are being used for something else, and they are not routed to a header and thus not easily accessible.

The code below is a working example of communication through hardware SPI. When the comments before the “#define” are removed the code will still work. The code stops working when for example the SCK pin is changed to pin 4

//Receiver code

//#define SOFTSPI
//#define SOFT_SPI_MISO_PIN 12
//#define SOFT_SPI_MOSI_PIN 11
//#define SOFT_SPI_SCK_PIN 13

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

RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_LOW);
  radio.startListening();
}
void loop() {
  if (radio.available()) {
    char text[32] = "";
    radio.read(&text, sizeof(text));
    Serial.print("Ontvangen tekst is: ");
    Serial.println(text);
  }
}
//Transmitter
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
void setup() {
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_LOW);
  radio.stopListening();
}
void loop() {
  const char text[] = "Hello World";
  radio.write(&text, sizeof(text));
  delay(10000);
}

I suspect you need to #include the SoftSPI library (or whatever it is called) in your program.

At the moment all your program does is define some values

...R

Dear,

the SoftSPI is implemented in the library by a define SOFTSPI and it is using the DigitalIO library for the software SPI.

jagil:
the SoftSPI is implemented in the library by a define SOFTSPI and it is using the DigitalIO library for the software SPI.

I'm not an expert on this but I think the library just selects the SoftSPI (rather than regular hardware SPI) - I am not aware that it includes code for doing soft SPI.

If you think I'm wrong do you have reference link to the softspi code?

...R

The link to how digitalIO is implementing software SPI, DigitalIO/testSoftSPI.ino at master · greiman/DigitalIO · GitHub

The example in your link starts with the line

#include "DigitalIO.h"

I don't see that in your program.

...R

Dear R,

the library DigitalIO is included in the header file of the nrf24.

Best regards,
J.

jagil:
the library DigitalIO is included in the header file of the nrf24.

So it is. I learn stuff every day.

Sorry, I've nothing further to suggest.

...R