I need to use the MCP2515 Can Bus module with the Lilygo TTGO T-Beam M8N.
However i can't seem to get the SPI pins to connect.
Any idea how to adjust the SPI pins on the MCP2515 Library and which pins to use?
There are 2 usable SPI buses on the ESP32, VSPI (SPI3) and HSPI (SPI2).
It would appear that the LORA module is connected to VSPI and the pins are not accessible without soldering.
HSPI uses 12, 13, 14 and but pin 12 is used for the GPS module.
Look in the library code to see what pins are being used by the various peripherals. You may be able to change the assignments using the io multiplexer.
If you are powering the MCP2515 with 5v, you must use a high speed 5v to 3.3v level shifter for the SPI pins.
The MPC2515 will work on 3V3 and you should be able to test communications with the chip and get your SPI working. At that point maybe it might work however realize the bus driver chip is probably 5V only. I got lucky some of mine worked but to be safe I changed the driver and it works great. Be sure the bus is terminated properly.
I'm trying to adjust the library so that the spi pins are accessible.
But i can't find the line where it sets the pins.
First thing I would do is check to see if pin 12 is being used as a regular digital read/write pin or if it's using the SPI hardware for some reason. If it is using the hardware SPI then you are probably out of luck.
This page talks about reconfiguring the pins for i2c, so perhaps there is something similar for SPI?
https://espressif-docs.readthedocs-hosted.com/projects/arduino-esp32/en/latest/tutorials/io_mux.html
I guess i'm out of luck then. pin 12 is used for the serial port for the GPS sensor which i also need.
Since i'm not using the LoRa module anyway, would it be possible to solder some wires on those pads with which the LoRa module is connected and just access the SPI pins directly?
For the chip select (slave select) line you need to physically disconnect the connection to the LORA module, which doesn't look easy. Using a hot air gun to remove the whole module or using another pin for chip select may be options.
Another option, If you only need a single CAN controller and assuming you have a regular ESP32 then there is already a SJA1000 chip onboard. All you need to add is a 3.3v CAN transceiver.
The only pin I can adjust or set in the MCP2515 Library is the Cs or ss pin.
Can i solder the wires for Mosi, Miso and Clk directly to the LoRa connections?
You can try,
I have now tried to do the same with another module, the LilyGo TTGO T-Energy and the ESP32-WROOM. both can't communicate with the mcp2515 through spi.
I tried to do the same code with an arduino mega which did work.
Any idea what i'm doing wrong.
The pins i'm using are SCK 14, CS 15, MOSI 13, MISO 12
I'm using the following code:
#include <SPI.h>
#include <mcp2515.h>
struct can_frame canMsg;
MCP2515 mcp2515(15);
void setup() {
Serial.begin(115200);
SPI.begin();
mcp2515.reset();
mcp2515.setBitrate(CAN_125KBPS);
mcp2515.setNormalMode();
Serial.println("------- CAN Read ----------");
Serial.println("ID DLC DATA");
}
void loop() {
if (mcp2515.readMessage(&canMsg) == MCP2515::ERROR_OK) {
Serial.print(canMsg.can_id, HEX); // print ID
Serial.print(" ");
Serial.print(canMsg.can_dlc, HEX); // print DLC
Serial.print(" ");
for (int i = 0; i<canMsg.can_dlc; i++) { // print the data
Serial.print(canMsg.data[i],HEX);
Serial.print(" ");
}
Serial.println();
}
}
I have now tried to use a LilyGo TTGO PCIE to connect the mcp2515 through the VSPI pins which do work.
Those same pins also work on the TTGO T-Energy.
So i think i'm going to stick with that.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.