Closed MurzzZ closed 4 years ago
Change this line: https://github.com/aster94/Keyword-Protocol-2000/blob/243d79a08a9dde20b574659909be3a152441e711/extras/ECU_Emulator/ECU_Emulator.py#L71 to 10400 Tell me if this makes it work again
much better, but still there is an error: Port Info:
Serial<id=0x3401e80, open=True>(port='COM7', baudrate=10400, bytesize=8, parity='O', stopbits=1, timeout=2, xonxoff=False, rtscts=False, dsrdtr=False)
Wrong checksum!
['0x81', '0x91', '0xfc', '0x81', '0xf0']
Expected: 0x8f
Sending Echo
81
1
11
F1
11
E1
81
4
Receiving:
1 - unexpected header
F0 - ECU is communicating with this address
Unexpected response: Initialization failed
can you try to change also this:
I forgot to check the python script before the newer arduino version
nothing in python shell:
Starting ECU Emulator
Port already opened
Port Info:
Serial<id=0x3d71e80, open=True>(port='COM7', baudrate=10400, bytesize=8, parity='N', stopbits=1, timeout=2, xonxoff=False, rtscts=False, dsrdtr=False)
Initialize K-line
Starting sequence
Sending Echo
81
81
11
F1
11
FC
81
4
Receiving:
81 - format physical
F0 - ECU is communicating with this address
Unexpected response: Initialization failed
and in serial port monitor, i see only echo:
19:59:39 +00:00.185 Capture started on COM7
19:59:48 +00:09.347 Port opened
Process: \Device\HarddiskVolume4\Program Files (x86)\Python38-32\pythonw.exe
PID: 19272
19:59:48 +00:09.400 Set baud rate: 10400 bps
19:59:48 +00:09.401 Set RTS: on
19:59:48 +00:09.403 Set DTR: on
19:59:48 +00:09.406 Set data bits: 8 bits
19:59:48 +00:09.406 Set stop bits: 1 bit
19:59:48 +00:09.406 Set parity: None
19:59:48 +00:09.406 Set flow control: None
19:59:55 +00:16.242 > 0000 c1
19:59:55 +00:16.243 < 0000 c1
19:59:55 +00:16.268 > 0000 91
19:59:55 +00:16.268 < 0000 91
19:59:55 +00:16.269 > 0000 fc
19:59:55 +00:16.269 < 0000 fc
19:59:55 +00:16.294 > 0000 c1
19:59:55 +00:16.295 < 0000 c1
19:59:55 +00:16.296 > 0000 f0
19:59:55 +00:16.296 < 0000 f0
ok, actually I finished the ideas, the truth is that since the arduino code started working well I didn't use the python emulator I found it was better to test with the real ecu
ok. Thank. I'll try with ecu later, and write the result.
which motorbike are you using?
Kawasaki Versys 650 2011
It Will work without problems ✌️
Il sab 9 mag 2020, 19:38 MurzzZ notifications@github.com ha scritto:
Kawasaki Versys 650 2011
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/aster94/Keyword-Protocol-2000/issues/6#issuecomment-626210837, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFBUBTXOJJ2BKIW2XGNVALTRQWIINANCNFSM4M43CBHQ .
I tried a test on a motorcycle. The connection is also not established. I connected to the TX/RX to see what is being sent to the ECU, and I see that the sequence sent is different from the request. request sent from the debug:
User Input: i
Initialize K-line
Starting sequence
Sending Echo
81
12
F1
81
4
request sent to the ECU:
c1 91 fc c1 f0
I also tried to init K-Line manualy by sending request: 81 11 f1 81 04, and i see that ECU answering: 80 f1 11 03 c1 ea 8f bf.
Maybe I doing somethng wrong? I use basic_working.ino and define the KAWASAKI motorcycle in ECU(). L9637D connected to pins 16 and 17.
It looks like it is sending out the wrong sequence, can you post exactly the code you are using? also are you sure you have the last version of the library?
#include <Arduino.h>
#include "KWP2000.h"
#include <M5Stack.h>
// Different core have different way to use a Serial port
#if defined(ARDUINO_ARCH_ESP32)
HardwareSerial bike(2);
#define TX_PIN 17
#elif defined(ARDUINO_ARCH_STM32)
HardwareSerial bike(PA3, PA2); // RX and TX
#define TX_PIN PA2
#else
#define bike Serial3
#define TX_PIN 14
#endif
#define debug Serial
// Replace YOUR_MOTORBIKE with SUZUKI, KAWASAKI, YAMAHA or HONDA
//KWP2000 ECU(&bike, TX_PIN, YOUR_MOTORBIKE);
KWP2000 ECU(&bike, TX_PIN, KAWASAKI);
void setup()
{
ECU.enableDebug(&debug, DEBUG_LEVEL_VERBOSE, 115200);
//Serial.begin(); this is not needed because we use then same serial as the debug
//ECU.enableDealerMode(pin); // This is available only on Suzuki bikes
}
void loop()
{
if (debug.available() > 0)
{
char in = debug.read();
debug.print("User Input: ");
debug.println(in);
switch (in)
{
case 'i':
while (ECU.initKline() == 0)
{
;
}
break;
case 'd':
ECU.setDealerMode(!ECU.getDealerMode());
break;
case 't':
ECU.readTroubleCodes();
break;
case 's':
ECU.requestSensorsData();
ECU.printSensorsData();
break;
case 'p':
ECU.printStatus();
break;
case 'c':
while (ECU.stopKline() == 0)
{
;
}
break;
}
in = 0;
}
ECU.keepAlive();
}
platformio.ini
[env:m5stack-core-esp32]
platform = espressif32
board = m5stack-core-esp32
framework = arduino
lib_deps = https://github.com/aster94/Keyword-Protocol-2000.git
If I run the same example I get:
Sending Echo
81
11
F1
81
4
11 not 12
also where did you take these number from:
request sent to the ECU: c1 91 fc c1 f0
did you used a logic analyzer?
I just tried in a completely new workspace using a platformio file like yours:
[env:test]
platform = espressif32
board = lolin32
framework = arduino
lib_deps = https://github.com/aster94/Keyword-Protocol-2000.git
and same code (except for removing the header #include <M5Stack.h>
)
can you try to do the same or that library is needed in your environment?
You don't need to test it with the ECU you can just print here the serial output
I am using IO Ninja Serial Port Monitor. I tried as you wrote: disabled M5Stack.h using your ini. The serial output for the same request (Initialize K-line) is different:
Set baud rate: 10400 bps
Set RTS: off
Set DTR: off
Set data bits: 8 bits
Set stop bits: 1 bit
Set parity: None
Set flow control: None
>> 81 91 fc 81 f0 >> 1 attempt
>> c1 91 fc c1 f0 >> 2 attempt
>> 81 91 fc 81 f0 >> 3 attempt
>> c1 91 fc c1 f0 >> 4 attempt
upd: if the com-port is open with the settings below, all data is the same:
Set baud rate: 10400 bps
Set RTS: on
Set DTR: off
Set data bits: 8 bits
Set stop bits: 1 bit
Set parity: None
Set flow control: None
Set baud rate: 10400 bps
Set RTS: on
Set DTR: off
Set data bits: 8 bits
Set stop bits: 1 bit
Set parity: None
Set flow control: None
Set DTR: off
>> c1 91 fc c1 f0
>> c1 91 fc c1 f0
can you post what you get from the debug? (the serial port that is connected to your esp and you probably use to program the board)
can you post what you get from the debug?
User Input: i Initialize K-line Starting sequence Sending Echo 81 11 F1 81 4 No response from the ECU Initialization failed
and that is what i see in the logic analyzer https://ibb.co/TcTpxzy https://ibb.co/zsVY8Hj https://ibb.co/vQJVMFV
now it is sending the correct request, but you didn't change anything in your code, except for the include, strange The logic captures are wrong, it is like your board is sending two bytes one right after the other It is similar to an old issue I had on the esp32 https://github.com/espressif/arduino-esp32/issues/2004 but it was fixed months ago
If you are using platformio you should already be using the lastest esp32 core, if not please update it Don't you have a esp32 in a different board, do you?
i have esp32 devkit v1 and arduino mega 256. Espressif 32 ver 1.12.1
esp32 devkit v1 the same result: request from debug: 81 11 F1 81 4 data in Serial2: c1 91 fc c1 f0 logic analizer: https://ibb.co/0tvQcRG
mega 256: request from debug: 81 11 F1 81 4 data in Serial3: 00 c1 91 f1 c1 84 logic analizer: https://ibb.co/nR3DLQn https://ibb.co/pZWPwLv
The mega Is correct, you are using a version of the esp32 core where the fix is not included
Also the program you are using to get the serial data is not reliable, you can see you have different values from the logic capture
I found the problem 😄
The error is not with platformio, not with your hardware. The last esp32 release is 7 months old and it doesn't include the fix of the serial. Until the esp32 team doesn't release a new version you would need to manually include the fix https://github.com/espressif/arduino-esp32/commit/ed220bd0420236e9ff95888f7459f0eb9c97a570
Thank you very much! after fixing esp32-hal-uart.c, seems that timing is correct. will test on the ECU in few days. https://ibb.co/XFqKLTz
but still strange, that the Serial Port monitor Reads wrong HEX: c1 91 f1 c1 84, that's why the emulator dosn't works. it recieves wrong HEX. I tried another project based on Arduino Nano and I see the correct data.
Session started
Capture started on COM10
>> 80 11 f1 02 21 0a af
<< 80 f1 11 03 61 0a a8 98
>> 80 11 f1 02 21 09 ae
<< 80 f1 11 04 61 09 3c 24 50
>> 80 11 f1 02 21 07 ac
<< 80 f1 11 03 61 07 44 31
>> 80 11 f1 02 21 06 ab
<< 80 f1 11 03 61 06 89 75
>> 80 11 f1 02 21 0b b0
<< 80 f1 11 03 61 0b 01 f2
Logic data: https://ibb.co/7Qm9MTP
@MurzzZ actually I also merged this other commit https://github.com/espressif/arduino-esp32/pull/3713 I don't know if it will solve your problems because after seeing so many errors with the esp32 I moved to the MEGA board for the development of the library. It was safer and I didn't want to debug errors that weren't created by my code
I am sure that the esp32 would be a good board but it is better to wait for these changes to be inside the official release
@aster94 I'v checked latest version (with manualy corrected esp32-hal-uart.c) with the ECU. and it's working!
Receiving: 80
- format physical F1
- ECU is communicating with us 11
- comes from the ECU 4
- data bytes coming (HEX) 61
- data 5
- data CD
- data 40
- data F9
- checksum
End of response
Bytes received: 8
Correct checksum
Correct response from the ECU
Sending Echo
80 80
11 11
F1 F1
2 2
21 21
6 6
AB AB
Receiving: 80
- format physical F1
- ECU is communicating with us 11
- comes from the ECU 3
- data bytes coming (HEX) 61
- data 6
- data 8B
- data 77
- checksum
End of response
Bytes received: 7
Correct checksum
Correct response from the ECU
---- SENSORS ----
Calculated: 0 milliseconds ago
GPS: 0
CLUTCH: 0
RPM: 0
Speed: 0
TPS: 0
STPS: 0
IAP: 50
IAT: 98
ECT: 56
VOLT: 0.00
---- ------- ----
Keeping connection alive
Last:1501
But this is still unusible for the emulator because the HEX data in serial is corrupted. So if I find something else, I will write to you.
And another question, what is the best way to initialize an ECU without debugging?
it's working!
Great! I am very happy to read this 😁 If you would ever test with other motorbikes keep me informed, I would be happy to bring the library to other models 😀
And another question, what is the best way to initialize an ECU without debugging?
Just delete this line ECU.enableDebug(&debug, DEBUG_LEVEL_VERBOSE, 115200);
Or, better, you can enable the debug in the setup and you can make a function that change the debug level using this function setDebugLevel();
you can choose between DEBUG_LEVEL_NONE, DEBUG_LEVEL_DEFAULT, DEBUG_LEVEL_VERBOSE
@MurzzZ I am closing the issue, if you have other questions feel free to ask
I'm trying to run basic_sample on M5Stack and something goes wrong when i try to connect with Emulator. here is what i see: Emulator
Starting ECU Emulator Port already opened Port Info: Serial<id=0x3de1e80, open=True>(port='COM7', baudrate=115200, bytesize=8, parity='O', stopbits=1, timeout=2, xonxoff=False, rtscts=False, dsrdtr=False) You should send me the init sequence! not this: ['0x0', '0x0', '0x0', '0x0', '0x0']
Debug ` User Input: iInitialize K-line Starting sequence
Sending Echo 81 FD 11 F1 ED 81 4
Receiving: 2D - unexpected header FF - ECU is communicating with this address Unexpected response: Initialization failed `