NefMoto

Technical => Communication Protocols => Topic started by: timr72 on June 13, 2022, 01:28:43 AM



Title: Generating CAN messages from Arduino for ME7.5
Post by: timr72 on June 13, 2022, 01:28:43 AM
Hi All,

I've got as far as I can, but I'm hitting an issue.  I have an ME7.5 ECU and 1.8T engine in my kitcar, none of the other units are there; so no ABS, no Airco, no Dashboard etc.  Although the car runs I am missing a speedo input for the ECU.  I've tried generating ABS pseudo traffic but this is not having the desired effect, I have also tried as Kombi1/2/3 same result.

Is there a way (And how do I do it) to check where the ECU expects to get the speed from Can Kombi, ABS or physical?
..and can I change the ECU to use VSS pulse on I think pin 54?

Binary and data useful attached; ECU and engine are BF/ME7.5 from a 2005 Audi A4 Convertible.


Code:
// CAN Receive and send Example
//

#include <mcp_can.h>
#include <SPI.h>

long unsigned int rxId;
unsigned char len = 0;
unsigned char rxBuf[8];
int EngineTemp;
int RoadSpeed;
int val;
char msgString[128];                        // Array to store serial string
char input[3];

#define CAN0_INT 2                              // Set INT to pin 2
MCP_CAN CAN0(10);                               // Set CS to pin 10


void setup()
{
  Serial.begin(115200);
 
  // Initialize MCP2515 running at 16MHz with a baudrate of 500kb/s and the masks and filters disabled.
  if(CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_16MHZ) == CAN_OK)
    Serial.println("MCP2515 Initialized Successfully!");
  else
    Serial.println("Error Initializing MCP2515...");
 
  CAN0.setMode(MCP_NORMAL);                     // Set operation mode to normal so the MCP2515 sends acks to received data.

  pinMode(CAN0_INT, INPUT);                            // Configuring pin for /INT input
 
  Serial.println("MCP2515 Library Receive Example...");
}

void loop()
{
  if(!digitalRead(CAN0_INT))                         // If CAN0_INT pin is low, read receive buffer
  {
    CAN0.readMsgBuf(&rxId, &len, rxBuf);      // Read data: len = data length, buf = data byte(s)
   
    if((rxId & 0x80000000) == 0x80000000)     // Determine if ID is standard (11 bits) or extended (29 bits)
      sprintf(msgString, "Extended ID: 0x%.8lX  DLC: %1d  Data:", (rxId & 0x1FFFFFFF), len);
    else
      if(rxId==0x288){
        byte data320[8] = {0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x00}; // Kombi1
        byte data420[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // Kombi2
        byte data520[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // kombi 3
        // 050H - Airbag 1,
        // 2C0 - Rad 1, 8mms raster, 5 bytes
        // 590 - Level 1, 48ms raster 6 byte
        // 5E0 - Climate, 20ms rast 8 byte
        // 573 - ZAS 1, 2 byte ?
        byte data1A0[8] = {0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x00}; //ABS1
        byte data4A0[8] = {0x00, 0x36, 0x00, 0x36, 0x00, 0x36, 0x00, 0x36}; //ABS3
       
        byte sndStat = CAN0.sendMsgBuf(0x320, 0, 8, data320);
        if(sndStat == CAN_OK){
          Serial.print("320 okay");
        } else {
          Serial.print("320 error");
        }
        sndStat = CAN0.sendMsgBuf(0x420, 0, 8, data420);
        if(sndStat == CAN_OK){
          Serial.print("\t420 okay");
        } else {
          Serial.print("\t420 error");
        }
        sndStat = CAN0.sendMsgBuf(0x520, 0, 8, data520);
        if(sndStat == CAN_OK){
          Serial.print("\t520 okay");
        } else {
          Serial.print("\t520 error");
        }

        sndStat = CAN0.sendMsgBuf(0x1A0, 0, 8, data1A0);
        if(sndStat == CAN_OK){
          Serial.print("\t1A0 okay");
        } else {
          Serial.print("\t1A0 error");
        }

        sndStat = CAN0.sendMsgBuf(0x4A0, 0, 8, data4A0);
        if(sndStat == CAN_OK){
          Serial.print("\t4A0 okay");
        } else {
          Serial.print("\t4A0 error");
        }
        Serial.println();
      } 
  }
}


Title: Re: Generating CAN messages from Arduino for ME7.5
Post by: fknbrkn on June 13, 2022, 02:29:47 AM
http://nefariousmotorsports.com/forum/index.php?topic=17021.0title=

Motor canbus runs at 1mbit


Title: Re: Generating CAN messages from Arduino for ME7.5
Post by: timr72 on June 14, 2022, 05:28:04 AM
http://nefariousmotorsports.com/forum/index.php?topic=17021.0title=

Motor canbus runs at 1mbit

Thanks for the link, I had read that thread.  What's interesting is the Arduino code I'm running reads CAN data reliably 0288 0280 etc and I can get all of that data.  I'll have a play around with 1000k and see if that influences the outcome.



Title: Re: Generating CAN messages from Arduino for ME7.5
Post by: BlackT on June 14, 2022, 07:39:15 AM
Motor CAN use 500 kbs, you have good config in code


Title: Re: Generating CAN messages from Arduino for ME7.5
Post by: tao13 on January 30, 2023, 11:33:27 AM
Do you tried to send some requests on CANBBUS (like pids) and did ecu respond?
I tried something but i think me7.5 doesn't know to respond on CANBUS, it only sent continously some ids.


Title: Re: Generating CAN messages from Arduino for ME7.5
Post by: prj on January 30, 2023, 11:43:31 AM
Do you tried to send some requests on CANBBUS (like pids) and did ecu respond?
I tried something but i think me7.5 doesn't know to respond on CANBUS, it only sent continously some ids.
There is no diagnostics on CAN on ME7.5, only on K-Line.


Title: Re: Generating CAN messages from Arduino for ME7.5
Post by: tao13 on February 01, 2023, 09:25:28 AM
Thanks again PRJ. From time to time you can be CUTE!
Please tell me if on KWP2000 can see and delete DTC? I saw in NefMotoECUFlasher exist something for DTC.
The initialisation procedure is the same with read variable from memory like ME7logger or not?
Thansk in advance!


Title: Re: Generating CAN messages from Arduino for ME7.5
Post by: musicleecher on February 12, 2023, 08:24:43 PM
Hi All,

I've got as far as I can, but I'm hitting an issue.  I have an ME7.5 ECU and 1.8T engine in my kitcar, none of the other units are there; so no ABS, no Airco, no Dashboard etc.  Although the car runs I am missing a speedo input for the ECU.  I've tried generating ABS pseudo traffic but this is not having the desired effect, I have also tried as Kombi1/2/3 same result.

Is there a way (And how do I do it) to check where the ECU expects to get the speed from Can Kombi, ABS or physical?
..and can I change the ECU to use VSS pulse on I think pin 54?

Binary and data useful attached; ECU and engine are BF/ME7.5 from a 2005 Audi A4 Convertible.


Code:
// CAN Receive and send Example
//

#include <mcp_can.h>
#include <SPI.h>

long unsigned int rxId;
unsigned char len = 0;
unsigned char rxBuf[8];
int EngineTemp;
int RoadSpeed;
int val;
char msgString[128];                        // Array to store serial string
char input[3];

#define CAN0_INT 2                              // Set INT to pin 2
MCP_CAN CAN0(10);                               // Set CS to pin 10


void setup()
{
  Serial.begin(115200);
  
  // Initialize MCP2515 running at 16MHz with a baudrate of 500kb/s and the masks and filters disabled.
  if(CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_16MHZ) == CAN_OK)
    Serial.println("MCP2515 Initialized Successfully!");
  else
    Serial.println("Error Initializing MCP2515...");
  
  CAN0.setMode(MCP_NORMAL);                     // Set operation mode to normal so the MCP2515 sends acks to received data.

  pinMode(CAN0_INT, INPUT);                            // Configuring pin for /INT input
  
  Serial.println("MCP2515 Library Receive Example...");
}

void loop()
{
  if(!digitalRead(CAN0_INT))                         // If CAN0_INT pin is low, read receive buffer
  {
    CAN0.readMsgBuf(&rxId, &len, rxBuf);      // Read data: len = data length, buf = data byte(s)
    
    if((rxId & 0x80000000) == 0x80000000)     // Determine if ID is standard (11 bits) or extended (29 bits)
      sprintf(msgString, "Extended ID: 0x%.8lX  DLC: %1d  Data:", (rxId & 0x1FFFFFFF), len);
    else
      if(rxId==0x288){
        byte data320[8] = {0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x00}; // Kombi1
        byte data420[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // Kombi2
        byte data520[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // kombi 3
        // 050H - Airbag 1,
        // 2C0 - Rad 1, 8mms raster, 5 bytes
        // 590 - Level 1, 48ms raster 6 byte
        // 5E0 - Climate, 20ms rast 8 byte
        // 573 - ZAS 1, 2 byte ?
        byte data1A0[8] = {0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x00}; //ABS1
        byte data4A0[8] = {0x00, 0x36, 0x00, 0x36, 0x00, 0x36, 0x00, 0x36}; //ABS3
        
        byte sndStat = CAN0.sendMsgBuf(0x320, 0, 8, data320);
        if(sndStat == CAN_OK){
          Serial.print("320 okay");
        } else {
          Serial.print("320 error");
        }
        sndStat = CAN0.sendMsgBuf(0x420, 0, 8, data420);
        if(sndStat == CAN_OK){
          Serial.print("\t420 okay");
        } else {
          Serial.print("\t420 error");
        }
        sndStat = CAN0.sendMsgBuf(0x520, 0, 8, data520);
        if(sndStat == CAN_OK){
          Serial.print("\t520 okay");
        } else {
          Serial.print("\t520 error");
        }

        sndStat = CAN0.sendMsgBuf(0x1A0, 0, 8, data1A0);
        if(sndStat == CAN_OK){
          Serial.print("\t1A0 okay");
        } else {
          Serial.print("\t1A0 error");
        }

        sndStat = CAN0.sendMsgBuf(0x4A0, 0, 8, data4A0);
        if(sndStat == CAN_OK){
          Serial.print("\t4A0 okay");
        } else {
          Serial.print("\t4A0 error");
        }
        Serial.println();
      }  
  }
}


I'm doing something similar on my 1.8T swapped '82 Toyota Carina. I'm using an ESP32 and a CAN transceiver to communicate with the ECU. Indeed the CAN is 500kbps not 1mbps. I am doing this to build a custom Dashboard for it. Right now I can get RPM and Engine temp. I'd like to get a bit more information but I'm not sure how I'll decode the CAN frames the ECU outputs.
I'm also using the ESP32 to feed VSS to the ECU, I'm getting the actual speed from GPS. I think I might have been able to send good data to the ECU because I felt a difference in power but I haven't been able to test it thoroughly yet.
These are the frames I'm currently sending (not tested thoroughly, might still not be working fine after all):

Code:
#define lo8(x) ((int)(x)&0xff)
#define hi8(x) ((int)(x) >> 8)

... ... ...

    speedL = lo8(speed);
    speedH = hi8(speed);

    CAN_frame_t tx_frame;

    tx_frame.FIR.B.FF = CAN_frame_std;
    tx_frame.MsgID = 0x320; //( 320 Kombi 1 ID - 420 Kombi 2)
    tx_frame.FIR.B.DLC = 8;
    tx_frame.data.u8[0] = 0x00;
    tx_frame.data.u8[1] = (speedL * 100);
    tx_frame.data.u8[2] = (speedH * 100);
    tx_frame.data.u8[3] = 0x00;
    tx_frame.data.u8[4] = 0x00;
    tx_frame.data.u8[5] = 0x00;
    tx_frame.data.u8[6] = 0x00;
    tx_frame.data.u8[7] = 0x00;
    ESP32Can.CANWriteFrame(&tx_frame);

    tx_frame.FIR.B.FF = CAN_frame_std;
    tx_frame.MsgID = 0x1A0; //(ABS1 ID)
    tx_frame.FIR.B.DLC = 8;
    tx_frame.data.u8[0] = 0x18;
    tx_frame.data.u8[1] = speedL;
    tx_frame.data.u8[2] = speedH;
    tx_frame.data.u8[3] = 0x00;
    tx_frame.data.u8[4] = 0xFE;
    tx_frame.data.u8[5] = 0xFE;
    tx_frame.data.u8[6] = 0x00;
    tx_frame.data.u8[7] = 0xFF;
    ESP32Can.CANWriteFrame(&tx_frame);

    tx_frame.FIR.B.FF = CAN_frame_std;
    tx_frame.MsgID = 0x5A0; //(ABS2 ID)
    tx_frame.FIR.B.DLC = 8;
    tx_frame.data.u8[0] = 0xFF;
    tx_frame.data.u8[1] = speedL;
    tx_frame.data.u8[2] = speedH;
    tx_frame.data.u8[3] = 0x01;
    tx_frame.data.u8[4] = 0x00;
    tx_frame.data.u8[5] = lo8(12345);
    tx_frame.data.u8[6] = hi8(12345);
    tx_frame.data.u8[7] = 0xAD;
    ESP32Can.CANWriteFrame(&tx_frame);


The Library I'm using for the CAN comms is called ESP32CAN.
I believe you have to have your ECU configured to accept VSS through CAN instead with CWGGVFZG = 1 (I did not have the opportunity to check your file)

I hope it helps and if you get to test it please post an update :)


Title: Re: Generating CAN messages from Arduino for ME7.5
Post by: prj on February 13, 2023, 03:28:02 AM
Speed via GPS is horrible, better not send any speed at all.

All the info about can frames of this ECU is in the FR.


Title: Re: Generating CAN messages from Arduino for ME7.5
Post by: musicleecher on February 13, 2023, 10:07:23 AM
Speed via GPS is horrible, better not send any speed at all.

All the info about can frames of this ECU is in the FR.

Why do you think it is horrible?


I can always resort to reading the ABS rings on the front wheels and calculating Km/h


Title: Re: Generating CAN messages from Arduino for ME7.5
Post by: prj on February 13, 2023, 10:12:13 AM
Why do you think it is horrible?
Because speed especially matters to ECU during starting/stopping. And GPS is too slow for that.
Quote
I can always resort to reading the ABS rings on the front wheels and calculating Km/h
Much better option.


Title: Re: Generating CAN messages from Arduino for ME7.5
Post by: musicleecher on February 13, 2023, 11:46:25 AM
Because speed especially matters to ECU during starting/stopping. And GPS is too slow for that.

Thanks for the clarification! Much appreciated!

BTW, If you're willing to help, do you know at what rate the ECU expects the VSS messages? Like I can flood the ECU with the CAN messages but I'd much rather send them from x ms to x ms..


Title: Re: Generating CAN messages from Arduino for ME7.5
Post by: fknbrkn on February 13, 2023, 11:54:55 AM
Thanks for the clarification! Much appreciated!

BTW, If you're willing to help, do you know at what rate the ECU expects the VSS messages? Like I can flood the ECU with the CAN messages but I'd much rather send them from x ms to x ms..

Just read the FR, CAN module
but imo its not worth, works fine without


Title: Re: Generating CAN messages from Arduino for ME7.5
Post by: musicleecher on February 13, 2023, 01:01:54 PM
Just read the FR, CAN module
but imo its not worth, works fine without

Does it? I'd say otherwise because the engine feels like it's not producing full power without VSS


Title: Re: Generating CAN messages from Arduino for ME7.5
Post by: prj on February 13, 2023, 03:37:41 PM
Does it? I'd say otherwise because the engine feels like it's not producing full power without VSS
VSS does not affect power.
Also, leave your "feels" for your partner and use logging for the ECU.


Title: Re: Generating CAN messages from Arduino for ME7.5
Post by: tao13 on February 14, 2023, 12:52:51 PM
PRJ, NYET , did you know if i start a kwp2000 session and read variables from memory, canbus will be slower, the ecu will send only few ID's on canbus?
I try to use both in the same time on my arduino, can listen and parse some id's but when i began KWP2000 and it is enought to read one variable , i don't receive all id's on canbus.
Exist 2 cause:
1 kwp2000 get a lot of time to process and intrerrupt the canbus
2 or what i asked upstairs, when a kwp session is started the canbus is limited by ecu.
Please if you have some info, tell us.
Thanks in advance


Title: Re: Generating CAN messages from Arduino for ME7.5
Post by: BlackT on February 14, 2023, 09:56:56 PM
Did you thibk that maybe arduino is to slow to do all tasks  ::)


Title: Re: Generating CAN messages from Arduino for ME7.5
Post by: tao13 on February 14, 2023, 11:49:50 PM
NO, isn't , the first impresion is kwp2000 block for some ms the process and can id's are few , i receive only 2-3 id's!


Title: Re: Generating CAN messages from Arduino for ME7.5
Post by: dal on February 15, 2023, 05:12:58 AM
PRJ, NYET , did you know if i start a kwp2000 session and read variables from memory, canbus will be slower, the ecu will send only few ID's on canbus?
I try to use both in the same time on my arduino, can listen and parse some id's but when i began KWP2000 and it is enought to read one variable , i don't receive all id's on canbus.
Exist 2 cause:
1 kwp2000 get a lot of time to process and intrerrupt the canbus
2 or what i asked upstairs, when a kwp session is started the canbus is limited by ecu.
Please if you have some info, tell us.
Thanks in advance

I dont think so, because I have 3DcolorMFD on my A3 cluster, and the screen connects to the ecu via kline as soon as I turn the key on. And the data that comes from canbus stays perfect, I can tell by the rpm that comes from CAN, fast refresh rate as hell.


Title: Re: Generating CAN messages from Arduino for ME7.5
Post by: tao13 on February 15, 2023, 05:55:16 AM
I made a test today, put me7loger to make log on a laptop and i sniffed the can with my arduino. The can works ok. So it is a problem from my sketch or speed of arduino but, i tried with mega2560 and esp32 too. The same issue. I will try more.
PS:
the speed/baud rate of initialise connection slow init with ecu is 10400 , the log speed it is different than this?
In me7logger if i chose per example 38400 log speed it is only for log but at connection with ecu it is only 10400?


Title: Re: Generating CAN messages from Arduino for ME7.5
Post by: dream on May 21, 2023, 02:48:24 AM
I just got into same thing with a project.
I use ME7.5 for engine, 2x ECUmaster PMU for controlling everything in the car and Arduino for the cluster  especially speedometer. The speedo was originally mechanical.

I use the CAN messages from the ECU for the PMU to use RPM and ECT.
On the other side I am going to send speedo with Arduino to ECU because I will use 2 step launch.

I already tested to see if the ECU will receive the broadcasted CAN messages from the PMU. It works. All the communication DTC were gone.

Only make sure you are broadcasting/receiving it on the right speed, as for 'motor1' works at 10ms (100Hz).