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

Thread: Teensy 3.2 Reading Megasquirt CAN Bus

  1. #1
    Member
    Join Date
    Jan 2016
    Location
    Tx
    Posts
    48

    Teensy 3.2 Reading Megasquirt CAN Bus

    Hello, I am working on a small project using a Teensy 3.2 to read data via CAN from a Microsquirt engine control computer. http://www.msextra.com/manuals/ms3manuals/

    I have a Teensy 3.2, running Arduino 1.6.7 on Windows 8. I've loaded the CANListen Sketch found on these forums. I have everything hooked up and it appears I am seeing data, however it seems to be the same data over and over until I power cycle the Megasquirt then the data changes, but only once and it goes back to the same stream. I have hooked up some of the inputs of the Megasquirt and changed their (things like throttle position, RPM, engine temp, etc.) values, with no change to the CAN data stream. The message idea appears correct, but again the data in serial monitor does not change. It seems as if the program simply grabs the first bit of data and loops it endlessly.

    Example:

    This repeats
    ID: 0x5E8 DLC: 8 DATA: 0 5F 0 0 7 8 0 3

    Power Cycle MS and this repeats until next powercycle.

    ID: 0x5E8 DLC: 8 DATA: 0 6F 0 0 7 8 0 25

    And so on.

    For further information here is some documentation to the MS CAN protocol, this PDF details out the "Dash Broadcasting" feature which I am using. Simply put it is a smaller data set for things like DIY guages and displays. http://www.msextra.com/doc/pdf/Megas..._Broadcast.pdf

    Code:
    // -------------------------------------------------------------
    // CANlisten for Teensy 3.1
    // by kjn
    //
    // This test enables the CAN interface on the teensy and prints all recieved packets
    // to the serial console. The RX FIFO buffer may overrun at high bus utilisation
    // states. This is untested.
    
    #include <FlexCAN.h>
    
    // Specify CAN Baudrate. Currently 125k, 250k, 500k, 1M are supported in teensydrino 1.20
    int baud = 500000;
    
    int led = 13;
    FlexCAN CANbus(baud);
    static CAN_message_t rxmsg;
    
    void setup(void)
    {
      
      Serial.begin(9600);
      while (!Serial) ; // wait for Arduino Serial Monitor
      Serial.println("Teensy 3.1 CANlisten Example"); 
      
      //boolean result = CANbus.begin(); -- Currently .begin object doesn't return state of bus
      //Serial.print("CAN begin successful: ");
      //Serial.println(result ? "YES" : "NO");
      
      CANbus.begin();
      
      //Light on to indicate on-bus state
      pinMode(led, OUTPUT);
      digitalWrite(led, 1);
      
    }
    
    void loop(void){
      
    //Poll Rx FIFO
    while ( CANbus.read(rxmsg) ) {
    //when message available
    
    //light off to indicate FIFO is not being polled
    digitalWrite(led, 0);
    
    //construct string  
    String text = "ID: 0x";
    text = String(text + String(rxmsg.id, HEX));
    text = String(text + " DLC: ");
    text = String(text + String(rxmsg.len, HEX));
    
    //check if DLC is >0 append string as required
    if (rxmsg.len >= 1)
    {
      text = String(text + " DATA: ");
    }
      
    //construct string for available bytes (trunctate to DLC to avoid reading garbage)
    for( int idx=0; idx<rxmsg.len; ++idx ) 
    {
       text = String(text + String(rxmsg.buf[idx],HEX));
       text = String(text + " ");
    }
      
    //print result
    Serial.println(text);
    
    //LED back on to indicate watching Rx FIFO  
    digitalWrite(led, 1); 
    } 
    
    }

  2. #2
    Junior Member
    Join Date
    Mar 2015
    Location
    Sewickley, PA
    Posts
    11
    Let me ask you a few questions first. What Microsquirt Firmware Version are you running ? I assume you have broadcasting enabled in TunerStudio. What is the interval set to ?? What data do you have it sending?? Do you have an running engine or a JimStim?

    Mark
    Last edited by K3FY; 01-24-2016 at 04:03 AM.

  3. #3
    Member
    Join Date
    Jan 2016
    Location
    Tx
    Posts
    48
    Quote Originally Posted by K3FY View Post
    Let me ask you a few questions first. What Microsquirt Firmware Version are you running ? I assume you have broadcasting enabled in TunerStudio. What is the interval set to ?? What data do you have it sending?? Do you have an running engine or a JimStim?

    Mark
    Hi Mark, it is a cased Microsquirt V3 running 3.4.1beta1, although James posted that this is labeled as "This is now released as "3.4.1 release""

    Yes, I have tried several different combinations, but went back to enabling "Dash Broadcasting" in Tuner Studio. The description of this is a smaller subset of values for items like digital displays and dashboards. Mostly gauge data. The Default trans rate is 20 Hz (although I poked around with a few different values, but they did not seem to change anything) with a default base CAN ID of 1512.

    This was running with a JimStim, I was changing data (like RPM and TPS) with no change in the data fields in the Serial Monitor. I even tried just powering up the Microsquirt via a bench top power supply, had same results.


    Thanks!
    Raymond

  4. #4
    Junior Member
    Join Date
    Mar 2015
    Location
    Sewickley, PA
    Posts
    11
    Give a me a couple days, I will give it a try. I have a microsquirt on a running engine. I currently have two teensy3.1s talking over can bus to each other. I will connect the microsquirt to the mix and see if I can receive the 1512 packet with live data.

    Mark

  5. #5
    Member
    Join Date
    Jan 2016
    Location
    Tx
    Posts
    48
    Thank you!

  6. #6
    Member
    Join Date
    Jan 2016
    Location
    Tx
    Posts
    48
    So I have been messing around with this some more. It seems as if either;

    1. My Microsquirt is only broadcasting one type of message ID, the base ID and nothing more. <---- I really doubt this as obviously I am a noob flopping around trying to figure this out.
    2. For whatever reason the code only pics up the base message ID.

    I imagine it's something in the code, but I am not sure what. I have fiddled with all the different settings in the Microsquirt, Dash Broadcasting, Real Time Data Broadcasting, etc. For whatever reason I only see the default message ID. I can change that ID and I see it reflected in the broadcast, but no data comes over.

  7. #7
    Junior Member
    Join Date
    Mar 2015
    Location
    Sewickley, PA
    Posts
    11
    OK today I upgraded the firmware of my MicroSquirt to 3.4.1 and turned on Dash Broadcasting. I added some code to an existing program that I am using on a Teensy3.1 and read coolant temperature from the 1512 ID. It updated as I applied heat to the sending unit and cooled down when I removed heat. I did not start the engine. That is another story. Here are a few lines of code I used in my program to read the coolant temperature. Hopefully this will help you. I hope to get the timing reset on the engine tomorrow and start it. I will be adding more Dash Data over the week end. BTW Do you have your EOL resistor on the bus ?? On the Chinese transceiver boards I bought from ebay adding a jumper actually disconnects the EOL resistor. Counter-intuitive in my book.

    FlexCAN CANbus(500000);
    static CAN_message_t txmsg,rxmsg;
    unsigned int CLT

    //In Setup
    CANbus.begin();


    //In Main Loop
    if ( CANbus.read(rxmsg) ) {

    switch (rxmsg.id) {
    case 1512:

    CLT=(int)(word(rxmsg.buf[4], rxmsg.buf[5]));

    break;
    case 1513:
    // extract other data as needed here
    break;
    case 1514:
    // extract other data as needed here
    break;
    case 1515:
    // extract other data as needed here
    break;
    case 1516:
    // extract other data as needed here
    break;
    }
    }

  8. #8
    Member
    Join Date
    Jan 2016
    Location
    Tx
    Posts
    48
    I thought the 3.2 Teensy only needed the Microsquirt as the transceiver? Also I do not have a 120 ohm resistor, would I simply run it between CANH and CANL on my breadboard?

    Also did you get any other message IDs than 1512? That's the base for dash broadcasting. Your code helped me decypher some of the values, but I still only have 1512's come across.
    Last edited by Raymond_B; 01-29-2016 at 08:27 AM.

  9. #9
    Junior Member
    Join Date
    Mar 2015
    Location
    Sewickley, PA
    Posts
    11
    I was typing fast on my reply last night as my laptop battery was dying. I will be attempting other ID's today. Also I need to check TDC and reset the timing I think the firmware update threw off my initial offset. I am not sure as I haven't tried starting this motor in 6 months. I should have trying starting it before the firmware update but I did not. So more information to come

    You need one of these or similar between the Teensy3.2 and the can bus to work properly http://www.ebay.com/itm/SN65HVD230-c...item20fb138c22

    If you have CANH and CANL signal you must already have a transceiver chip?? Which chip do you have? It needs to be 3.3v!

    If you only have The Teensy3.2 and the Microsquirt you need the EOL Resistor across CANH CANL . 120 Ohm.

    The board I mentioned above has a build in EOL resistor. As I mentioned there is a jumper for it. Jumper on no resistor, Jumper off resistor active.

    Mark

  10. #10
    Member
    Join Date
    Jan 2016
    Location
    Tx
    Posts
    48
    Yeah, I'm dumb When I saw Teensy had CAN support I thought that meant it could go straight on the CAN bus. I should have known it could not because Teensy has TX and RX and no CANH and CANL, duh...

    Thank you very much for your help! I can say this has been a good learning experience, I've always wanted to mess around with microcontrollers.

  11. #11
    Member
    Join Date
    Jan 2016
    Location
    Tx
    Posts
    48
    Also I found that transceiver on Amazon! It's a couple bucks more, but I can get it tomorrow!!!

    http://www.amazon.com/gp/product/B00...ilpage_o00_s00

  12. #12
    Junior Member
    Join Date
    Mar 2015
    Location
    Sewickley, PA
    Posts
    11
    Glad your headed in the right direction now. I started the engine A OK. It was a problem with throttle linkage that was connected to an automatic governor. Now I will see if I can get some more data from the MicroSquirt.

  13. #13
    Member
    Join Date
    Jan 2016
    Location
    Tx
    Posts
    48
    Quote Originally Posted by K3FY View Post
    Glad your headed in the right direction now. I started the engine A OK. It was a problem with throttle linkage that was connected to an automatic governor. Now I will see if I can get some more data from the MicroSquirt.
    Good deal, what vehicle are you running the Microsquirt on?

    My setup is a 95 Lightning with MS3/3x running the engine and Microsquirt for the trans (E4OD). It's all apart though for a major engine rebuild.

  14. #14
    Member
    Join Date
    Jan 2016
    Location
    Tx
    Posts
    48
    Everything working good! Thanks again!

  15. #15
    Junior Member
    Join Date
    Mar 2015
    Location
    Sewickley, PA
    Posts
    11
    Your welcome. I changed my code around a little as I needed to restrict my data to two byte integers.

    I am now using:
    uint16_t CLT, RPM, MAP, MAT, BATTV, TPS, GSI1, GSI2;

    switch (rxmsg.id)
    case 1512:
    MAP=((int16_t((rxmsg.buf[1]) | (rxmsg.buf[0] << 8)))/10);
    RPM=(int16_t((rxmsg.buf[3]) | (rxmsg.buf[2] << 8)));
    CLT=((uint16_t((rxmsg.buf[5]) | (rxmsg.buf[4] << 8)))/10);
    TPS=(int16_t((rxmsg.buf[7]) | (rxmsg.buf[6] << 8)));
    break;
    case 1513:
    MAT=((int16_t((rxmsg.buf[5]) | (rxmsg.buf[4] << 8)))/10);
    break;
    case 1514:
    break;
    case 1515:
    BATTV=((int16_t((rxmsg.buf[1]) | (rxmsg.buf[0] << 8)))/10);
    GSI1= ((int16_t((rxmsg.buf[3]) | (rxmsg.buf[2] << 8)))/10);
    GSI2= ((int16_t((rxmsg.buf[5]) | (rxmsg.buf[4] << 8)))/10);
    break;
    case 1516:
    break;
    default: // not a broadcast packet

    You asked what kind of vehicle. Actually I have the Microsquirt on a GM 1.6L 4 cyl propane engine which powers a narrow aisle forklift. The Teensy3.1 handles steering the 4 wheels, driver input and dash. Ha Ha not what you thought I'll bet!!

    Although I do have a MegaSquirt 3 Pro on my Factory Five GTM.
    Click image for larger version. 

Name:	419856_344471065637888_2110245708_n.jpg 
Views:	321 
Size:	103.3 KB 
ID:	6254

  16. #16
    Member
    Join Date
    Jan 2016
    Location
    Tx
    Posts
    48
    OK, wow on both counts

    Gorgeous car!

  17. #17
    Hello. I have too Teensy 3.2 and SN65HVD230 transreceiver. I'm trying to read CAN from MS2. I only get "teensy can listen example" to the serial monitor. What I'm doing wrong? I measured that there was no 120 ohms between can pins at transreceiver. It is then dodgy? I soldered resistor on it but it didnt make any difference. I've connected transreceiver tx rx pins to teensys can marked pins. Is this correct? Led on teensy stays lit after few seconds.
    Dash broadcasting is enabled and code is 3.4.2 in MS.

Posting Permissions

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