-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Questions and ISO 14230-2 KWP development #11
Comments
You shouldn't have to change anything, for the library it doesn't matter what type of transceiver chip or circuit is used. As long as the Tx and Rx pins both support That being said, the schematic you have it a bit problematic, since the K-line is a 12v data line, it is connected to the Rx pin on your microcontroller through just a 10k resistor. That means that there's still 12v connected to your microcontroller, (although at low current,) it will likely exceed the microcontroller's maximum rating. At the very minimum I would use a voltage divider to drop the K-line from 12v to your microcontrollers level. The bus is a low speed one, so you can get away with a simple voltage divider to drop the voltage, I also used a voltage divider to record the logic analyzer traces.
Okay, remember that that is untested code, see #5. The branch contains quite some debugging statements intended to diagnose problem, please report back on your findings and output from those. If it works I'd love to hear about it because I can then merge it into the master branch. If it doesn't work, please also get back with your findings, we may be able to fix the issues you encounter by inspecting the code and output. What microcontroller are you intending to use? |
Realy appreciate you getting back to me on this. Anyway,
Was looking at the code a little closer after I posted actually didn't see anything I needed to change so not planning on any changes.
I using a Teensy 3.2 so it should work based on the read me. The only change I made was using init to Serial3 and RXpin = 7 with TXpin = 8;
Thanks for the explanation - not very good with circuits as you can tell, that's why I posted the schematic :) I will try a simple voltage divider and give it a try tomorrow. Its a little late here now to try it. Do I still need the rest of the circuit? Actually probably not. Just looked at the other circuit I found:
I will definitely get back to you on the results of my testing. Like I said I have one of chips coming and should be here next week so at least I am using the same circuit as you have. If it works with a simple voltage divider I will let you know as well. Thanks for your help. |
Looks much better, that's a voltage divider that drops 12v to 4.95v. I'd make it drop to 3.3 such that you don't risk exceeding the 5v input tolerance on the pin if there's some ripple on the line because your car alternator produces above 12v, just to be sure. But yeah, I think this should work. Look forward to hearing about your findings. |
Two quick comments, please also try the normal initialisation, some cars respond to both initialisations. Also, I don't quite remember of the top of my head if the actual protocol for KWP is the same as for 9141-2, we may have to do some more work. Secondly, because you have a working OBDlink on hand, it may be helpful to test the Rx side of your circuitry by trying to listen to the working OBD reader you have while it does communication with the bus. Not only will it help verify the Rx side of your circuit, but it will also provide us with information on how we should be communicating with the bus. A small program that just blocks on Testing the Tx side of your circuit should be fairly straightforward, just check if the K-line goes low if you set the teensy pin low. |
Thanks will work on it and let you know how it goes |
Just as a quick update:
This after noon I will test with the ODBLink connected and see if I get anything with just serial reads. UPDATE: Using a splitter odb cable I attached the teensy to one side and the odblink to the other and just using serial3.read() odblink kept losing connection with the Arduino attached - going to try on my windows 7 laptop and just try looking at the port but I have the feeling the same thing is going to happen. Oh, btw you might find this instructable interesting: https://www.instructables.com/id/Low-Cost-OBD2-Communications-on-K-line-ISO-9141-2-/ |
Using a different OS is likely not going to make a difference. If you are unable to sniff the data, it sounds like the interface circuitry doesn't work as it should. Maybe it always pulls the bus low? You may have to remove the 510 pullup to 12v from your circuit, if another device on the K-line provides the pullup. Though I doubt this would be as impactful as losing the connection. May be best / easiest to wait for the transceiver chip, that should rule out the circuitry issues. |
I agree. Estimated date is Thursday - just hate waiting :) UPDATE: Ok. For the heck of it since I had finished putting the third circuit together I finally got it to read the k-line. While I don't think the circuit is right it finally not only wrote the init but it got a message back. Most of the time it was all zeros since init was not successful but periodically it would return: 246, 0, 0, 0, 0, 0, 0, 0. just some added info just in case. |
Hi. Nothing new yet. But I just found your thread on the Teensy forum: https://forum.pjrc.com/threads/24549-OBD-K-Line-Buffer-Circuit/page2. |
Ok. Back again. I finally got the sn65 chip. Wired it up and gave it a test and no go. Pretty sure the wiring is correct. Did a bench test of voltages.
|
First thoughts, did you ensure the EN pin on the Sn65 is pulled high and that nwake is connected to ground? About 1. and 2.; I'm not sure how you measured this, always measure between measuring point and ground. K line should idle at 12v and when active is should go to ground. Setting Tx to high should make the Kline ground, I thought the sn65 had some timeout mechanism in case the mcu locks up or something, it may not hold it at ground indefinitely. If K-line does not idle at 12v, you need the pullup (R1 in the readme). If it doesn't go to ground it may already be pulled up quite a lot, you may want to remove R1 if you had it. Though I'm pretty sure the Sn65 chip can sink a sufficient amount, even with two pullups. It can also be that the KWP init is not working (most likely the issue), in which case I'd try sniff that other OBD reader you have. Just connect the K-line (add no resistors) to the Sn65 and hook the Sn65 up to the serial port of your teensy. Initialiser the serial port at a baudrate of 10400 and try to listen in. I expect that to work 100%, since the SN65 is only acting as a level converter then. |
The bytes after
Checksum is addition of all bytes before the checksum. We expected one byte too many, it is correct if we discard the last
From this webpage I get that the length byte may be omitted in case the format byte specifies the length. So in that care the length byte from your table drops out, and we would indeed see So, that's pretty exciting, the physical layer is confirmed good and the KWP init may even be working. We need to fix the incorrect expected response length, either by changing the Do we know whether the protocol after the initialisation is identical to 9141-2? Or are the requests a different format than the obd ones? Best way to figure this out is probably to listen in on the working OBD device you have. Or just assuming it's identical and giving it a go. |
Please pull the latest version of the
Since I don't have the hardware to test this, could you give it a go and report back? |
Decided to just give it a go until we get past initialization. Results were the same for some reason it still shows initialization success: 0 and just keeps looping. Response is the same. Going to add some more debug statements but just wanted to post this for now. |
Update; Added some debugging statements to your readKWP function and think the problem might be in the checksum:
|
I'm not sure how your sketch came up with |
This is what I used to get the checksum
I will give the update a go and let you know. |
Yeah, give it a go, the mistake was here: if (this->checksum(&(this->buffer[0]), ret_len) == this->buffer[ret_len]) That should've been if (this->checksum(&(this->buffer[0]), ret_len - 1) == this->buffer[ret_len]) Otherwise we include the checksum in the checksum calculation. |
Think you may have to do the same with the
EDIT: Have to go out in a little while. So any changes I will test when I get back. |
You are completely right, I've pushed a fix for that. |
Ok. Made the fix, it passed initialization but messages just timed out. Checking another this: https://www.instructables.com/id/Low-Cost-OBD2-Communications-on-K-line-ISO-9141-2-/ I noticed that the request header to get a PID had to change if using 14230. I made the change and immediately got results;
In the getPID function the message had to be:
Not sure how you want to handle making the difference - a different function or maybe a define for 9140 vs 14230? |
Awesome, good find! Amazing that it's all coming together now!
Lets store a boolean in the class that gets set in both init methods. Then in the request method we can select the appropriate header. I see the header we transmit also has the length of the payload in the first byte. Lets see if we can generalize that with the handshake. I'll whip up something in a bit. Benefit of a boolean over a define is that this way one can write a sketch that support both protocols, which is of course advantageous if we are to try this on a car we don't know what protocol to speak to. |
There you go. Let me know when its ready and I will give another test. |
Shame the architecture of this class isn't as pretty for multiple protocols.I didn't really write it with that in mind, so adding this KWP support is a bit hacky since it requires a different header. I chose to rename the Did the same in the variable length one, modify the request and call the Please try the latest, I've also added a |
Works part way. Getting data but results not printed.
Think where ever you use the message construct
|
If you compare the I spotted another issue in
If we failed on the reading there was no delay between the requests and we probably went out of sync here. I've added an extra delay to compensate for this. |
Ok. Just tried the latest. Worked sometimes - maybe something still out of sync. Most of the time just got the RPM using the example sketch. Here's part of the run:
|
Ok, I think this issue is timing related. I've made some small changes, and added a delay to the However, I think it's the most likely that you'll have to tune the |
As a fyi I did add a 10ms delay between requests in another test I ran in
the sketch and no results were printed.
Guess we are talking about a few Millis at most.
Funny though, in original working version where I juse changed the mesage
heaDer we didn't have that problem.
Will give it a try
…On Sun, Jul 29, 2018, 4:26 PM Ivor Wanders ***@***.***> wrote:
Ok, I think this issue is timing related. I've made some small changes,
and added a delay to the readerKWP sketch.
However, I think it's the most likely that you'll have to tune the
OBD9141_WAIT_FOR_REQUEST_ANSWER_TIMEOUT parameter in the header file, you
likely need to increase it. Or, thinking about it, increase the time
between each request, try that first, the readme specifies that the time
between each request is up to the user. From what I can see in the data is
that we time out on the first request, then start the second request and
while we are doing that the answer from the ECU comes in, which we discard
as the perceived echo, then we write the request to the bus, which we read
as a response. Can you try increasing the said define from the header file
and the delay between requests?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#11 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AFHhxUDMXXmIUU9ySDKUT74b1nH0rgMZks5uLhqNgaJpZM4VNtvl>
.
|
Yeah, that's kinda peculiar I agree... You could try to go back to that version and see if that really worked with the example test? Or just copy the init method and change the header, see if that works... I feel like the current version should be better, but maybe it isn't? :O If just the current init and header change solves all the issues we can go down that route? Thing is that I think we need to populate the first header byte with the length, and the old header didn't do that did it? |
Maybe my assumption is incorrect? And we shouldn't specify the correct length in the request header? Can you change this line to |
You mean just make rbuf[0] = 0xc2 ? |
Yes, in the old requests we sent that value was fixed. I assumed that it should've been just like the response where the lower 5 bits of that byte represent the length of the data. But in our previous working requests that value was always |
Ok. Glad you gave me a couple of things to try.
So I think the solution is just to change the timeout and it will work. Looks like just some cleanup on the additional debug prints and your good to go to update the main branch :) Probably should let everyone know that on the forum that you updated the lib and it was also tested on a T3.5 as well
|
Cool!
Interesting, that tells us that the ECU doesn't care about the first byte, and they always accept a variable length, instead of reading the value from the first byte. I'll leave the
I'll update that for both protocols, and make it 20 for good measure. Increasing it doesn't have any adverse effects as we only block in I'll update the branch, hopefully the last time. |
Disabled the debug prints (they can be enabled again with the define in the header file) and changed the timeout to |
Ok. Works like a charm:
Think you need to test it on a car that just uses 9140 and not KWP? |
Nice! 🎉
Probably the best to do that yes, given that we touched some of that functionality as well. I'll be sure to test it before merging this. Could be a few weeks, my hardware is at a friend at the moment. I'll also update the readme and point towards this issue when I get around to it. |
Thanks for all the help in getting this working so quickly. Will be a nice addition to your library :) BTW going to give the display sketch a try when I get a chance. I will go ahead and close this and if something else pops up will let you know. Mike |
Just a quick note - I ran the display example and it worked out of the box once I changed the obd.init to odb.initKWP no problem. |
Great! Thanks for letting me know everything is working smoothly now. |
Hi, I am trying to connect to my vehicle network with Arduino and a OBD interface board with TJA1027 transceiver. I tried to run the readerKWP.ino from the examples and the initialization with ECU is failing PS : I took the code from master branch. |
@zakirsheik , the master branch is the right branch, all other branches are stale feature branches that have been merged. Try enabling this define and check if there is even any response coming back from the ECU, that should provide some information as to where the problem lies. In the ideal case you'd sniff communication (with a logic analyzer, or serial port on the transceiver chip) from an OBD reader that is working on your car and compare that to the data from your own PCB and your car. Please don't use this (old) issue for extended discussion, make a new issue if you can't figure it out, I'm not sure I'll be able to help, but others may see the issue if it's unclosed and chime in. |
hi iwanders, thank's for your library, i want to know if it's compatible with iso 14230-4 ( KWP 2000)? A lot of software uses an ELM because it makes it possible to get rid of all headers, checksum. we just do make the request. does it possible with it. Thank's for your answer |
@TeensyDucM , I'm not sure how different 14230-4 and 14230-2 are. Support for normal KWP and 14230-2 was added under #12 and this issue, I'm not sure how 14230-4 differs from this unfortunately. |
hi Ivors,
Please find the fiat documents for the Kline Implementations. In this, you
can see that the implementation is the same as the layout 2. i make you a
pdf files as attached with just elements of dialog . So i think it's the
same like you make in your library.
For the kline function, i understand that you explain. I thook just that
digitalWrite can receive HIGH or LOW only.
thank's
Le mar. 19 nov. 2019 à 01:26, Ivor Wanders <[email protected]> a
écrit :
… @TeensyDucM <https://github.com/TeensyDucM> , I'm not sure how different
14230-4 and 14230-2 are. Support for normal KWP and 14230-2 was added under
#12 <#12> and this issue, I'm not
sure how 14230-4 differs from this unfortunately.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#11?email_source=notifications&email_token=ANZYXDQIGRIDMWGGYP7XT4DQUMXEBA5CNFSM4FJW3PS2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEEMM3SY#issuecomment-555273675>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ANZYXDSRSQRBAYCB6JVZF3LQUMXEBANCNFSM4FJW3PSQ>
.
|
Hi @mjs513 Great it works for you. Could you please let me know your working configuration like....
|
First I have to tell your library makes it easy. So now the questions. I don't have one of the ICs readily available (they are order be about a week to get) but I found another circuit that is floating around out there on the web, see attached:
In looking through the lib I know that it can't really be used directly to drive the circuit. But if I wanted to use this circuit instead of the chip I would have to change several functions. Any suggestions?
BTW I am using the inti_kwp_fast fork.
Thanks
Mike
The text was updated successfully, but these errors were encountered: