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
#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
// 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.
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