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

Thread: Teensy 3.6 with WaveShare CAN not working

  1. #1
    Junior Member
    Join Date
    Oct 2019
    Posts
    8

    Teensy 3.6 with WaveShare CAN not working

    Hello,

    I am trying to capture vehicle speed through CAN, however Can0 object is unavailable.

    Hardware:
    1. Teensy 3.6
    2. WaveShare CAN
    3. Teensy Audio Shield
    4. DB9 Connector



    Software & OS:
    1. Windows 10
    2. Arduino 1.8.7


    Pictures:

    From web(OBDII to DB9):
    Click image for larger version. 

Name:	OBDII to DB9.jpg 
Views:	6 
Size:	39.1 KB 
ID:	18012

    Click image for larger version. 

Name:	Setup4.jpg 
Views:	7 
Size:	74.6 KB 
ID:	18009

    Click image for larger version. 

Name:	Setup5.jpg 
Views:	6 
Size:	76.5 KB 
ID:	18010

    Click image for larger version. 

Name:	Setup6.jpg 
Views:	7 
Size:	77.1 KB 
ID:	18011

    Code:

    Code:
    #include <FlexCAN.h>
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    
    //#include <SD.h>
    #include <SerialFlash.h>
    
    AudioControlSGTL5000     sgtl5000_1;
    float maxVol = 0.4;
    
    float wheel_speed[] = {0.0, 0.0, 0.0, 0.0};  //LF, RF, LR, RR
    
    
    class ExampleClass : public CANListener
    {
      public:
        void printFrame(CAN_message_t &frame, int mailbox);
        void gotFrame(CAN_message_t &frame, int mailbox); //overrides the parent version so we can actually do something
        void updateSnd(CAN_message_t &frame, int mailbox);
    };
    void ExampleClass::printFrame(CAN_message_t &frame, int mailbox)
    {
      
        Serial.print("ID: ");
        Serial.print(frame.id, HEX);
    
        Serial.print(frame.id);
    
        Serial.print(" Data: ");
    
        for (int c = 0; c < frame.len; c++)
        {
          Serial.print(frame.buf[c], BIN);
          Serial.write(' ');
        }
        Serial.write('\r');
        Serial.write('\n');
    
    }
    void ExampleClass::gotFrame(CAN_message_t &frame, int mailbox)
    {
      printFrame(frame, mailbox);
      updateSnd(frame, mailbox);
    }
    void ExampleClass::updateSnd(CAN_message_t &frame, int mailbox)
    {
        
      if (frame.id == 840) //wheel speeds 1
      {
        //parse wheel speed here//    
        wheel_speed[0] = ((frame.buf[1]) + (frame.buf[0] * 256)) * 0.03125;
        wheel_speed[1] = ((frame.buf[3]) + (frame.buf[2] * 256)) * 0.03125;
        //End Parse Wheel Speed//
      }
      if (frame.id == 842) //wheel speeds 2
      {
        //parse wheel speed here//    
        wheel_speed[2] = ((frame.buf[1]) + (frame.buf[0] * 256)) * 0.03125;
        wheel_speed[3] = ((frame.buf[3]) + (frame.buf[2] * 256)) * 0.03125;
        //End Parse Wheel Speed//
      }
     
    }
    ExampleClass exampleClass;
    
    
    void setup() {
      // put your setup code here, to run once:
    
      
      sgtl5000_1.enable();
      sgtl5000_1.volume(maxVol);
      Serial.begin(115200); //115200 bits/second
      Can0.begin(500000); // Start CAN bus
      
    
      //if using enable pins on a transceiver they need to be set on
      pinMode(2, OUTPUT); 
      digitalWrite(2, HIGH); 
    
      Can0.attachObj(&exampleClass); //CAN bus handler
      exampleClass.attachGeneralHandler();
     
    
      if (Can0.available())
      {
        Serial.print("Successful connection to CAN");
      }
      else
      {
        Serial.println("CAN connection unsuccessful");
      }
    
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
    
      
    //  Serial.print("Wheel Speed 0: ");
    //  Serial.println(wheel_speed[0]);
    //
    //  Serial.print("Wheel Speed 1: ");
    //  Serial.println(wheel_speed[1]);
    //
    //  Serial.print("Wheel Speed 2: ");
    //  Serial.println(wheel_speed[2]);
    //
    //  Serial.print("Wheel Speed 3: ");
    //  Serial.println(wheel_speed[3]);
    
    }
    Supply voltage to WaveShare CAN is 3.3V. Voltage between Can High and ground is also 3.3V. Same with CAN Low and ground. I have checked the voltages at pin3 and pin4 with respect to ground as well. They also read 3.3 V.

    Not really sure what I am missing here. Any help is appreciated!!

    --Mayo

  2. #2
    Junior Member
    Join Date
    Oct 2019
    Posts
    8
    Any suggestions guys?

    From other forum threads, I confirmed that there is 120 ohm resistance between CAN H and CAN L.

    I think I am not understanding FlexCAN correctly. Can someone please tell me where I am going wrong?

  3. #3
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,133
    Try out IFCT, it has very easy examples to get up and running

Posting Permissions

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