ESP-WROOM-32 CAN Bus comminication with teensy 3.2

Hello guys ,

I am a student , currently working on a personal project , i want to establish a can bus communication between an esp-wroom-32 and a teensy 3.2. For that i used 2 mcp2551 can transceivers i have connected pins 21 on the esp for TX and pin 22 for RX. So far its a simple project , i want the teensy to send some messages and the esp to read them. However , it seems there is a problem and it fails to read them. I have done a can bus communication with the teensy and an arduino uno board (i used an mcp2515 can module for that and removed 1 transceiver as the module has one ) . I am kinda stuck on that project for the past week and i cant understand what i am doing wrong. I have also connected a 5V power supply to the transceivers , and have set the baud rate to 115200.
Here is the code for the teensy

#include <FlexCAN.h>

static CAN_message_t msg;
static CAN_message_t msg2;

void setup() {

  Serial.begin(115200);

  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);
  pinMode(3,INPUT);
  digitalWrite(4,HIGH);

  Can0.begin(500000);

  msg.ext = 0;
  msg.id = 0x010;
  msg.len = 8;

  msg2.ext = 0;
  msg2.id = 0x080;
  msg2.len = 8;
}

void CAN_send()
{
  noInterrupts();

  msg.buf[0] = 1;
  msg.buf[1] = 54;
  msg.buf[2] = 64;
  msg.buf[3] = 87;
  msg.buf[4] = 12;
  msg.buf[5] = 35;
  msg.buf[6] = 23;
  msg.buf[7] = 0;

  Can0.write(msg);
  delay(1000);

  msg2.buf[0] = 'a';
  msg2.buf[1] = 'b';
  msg2.buf[2] = 'c';
  msg2.buf[3] = 'd';
  msg2.buf[4] = 0;
  msg2.buf[5] = 1;
  msg2.buf[6] = 2;
  msg2.buf[7] = 3;

  Can0.write(msg2);
  delay(2000);
  interrupts();
  
}
void loop() {
  
  CAN_send();
  
  Serial.println("Message sent ... ");
}

and the code for the esp to read the can messages

#include "driver/gpio.h"
#include "driver/can.h"

void setup()
{
    Serial.begin(115200);

    app_main();
    // Initialize configuration structures using macro initializers
    can_general_config_t g_config = CAN_GENERAL_CONFIG_DEFAULT(GPIO_NUM_21, GPIO_NUM_22, CAN_MODE_NORMAL); // 21 Tx 22 Rx
    can_timing_config_t t_config = CAN_TIMING_CONFIG_1MBITS();
    can_filter_config_t f_config = CAN_FILTER_CONFIG_ACCEPT_ALL();

    delay(2000);
    // Install CAN driver
    if (can_driver_install(&g_config, &t_config, &f_config) == ESP_OK)
    {
        Serial.println("Driver installed\n");
    }
    else
    {
        Serial.println("Failed to install driver\n");
        return;
    }

    // Start CAN driver
    if (can_start() == ESP_OK)
    {
        Serial.println("Driver started\n");
    }
    else
    {
        Serial.println("Failed to start driver\n");
        return;
    }
}

void loop()
{
    can_message_t message;
    if (can_receive(&message, pdMS_TO_TICKS(5000)) == ESP_OK)
    {
        Serial.println("Message received\n");
    }
    else
    {
        Serial.println("Failed to receive message in the last 5 seconds\n");
        return;
    }

    Serial.println((String) "ID is " + message.identifier);

    for (int i = 0; i < message.data_length_code; i++)
    {
        // Serial.println("Data byte %d = %d\n", i, message.data[i]);
        Serial.print((String)message.data[i] + " ");
    }
    Serial.println();
}


and the usefull links :

https://www.pjrc.com/store/teensy32.html
as well as the link for the library i used for teensy is the collin80' one , sorry but as a new user i cant post more than 2 links ...

This would be a good point to narrow down your problem. Lets eliminate any hardware errors first. Post your Schematic showing how you have wired it include all connections, power, ground and power sources. Frizzy pictures are useless so do not bother doing one. Also links to each of your hardware items that give "Technical" information would be a big help. Links to sales outlets such as azon resellers are useless.

I have updated my post , sorry for the late response too , i am gonna try testing if esp32 or the teensy actually send the messages (and not just printing serial.print) . Also worth mentioning that the full esp32 code was provided by a senior friend and i wanna mainly see if there is as u said a hardware error on my part or a coding error on the teensy board. Also a correction on the picture i have sent, the TX pin from the microcontrollers goes to the TX pins of the mcp2551 and the RX pins to RX respectively , sorry for any incovinience and thanks for any help :slight_smile:

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