NRF24l01 and ILI9341 SPI bus

Hello, I am trying to use the Adafruit ILI9341 TFT to display data received from NRF24l01 but when both are plugged in to SPI pins they don't work. I understand that I need to manage what device I am talking too but I do not know how to implement that into code as I am unfamiliar with SPI library.

Note: When both are plugged in the NRF24l01 is unable to receive "HELLO WORLD" string from the transmitter however when tft display is unplugged it seems to work fine.

#include <SPI.h>
#include <RF24.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>

#define TFT_DC 9
#define TFT_CS 10

RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);

void setup() {
  Serial.begin(9600);
  SPI.begin(); // Initialize the SPI interface
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();
  tft.begin();
  Serial.println("STARTING");
}

void loop() {
  tft.fillScreen(ILI9341_BLACK);

  if (radio.available()) {
    char text[32] = "";
    radio.read(&text, sizeof(text));
    Serial.println(text);
    
    // Begin SPI transaction for the TFT display

    delay(2000);
  }

    SPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE0));
    tft.setTextColor(ILI9341_WHITE);
    tft.println(text);
    SPI.endTransaction(); // End SPI transaction for the TFT display
}

Here is something chatGPT cooked up. Although most of it is my code it added SPI.beginTransaction() and SPI.endTransaction()

#include <SPI.h>
#include <RF24.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>

#define TFT_DC 9
#define TFT_CS 10

RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);

void setup() {
  Serial.begin(9600);
  tft.begin();
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();
  Serial.println("STARTING");
}

void loop() {
  tft.fillScreen(ILI9341_BLACK);

  if (radio.available()) {
    char text[32] = "";
    radio.read(&text, sizeof(text));
    Serial.println(text);
    tft.setTextColor(ILI9341_WHITE);
    tft.println(text);
    delay(2000);
  }

}

This was my original code but it didn't work I can write to tft display no problem when they're both plugged in but I cannot receive data properly however I can when the LCD is unplugged.

SPI requires a separate chip select for each device. That equates to three bus wires and a seperate select.

The screen works ok but the NRF24L01 does not when both these SPI devices are active?
Pin 10 pulled low allows the screen to hold the SPI bus.
Pin 8 pulled low allows the NRF24L01 to hold the bus.
Both devices should not be active (select pins LOW) simultaneously. Libraries are usually written in such a way that the SPI bus is configured and held at the beginning of an operation and released at the end so this should not happen.
If the screen does not let go of the bus I suppose you could try forcing pin 10 high to give the radio a chance.
Better would be to use a logic analyser or some equivalent method of determining if there is some bus contention.
A coding solution may be to separate the screen and radio activities with some sort of reset/cleanup between them.

Edit: Google for "nrf24l01 shared spi bus problem". Without looking too deeply, it looks like the radio could actually problem.

maybe it is power issue. how you wired your setup?

I will provide a schematic off my wiring later today, please tell me if you see any potential issues and thank you.

I am so sorry advance my fritzing doesn't have the ILI9341 so I made a breadboard view just to give the general idea.

I was able to wire NRF24l01 but where the yellow wires are (assuming all the other LCD connections are fine) is how I wire the ILI9341 where the wires would jump directly to CLK, MISO, MOSI.

again sorry for the bad drawing and also they are powered but a Arduino Uno USB. (USB Cable - A) I believe.

i unplugged the MISO pin and now its working.

There are many CAD (Computer Aided Design) software packages that can be simply downloaded for free. KiCad is one of the good ones. KiCad will take you from simple schematic to a printed circuit board. The frizzy drawings as you are finding are useless for debugging.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.