Setting up Adafruit Feather RP2040 CAN Bus + ST7789v2 #3566
Replies: 3 comments
-
Ok, looks like my experience with PlatformIO is negative. I can't make it work so that display and CAN controller work simultaneously. The missing piece at first was defining But, moving to Arduino IDE, I can make them work... Kind of. If I initiate display after Can someone look at the sketch and see if something is up? This is when CAN functionality works as I need. #include <TFT_eSPI.h>
#include <mcp_can.h>
#define CS_PIN 19
long unsigned int rxId;
unsigned char len = 0;
unsigned char rxBuf[8];
char msgString[128];
#define CAN0_INT 22
MCP_CAN CAN0(CS_PIN);
TFT_eSPI tft = TFT_eSPI();
void setup() {
tft.init();
tft.setRotation(1);
tft.fillScreen(TFT_WHITE);
tft.setTextColor(TFT_BLACK, TFT_WHITE);
tft.setCursor(20, 20, 4);
tft.print("TESTING");
Serial.begin(115200);
while(!Serial) delay(10);
if (CAN0.begin(MCP_STDEXT, CAN_500KBPS, MCP_16MHZ) == CAN_OK) {
Serial.println("MCP2515 Initialized Successfully!");
} else {
Serial.println("Error Initializing MCP2515...");
}
pinMode(CAN0_INT, INPUT_PULLUP);
CAN0.init_Mask(0,0,0x02FF0000);
CAN0.init_Filt(0,0,0x02020000);
CAN0.init_Filt(1,0,0x02280000);
CAN0.setMode(MCP_NORMAL);
// Serial.println("MCP2515 Receiver test!");
// if (!mcp.begin(CAN_BAUDRATE)){
// Serial.println("Error initializing MCP2515.");
// while(1) delay(10);
// }
// Serial.println("MCP2515 chip found");
}
void loop() {
if (!digitalRead(CAN0_INT)) {
CAN0.readMsgBuf(&rxId, &len, rxBuf);
Serial.print("ID: ");
Serial.print(rxId, HEX);
Serial.print(" Data: ");
for (int i = 0; i < len; i++) {
sprintf(msgString, " %.2X", rxBuf[i]);
Serial.print(msgString);
}
Serial.println();
delay(250);
}
tft.drawString(msgString, 20, 40, 2);
} |
Beta Was this translation helpful? Give feedback.
-
My // User defined information reported by "Read_User_Setup" test & diagnostics example
#define USER_SETUP_INFO "User_Setup"
// Define to disable all #warnings in library (can be put in User_Setup_Select.h)
#define DISABLE_ALL_LIBRARY_WARNINGS
#define ST7789_2_DRIVER // Minimal configuration option, define additional parameters below for this display
#define TFT_WIDTH 240 // ST7789 240 x 240 and 240 x 320
#define TFT_HEIGHT 280 // GC9A01 240 x 240
#define TFT_MOSI 15 // Automatically assigned with ESP8266 if not defined
#define TFT_SCLK 14 // Automatically assigned with ESP8266 if not defined
#define TFT_CS 10 // Chip select control pin D8
#define TFT_DC 11 // Data Command control pin
#define TFT_RST 12 // Reset pin (could connect to NodeMCU RST, see next line)
//#define TFT_BL PIN_D1 // LED back-light (only for ST7789 with backlight control pin)
#define LOAD_GLCD // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH
#define LOAD_FONT2 // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters
#define LOAD_FONT4 // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters
#define LOAD_FONT6 // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm
#define LOAD_FONT7 // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:-.
#define LOAD_FONT8 // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-.
//#define LOAD_FONT8N // Font 8. Alternative to Font 8 above, slightly narrower, so 3 digits fit a 160 pixel TFT
#define LOAD_GFXFF // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts
#define SMOOTH_FONT
// For RP2040 processor and SPI displays, uncomment the following line to use the PIO interface.
#define RP2040_PIO_SPI // Leave commented out to use standard RP2040 SPI port interface
#define CGRAM_OFFSET
#define TFT_SPI_PORT 1 // Set to 0 if SPI0 pins are used, or 1 if spi1 pins used
// Define the SPI clock frequency, this affects the graphics rendering speed. Too
// fast and the TFT driver will not keep up and display corruption appears.
// With an ILI9341 display 40MHz works OK, 80MHz sometimes fails
// With a ST7735 display more than 27MHz may not work (spurious pixels and lines)
// With an ILI9163 display 27 MHz works OK.
// #define SPI_FREQUENCY 1000000
// #define SPI_FREQUENCY 5000000
// #define SPI_FREQUENCY 10000000
// #define SPI_FREQUENCY 20000000
#define SPI_FREQUENCY 27000000
// #define SPI_FREQUENCY 40000000
// #define SPI_FREQUENCY 55000000 // STM32 SPI1 only (SPI2 maximum is 27MHz)
// #define SPI_FREQUENCY 80000000
// Optional reduced SPI frequency for reading TFT
// #define SPI_READ_FREQUENCY 20000000 |
Beta Was this translation helpful? Give feedback.
-
I managed to make it work, and the way I did is to just connect everything display related to SPI0 pins, and use I couldn't wrap my head around using and declaring hardware SPI1 on RP2040 just for a display, so I guess this'll do... |
Beta Was this translation helpful? Give feedback.
-
I've got an Adafruit Feather RP2040 CAN Bus module and I've been trying to set up one of my displays (Waveshare 1.69 240x280 IPS) which uses ST7789v2 driver.
I've been using PlatformIO in the beginning, and it sorta works fine when I use the default
pico
core, but when I useearlephilhower
core the screen refuses to update. The same happens when I use Arduino IDE to manage the board. Just getting a blank screen.I used build flags based on some of the RP2040 user setups. But I guess I need
earlephilhower
core to get the CAN controller running? It says so in the learning guide...I think I am missing some of the build flags/user setup definitions, could someone help?
Beta Was this translation helpful? Give feedback.
All reactions