Hi All...
Bit (lot)stuck and not sure where to go .
My circuit comprises an Adafruit 2.8" TFT and a generic CAN bus breakout with a 2515 chip. The processor is a ESP32S3 -wroom-1 .
THe processor is 3.3v and the 2515 is running at 5v ( due to its on board 2550).
I have made the connections for SPI using the default ESP pins, but with a idffrertnt pin for CS on the display . Here is my circuit. I have a potential divider on the MISO pin of the CAN devise as it outputs at 5v
If the CAN and TFT are plugged into the board the CAN with not initalise. The CAN on its own will however. The TFT will work in either situation.
Here is the first bit of my code, where the issues occurs:
#include <EEPROM.h>
#include <mcp_can.h>
#include <SPI.h>
#include "Adafruit_ILI9341.h"
#include "Adafruit_GFX.h"
#include <Fonts/FreeSerif9pt7b.h> // font used for text
#include <Fonts/FreeSansBold12pt7b.h> // like this font
#include <Fonts/FreeSans9pt7b.h>
#define TFT_GRAY 0x8410
//for pro mini32 testing use
/*
#define TFT_DC 10
#define TFT_CS 12
#define TFT_MOSI 11
#define TFT_MISO 9
#define TFT_CLK 7
#define TFT_RST 0
*/
//"EEPROM" (actually flash but ...)
#define EEPROM_SIZE 20 // number of bytes needed
const bool Verbose = 1; //used in debug for serial monitor printing.
const int TESTled=7;
// setup parameters:
bool FirstRun;
int CANBaudRate = 500;
int CanBaseNumber = 0x290;
byte firstrunCode = 121;
// RF and input type:
byte COMSchoiceTx;
byte COMSchoiceRx;
const int COMSaddressRx = 10; // address in flash (EEPROM) wehere these are stored.
const int COMSaddressTx = 11;
// coms stuff: variables to hold the parsed data from PC for rest of program:
const byte numChars = 20;
char messageFromPC[numChars] = {0};
int DesiredFillTime = 0;
int TimerStatusFromPC = 0;
bool newData = false;
bool freshData = false;
bool RUN = false;
int Status; // used for tranmitting info to host PC , sends battery , shutdown status. see voltage and shutdown function and void DataTx()
int Battery_Status = 2; // (2==good)
int Switchoff_Status = 1;
char receivedChars[numChars];
char tempChars[numChars]; // temporary array for use when parsing
// display type:
bool DisplayType; // 0 =enery prioroty ,1 =timer priority
const int DisplayTypeAddr = 12; // where data for display view is stored
#define CAN0_INT 47 // IO 47 process pin to show buffer data present.
// eeprom sytax: EEPROM.write(addr, val);
// EEPROM.read(addr);
// EEPROM Locations:
byte FirstRunSave = 1;
const int BaudrateSave = 2; //(and 3!)
const int CanBaseNumberAdd = 4;//&5
// Data Areas:
const int timeAdd = 6;
const int DeadManHandle = 5; // fuel control lever. IO5
const int Flow = 4;
// 2515 setup
const int CanCS = 14; //IO14;
long unsigned int rxId;
unsigned char len = 0;
unsigned char rxBuf[8];
char msgString[128]; //128 // Array to store serial string
char SpeedString[25];
MCP_CAN CAN0(CanCS);
// input Buttons
bool Up;
bool Down;
bool Enter;
bool Across;
const byte Uppin = 40;// IO40
const byte Downpin = 39; //IO39
const byte Enterpin = 38; //IO38
const byte Acrosspin = 42; //IO42 , pin35
//Power control:
byte PowerlockinPin = 48; // IO48 used for switch on to hold unit on.
bool PowerlockinPinState;
long AutoSwitchoffTime = 900000; // time to switch off Ms
long RunTime; // millis() time since switch on, reset by any operation event
//outputs to display etc:
long Volval;//flow rate
long Massval;
long StartReading;
int Temperature;
long totalVol; //from can bus
long TotalVolinRun;
long Filltime; // the duration of a fuel fill
long StartFilltime;
long EndFilltime;
long TimerupdateInterval = 200; // how often to update the display
unsigned long currentMillis;
// Second serial port used for debugging:
#define RXD2 16 //default for these
#define TXD2 17
// start display.
//For PCB use: these are just the default SPI pins for esp32, but different cs for display.
#define TFT_DC 10
#define TFT_CS 21 // pin 23 on the chip
#define TFT_MOSI 11
#define TFT_MISO 13
#define TFT_CLK 12
#define TFT_RST 0
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);
void setup()//********** start of setup***************
{
pinMode (TESTled, OUTPUT);
if (Verbose == 1) //used for debug
{
Serial.begin(115200);
delay(100);
Serial.print(F( "PSH/24 Ver:"));
Serial.println(Ver);
}
pinMode(Flow, INPUT_PULLUP);
pinMode(DeadManHandle, INPUT_PULLUP);
pinMode(CAN0_INT, INPUT);
//pinMode (CanCS, OUTPUT);
// input buttons buttons:
pinMode (Uppin, INPUT);
pinMode (Downpin, INPUT);
pinMode (Enterpin, INPUT);
pinMode( Acrosspin, INPUT); //these are all active low, with external pull ups
// lock in power
pinMode(PowerlockinPin, OUTPUT); //HOLDS POWER ON AFTER BUTTON PRESS
digitalWrite(PowerlockinPin, HIGH);
PowerlockinPinState = 1;
EEPROM.begin(EEPROM_SIZE);
Retrieveparameters(1); // GET SETUP CONSTANTS
//setup receiver:
//Set up receiver (we start as a receiver):
Serial.print(F("ATR")); //ASCII
Serial.write(COMSchoiceRx); // decimal byte values
Serial.write(numChars); // length of data string ("<----data,length--->"
//*****************************************************
// Initialize MCP2515 running at 16MHz with a baudrate of CANBaudRate and the masks and filters disabled.
// if (CAN0.begin(MCP_ANY, SpeedString, MCP_16MHZ) == CAN_OK)
if (CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_16MHZ) == CAN_OK) // default method
{
if (Verbose == 1)
{
Serial.println("MCP2515 Initialized Successfully!");
}
}
else
{
if (Verbose == 1)
{
Serial.println("Error Initializing MCP2515...");
}
}
CAN0.setMode(MCP_NORMAL);
delay(2000); // TIME TO READ ABOVE MSG
tft.begin();
tft.fillScreen(ILI9341_BLACK); // blank screen out.
tft.setRotation(1);// rotate display
Retrieveparameters(1); //restore saved values
//*****************************************
RunTime = millis(); // start up time recorded
if (Verbose == 1)
{
Serial.println (F(" INTO Loop...")) ;
}
}//*******end of setup**********
messages are :
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3808,len:0x44c
load:0x403c9700,len:0xbd8
load:0x403cc700,len:0x2a80
entry 0x403c98d0
PSH/24 Ver:0.85
Run code is (121)121
Setup values retrieved
ATR**Entering Configuration Mode Failure...**
**Error Initializing MCP2515...**
Run code is (121)121
Setup values retrieved
INTO Loop...
CANBUS SECTION... Can int= 1
Standard ID: 0x000 DLC: 0 Data:
HEADER:0
into display3