# MCP2515 and TFT ILI9341 on the same SPI on ESP8266 using Arduino

**URL:** <https://forum.arduino.cc/t/mcp2515-and-tft-ili9341-on-the-same-spi-on-esp8266-using-arduino/1089289>\
**Category:** Programming\
**Created:** [February 12, 2023, 12:48pm UTC](https://forum.arduino.cc/t/mcp2515-and-tft-ili9341-on-the-same-spi-on-esp8266-using-arduino/1089289 "2023-02-12T12:48:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ptrenta](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ptrenta/32/918146_2.png) [@ptrenta](https://forum.arduino.cc/u/ptrenta)\
**Post date:** [February 12, 2023, 12:48pm UTC](https://forum.arduino.cc/t/mcp2515-and-tft-ili9341-on-the-same-spi-on-esp8266-using-arduino/1089289/1 "2023-02-12T12:48:50Z")

</div>

Hello,  
i read from CAN BUS through MCP2515 and i want to write the result on a LCD ILI9341 using SPI.  
I am using the library MCP\_CAN and ADAFRUIT

```cpp
#include <Arduino.h>
#include <mcp_can.h>
#include <SPI.h>
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include <Fonts/DS_DIGIT_1_48pt7b.h>

```

the TFT use the same HSPI of the CAN

```cpp
// LCD definition
#define TFT_CS 4 //D2 IO4
#define TFT_RST 16 //D0 IO16
#define TFT_DC 5 //D1 IO5
#define TFT_MOSI 13 //D7 IO13
#define TFT_CLK 14 //D5 IO14
#define TFT_MISO 12 //D6 IO12
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
// CAN definition
MCP_CAN CAN0(2); // Set CS to pin GPIO2 D2
#define CAN_INT 15 //D8 //2 // Interrupt CAN GPIO2 D4

```

the single elements are working good, LCD works and CAN works, the problem is that at the start i initialize the LCD and it works, then after the CAN begin, LCD stop to work.

````cpp
void setup() { // --------------setup
  Serial.begin(115200);
  // ------------------- Init CAN BUS
   pinMode(CAN_INT, INPUT); // Setting pin INT input
  delay(500);
  // --------------------------- Init LCD
  tft.begin(10000000);```
 tft.fillScreen(BLACK);

 freccia(salita); // <---------- draw an arrow on LCD
  // ---------------------

  if (CAN0.begin(MCP_STDEXT, CAN_125KBPS, MCP_8MHZ) == CAN_OK) 
          Serial.print("MCP2515 Init Okay!!\r\n");
  else 
         Serial.print("MCP2515 Init Failed!!\r\n");

  CAN0.init_Mask(0, 1, 0xFFFFF000); // Init first mask...
  CAN0.init_Filt(0, 1, 0x1FDFC000); // Init first filter...
  CAN0.init_Mask(1, 1, 0xFFFFF000);
  CAN0.setMode(MCP_NORMAL); // Change to normal mode
} // -- fine SETUP

void loop() { // ------------------------LOOP
 if (!digitalRead(CAN_INT)) // If pin 2 is low, read receive buffer
  {
    CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
    Serial.print("ID: ");
    Serial.print(rxId, HEX);
    Serial.print(" Data: ");
    for (int i = 0; i < len; i++) // Print each byte of the data
    {
      if (rxBuf[i] < 0x10) // If data byte is less than 0x10, add a leading zero
      {
        Serial.print("0");
      }
      Serial.print(rxBuf[i], HEX);
      Serial.print(" ");
    }
    Serial.println();
  }
// ..... elaborate message and print something on LCD
}

````

The result is that at start, LCD draw the arrow in Setup() but after CAN.begin() LCD remain freezed, and CAN continue to work.

I am sure that the problem is in switching module in same SPI, but i think to have the same frequency (mcp\_can inizialize SPI with 10000000 and i started TFT.begin(10000000) ).

I tried everything but i got stuck.  
I don't want to use another micro just to drive the display, any ideas?

Thanks.  
Paolo

---

<div class="post-metadata">

**Author:** ![ua6em](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ua6em/32/930389_2.png) [@ua6em](https://forum.arduino.cc/u/ua6em)\
**Post date:** [February 12, 2023, 1:12pm UTC](https://forum.arduino.cc/t/mcp2515-and-tft-ili9341-on-the-same-spi-on-esp8266-using-arduino/1089289/2 "2023-02-12T13:12:36Z")

</div>

> [@ptrenta](#):
>
> `Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);`

**Adafruit\_ILI9341 tft = Adafruit\_ILI9341(TFT\_CS, TFT\_DC, TFT\_RST);**

```arduino
// Init TFT SPI
//Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST,TFT_MISO); // Soft SPI
//Adafruit_ILI9341 tft = Adafruit_ILI9341(&SPI1, TFT_DC,TFT_CS, TFT_RST); // HARD SPI1
//Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST); // HARD SPI

```

---

<div class="post-metadata">

**Author:** ![ptrenta](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ptrenta/32/918146_2.png) [@ptrenta](https://forum.arduino.cc/u/ptrenta)\
**Post date:** [February 12, 2023, 2:36pm UTC](https://forum.arduino.cc/t/mcp2515-and-tft-ili9341-on-the-same-spi-on-esp8266-using-arduino/1089289/3 "2023-02-12T14:36:47Z")

</div>

Thanks, that was the solution!

---

<div class="post-metadata">

**Author:** ![ua6em](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ua6em/32/930389_2.png) [@ua6em](https://forum.arduino.cc/u/ua6em)\
**Post date:** [February 12, 2023, 2:38pm UTC](https://forum.arduino.cc/t/mcp2515-and-tft-ili9341-on-the-same-spi-on-esp8266-using-arduino/1089289/4 "2023-02-12T14:38:17Z")

</div>

GL! TU & you FAM

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [August 11, 2023, 2:39pm UTC](https://forum.arduino.cc/t/mcp2515-and-tft-ili9341-on-the-same-spi-on-esp8266-using-arduino/1089289/5 "2023-08-11T14:39:09Z")

</div>

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