Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: Teensy 3.2 and 3.6 CAN BUS

Threaded View

  1. #1
    Junior Member
    Join Date
    Dec 2018
    Location
    Perth, Australia
    Posts
    6

    Teensy 3.2 and 3.6 CAN BUS

    Hi,

    I'm trying to make a Teensy 3.2 (transmitter) and a Teensy 3.6 (receiver) communicate through CAN using these cheap MCP2551 Modules:https://www.aliexpress.com/item/32467806585.html?spm=a2g0s.9042311.0.0.22f24c4dP75 xAS.

    But I'm not receiving anything through Teensy 3.6. I'm even tried swapping both MCP2551 modules as I have 5 of them available, thinking that maybe one of them could be faulty, with no success. I have the photos of my connections attached, and this is my code:

    Teensy 3.2 transmitter
    Code:
    #include <FlexCAN.h>
    #include <kinetis_flexcan.h>
    
    FlexCAN CANBus(500000);
    static CAN_message_t msg;
    
    void setup() {
      CANBus.begin();
      pinMode(LED_BUILTIN, OUTPUT); 
      delay(1000);
      Serial.println("CAN Transmitter Initialized");
    }
    
    void loop() {
        Serial.println("Sending");
        msg.id = 0x1;
        msg.len = 1;
        msg.buf[0] = 1;
        CANBus.write(msg);
        //digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
        delay(500);
    }
    Teensh 3.6 receiver
    Code:
    #include <FlexCAN.h>
    #include <kinetis_flexcan.h>
    
    FlexCAN CANBus(500000);
    static CAN_message_t msg;
    
    void setup() {
      CANBus.begin();
      pinMode(LED_BUILTIN, OUTPUT); 
      delay(1000);
      Serial.println("CAN Receiver Initialized");
    }
    
    void loop() {
        if (CANBus.available()) {
            Serial.println("Message Received");
            CANBus.read(msg);
            Serial.println(msg.buf[0]);
            digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
        }
    }
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	IMG_20191208_110433085.jpg 
Views:	15 
Size:	49.6 KB 
ID:	18364   Click image for larger version. 

Name:	IMG_20191208_110512273.jpg 
Views:	8 
Size:	55.8 KB 
ID:	18365  


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •