Multiple SPI devices - RF24 and ST9720

I'd like to use a NRF24L01 radio along with a ST9720 display. The libraries I am using are U8g2lib and RF24. Both devices work when using them separately, with no other devices on the SPI bus. However, when try to add them in the same sketch, the display does not work at all. The devices are using different chip select lines.

This is my very beginning with the Arduino platform and I am not sure where to look, but possible lead is different frequency, which at the moment I am trying to gauge. I know that the radio uses 10 MHz clock, as defined in RF24_config.h.

Can someone chip in with ideas what to do?

Thanks

Edit: I am using Arduino Uno, NRF24L01 and ST9720.

Multiple SPI device should work together.

Could be a problem with your code, the Arduino or the wiring.

ST7920 SPI does not play cricket. Just use separate GPIO pins e.g. bit bang U8g2.

I did not get the metaphor, sorry. English is not my strong side.

I'll try using bit bang mode.

I thought they would work. My code is below; the radio works, the display does not. When I disconnect the radio and remove the associated code, the display is fine.

#include <Arduino.h>
#include <U8g2lib.h>
#include <SPI.h>
#include <RF24.h>

U8G2_ST7920_128X64_1_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* CS=*/ 10, /* reset=*/ U8X8_PIN_NONE);
RF24 radio(7, 8);                                  // using pin 7 for the CE pin, and pin 8 for the CSN pin
const byte address[5] = {'A', 'A', 'A', 'A', 'A'}; 

void setup(void) {
  Serial.begin(115200);
  u8g2.begin();
  u8g2.clearBuffer();
  u8g2.setFont(u8x8_font_7x14_1x2_f );
  u8g2.drawStr(0,20,"Starting!");
  u8g2.sendBuffer();
  delay(1000);

  if (!radio.begin()) {
      Serial.println("Failed starting the radio!");
      u8g2.clearBuffer();
      u8g2.setFont(u8x8_font_7x14_1x2_f );
      u8g2.drawStr(0,20,"Fail!");
      u8g2.sendBuffer();
      while (1) {}
    }

    Serial.println("Radio started!");
}

void loop(void) {
  u8g2.clearBuffer();
  u8g2.setFont(u8x8_font_7x14_1x2_f );
  u8g2.drawStr(0,20,"OK!");
  u8g2.sendBuffer();
  delay(100);
}

My apologies. Americans don't understand cricket.

The simple answer is that the ST7920 does not stop listening when CS is inactive.

However it looks as if you are trying to use SW_SPI on U8g2 and hardware SPI on RF24. You can never mix SW_SPI and HW_SPI. Even well behaved SPI devices must both use SW_SPI or both HW_SPI.

Just use HW_SPI for RF24 and bit-bang SW_SPI on different pins for ST7920.

David.

Thanks for spotting my mistake. I followed your advise and now the display and the radio are working:

#include <Arduino.h>
#include <U8g2lib.h>
#include <SPI.h>
#include <RF24.h>

U8G2_ST7920_128X64_1_SW_SPI u8g2(U8G2_R0, /* clock=*/ 7, /* data=*/ 6, /* CS=*/ 5, /* reset=*/ U8X8_PIN_NONE);
RF24 radio(8, 9);                                  // using pin 8 for the CE pin, and pin 9 for the CSN pin
const byte address[5] = {'A', 'A', 'A', 'A', 'A'}; 


void setup(void) {
  Serial.begin(115200);
  u8g2.begin();
  u8g2_prepare();

  if (!radio.begin()) {
    Serial.println("Failed starting the radio!");
    u8g2_print_text(0, 2, "Fail!");
    while (1) {}
  }
    Serial.println("Radio started!");
    u8g2_print_text(0, 2, "Radio started!");
}

void loop(void) {
  Serial.println("In main loop");
  delay(1000);
}

void u8g2_prepare(void) {
  u8g2.setFont(u8g2_font_6x10_tf);
  u8g2.setFontRefHeightExtendedText();
  u8g2.setDrawColor(1);
  u8g2.setFontPosTop();
  u8g2.setFontDirection(0);
}

void u8g2_print_text(u8g2_uint_t x, u8g2_uint_t y, const char *s) {
  u8g2.firstPage();
    do {
    u8g2.drawStr(x ,y, s);
  } while ( u8g2.nextPage() );
}