Skip to content
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

LIN Slave Example #4

Closed
patrickjsimons opened this issue Dec 13, 2022 · 26 comments
Closed

LIN Slave Example #4

patrickjsimons opened this issue Dec 13, 2022 · 26 comments

Comments

@patrickjsimons
Copy link

Is it possible to reuse this library to build an example slave project that connects to either a LIN master implementation or to a physical network in a car?

@gicking
Copy link
Owner

gicking commented Dec 14, 2022

No, not with this library, sorry! A LIN slave library looks very different from a master library.

Actually I've been playing with an Arduino LIN slave library for AVR, but frame synchronization requires special measures. Reason is that LIN slaves use a Sync Break (=>13bit dominant) for frame synchronization. To the slave that looks like 0x00 with a framing error (=no stop bit received). But Arduino Serial() doesn't store the latter information - and in some board implementations not even the data.

For AVR like Arduino Mega I therefore modified the NeoHWSerial library by SlashDevin to store the framing error as well. You find the modified version here. The (largely untested) LIN slave library is not available via Github yet, but I've attached it as LIN_slave.zip

Let me know if that works for you. Have fun,
Georg

@patrickjsimons
Copy link
Author

patrickjsimons commented Dec 14, 2022

Thanks so much for the info and files.

Just a few issues compiling in my environment:

In the example file LIN_Daimler_MRA2.ino should the LIN_master3.h be including from the library: LIN_master_emulation_with_background_operation at version 1.4

It's using the above and there are a few compile errors relating to: "no matching function for call to 'LIN_Master_3::begin(int, LIN_version_t)"

Also there are a few compile errors relating to calling function sendSlaveResponse, which I see is a function included in the LIN_slave.zip file LIN_slave3

PS I'm using the Mega2560 for testing.

Regards,
Patrick

@gicking
Copy link
Owner

gicking commented Dec 14, 2022

oh darn! The example is for a LIN master, not a slave :-( Looks like I have to do some more work...

Forget what I sent you before. I have to clean up the mess first. Sorry!

@patrickjsimons
Copy link
Author

No worries, I was just looking through the code to see if I could fix it by replacing the master references with slave based on the header definitions. The sendSlaveResponse function seems to be in the header file but missing from the cpp.

Just a bit lost now :)

@gicking
Copy link
Owner

gicking commented Dec 14, 2022 via email

@patrickjsimons
Copy link
Author

patrickjsimons commented Dec 14, 2022

I'm working on iBus using an MCP2003 transceiver at the physical layer within a 2004 Range Rover L322. It's BMW's implementation as they owned Land Rover at the time. I retro fitted an Android radio and I'm looking at developing an app that I'll install on the radio that can be used to display and reset non-critical devices while the car is in park mode. The app will eventually communicate beyond the Kline and access other protocols such as CAN, which I'll use to read and reset faults.

The starting point is to receive messages from the steering wheel radio controls, which are working out-of-the box with the retro fitted radio. I first need to simulate on the beach a slave device that is able to control the radio such as volume controls, etc., and I can work my way up to simulating other devices later.

As a staring POC I have two Arduino devices communicating at a very basic level through two MCP2003 chips that are connected to a UNO and Mega device.

@gicking
Copy link
Owner

gicking commented Dec 16, 2022

hi again,
sorry, I don't get all the details of what you plan to do. But I understand you need an example or library for Arduino as LIN slave. So here's what I can do:

  • set up one Arduino as LIN master with 1x master request frame (e.g. set LED state) and 1x slave response frame (e.g. read slave ADC0)
  • create an example (not a generic library) for another Arduino which acts as a LIN slave

As said, LIN slave is not really the problem, but creating a generic library is. But I hope the above already helps you...!?

PS: I'm busy with another project right now, so please don't hold your breath... ;-)

@patrickjsimons
Copy link
Author

patrickjsimons commented Dec 16, 2022

Any help on this is greatly appreciated. I'll continue on in the background to see if I can expand out the POC. It's all exploratory at this stage so not really sure myself about the details.

Transferring data from one Arduino to another via two MCP2003 ICs is quite straightforward.

The hard part for me is getting it working within the context of a real network in my car i.e. when I connect it to the LIN bus I see no data.

The first task I'm trying to solve is viewing the data on the car network when the radio remote steering wheel controls are pressed, and after storing these codes, the second task is to transmit them over a bench setup LIN network that has the radio connected with two Arduino devices: 1 slave and 1 master.

My understanding is there can only be one master device on the network and that the salve devices communicate via the master device. If this is correct, I was looking at using your LIN master project to simulate the LIN master device in the car, and a LIN slave device to simulate the sending of control button presses to the radio via the LIN master.

Am I on the right track here or have I missed the context of what your LIN Master project is intended for?

@gicking
Copy link
Owner

gicking commented Dec 16, 2022 via email

@patrickjsimons
Copy link
Author

patrickjsimons commented Dec 16, 2022

LIN

@patrickjsimons
Copy link
Author

The above shows the high-level bench setup that I'm using. The radio is powered from a car battery and the LIN bus is powered by a seperate 12v power supply. When I connect the radio into the car using three wires i.e. ground, battery, and LIN, the remote steering wheel controls work fine. If I can get it working on the bench, the next test will look at connecting the slave and radio into the car for more testing and to see if it can coexist without conflicts. I'll then build out the slave to have more control over devices and finally interface the slave into the radio app that I intend to build.

@gicking
Copy link
Owner

gicking commented Dec 17, 2022 via email

@patrickjsimons
Copy link
Author

patrickjsimons commented Dec 17, 2022 via email

@gicking
Copy link
Owner

gicking commented Dec 20, 2022

here is a small LIN sniffer project which allows you to log the LIN traffic (but no sending). It requires a modified NeoHWSerial library available from https://github.com/gicking/NeoHWSerial and runs on an Arduino Mega 2560. I believe the code is self explanatory. Please let me know if this works for you

@gicking
Copy link
Owner

gicking commented Dec 20, 2022

if I now understand you correctly, I think that would require creating a new LIN sub-net. So here's my understanding, please correct me if I'm wrong.

  • You want to add a new LIN slave (=Arduino) to the network, which listens and also sends information to the LIN bus (which information and who is the recipient?)
  • the LIN slave also communicates with some Android App (what information and which interface?)
  • the existing vehicle LIN master (=body computer) and LIN slave (=steering wheel control) cannot be modified. The LIN scheduler and frame IDs are fixed

Is my understanding now correct?

If yes, please note some LIN properties, which you should know:

  • all communication is initiated by the master. The master starts each frame by sending BREAK, SYNC, ID (="frame header")
  • after the header either the master continues sending (="master request"), or a slave replies (="slave response") with DATA[0..8], CHK
  • the frame length is fixed for each ID
  • a slave must not respond to a master request ID, and only one slave can respond to a slave response ID. Failure results in garbage on the bus

Especially from the last statement you see that - unless you can change the LIN master scheduler - there is no free frame ID to send data from your slave to the bus.

But before I continue discussing options (LIN sub-bus), please confirm if my above understanding is correct - or correct it. Maybe I'm still missing something...!?

Georg

@patrickjsimons
Copy link
Author

I’m still trying to get my head around this jigsaw puzzle before I get around to actually building the App.

I might be going in the wrong direction, however, I suspect that the only option available for the App is to communicate via the K bus wire on the radio (which I’m assuming is LIN) and the K wire will connect to the Arduino via a LIN transceiver. The Arduino in turn will likely communicate with the diagnostic port as opposed to connecting directly to one of the networks listed in the table below.

I’m assuming that typical diagnostic tools are not acting as LIN slaves when communicating via the diagnostic port?

Directly answering your questions above:

  1. Yes. The initial recipient is the radio and the information is the volume controls etc. Before I can send anything I need to know the destination IDs so hence setting up a slave to passively listen. As it’s an after market Android based radio I think it just passively listens and just responds internally to standard codes. Again the documentation states that the steering wheel control communicates on the K bus.

  2. The recipient and information sent from the App will probably target the Air Suspension module as it is the most problematic device (this is phase two)

  3. Yes. Although I’m not sure, which unit is acting as the master. Also, I could be completely wrong here and the K bus is not based on the LIN protocol, although I do think that K bus is just BMWs terminology for it.

  4. Noted

  5. Noted

  6. In the case for the steering wheel control 1) does the master scheduler cycle through each registered slave to give the slave the opportunity to send a message? 2) for example, when I press a volume up function key, does the control unit queue up the key press and wait for the master to authorise the slave to send the message? 3) Can all slaves continuously read from the bus at the same time?

The purpose of the LIN slave initially is just for experimentation, i.e. there isn’t really any practical example where I would need to simulate the radio controls. However, being able to do this on a bench setup, independent of the car devices, will assist greatly with understanding how these networks work, and hopefully will be useful to others too.

@patrickjsimons
Copy link
Author

patrickjsimons commented Dec 20, 2022

Some additional information to the above which I extracted from the workbook manual:

A number of different types of data bus are incorporated into the vehicle wiring harnesses for the transmission of commands and information between ECU’s.

  1. Controller Area Network (CAN) bus. A network connected between the brake, powertrain, steering and
    suspension related ECU’s

  2. Diagnostic buses. Two networks that, directly and indirectly, connect the diagnostic socket to all of the of the
    ECU’s installed on the vehicle

  3. I bus. A network connected between ECU's of the 'Information' systems

  4. K bus. A network connected between ECU’s of the 'body' systems

  5. M bus. A network connected between the ATC ECU and motors on the heater assembly
  6. P bus. A network connected between the BCU and 'Peripheral' ECU's.

Serial interface circuits in the ECU’s transmit and receive commands and information on the buses as digital messages. ECU’s connected to the same bus use a common protocol (format) and baud rate (transmission speed) for the messages they transmit. The protocol and baud rate varies between bus networks. To enable messages to be exchanged between ECU’s from different bus networks, the instrument pack provides a communication gateway. A microprocessor in the instrument pack converts and/or re-transmits messages between bus networks.

@patrickjsimons
Copy link
Author

Screenshot 2022-12-20 at 20 54 30

@patrickjsimons
Copy link
Author

here is a small LIN sniffer project which allows you to log the LIN traffic (but no sending). It requires a modified NeoHWSerial library available from https://github.com/gicking/NeoHWSerial and runs on an Arduino Mega 2560. I believe the code is self explanatory. Please let me know if this works for you

That's great. I'll set this up to see what I can log.

@hnsmarkt
Copy link

Hello, nice lin master code. i will test it soon...

There is een old project that i worked with. That has an injector and a slave logger tools...
https://github.com/zapta/linbus/tree/master/injector

@patrickjsimons
Copy link
Author

Screenshot 2023-01-05 at 13 07 02

@patrickjsimons
Copy link
Author

I've been working on integrating the Android radio and Arduino into the car, which is taking some time. The above diagram shows how the Arduino integrates to the car via existing harness connections.

The diagram is an extract from a video that I'm in the process of editing, which will show the end-to-end setup, installation and operation. I'm in the process of installing a secondary car battery, which will power the Amp and Arduino. The battery will connect to the main power via an ignition key triggered new relay.

I'll be able to start testing the initial Arduino communications using the LIN Sniffer as soon as the initial installation is complete.

@hnsmarkt thanks for sharing the link, this might come in handy when I move on to building the Android App, which will interface to the Arduino via USB.

@hnsmarkt
Copy link

hnsmarkt commented Jan 5, 2023

@hnsmarkt
Copy link

hnsmarkt commented Jan 5, 2023

i use this (smart) relay for use off a second battery https://www.samlex.com/product/bs-100-dual/ it protects the main (start) battery. It can be triggert by ignistion but it is a option. it checks the voltage of the battery bank. read the manual on the site.
good luck

@patrickjsimons
Copy link
Author

i use this (smart) relay for use off a second battery https://www.samlex.com/product/bs-100-dual/ it protects the main (start) battery. It can be triggert by ignistion but it is a option. it checks the voltage of the battery bank. read the manual on the site.
good luck

This looks like an excellent product for seamlessly adding a secondary battery. In my case I would need to use the connection to the starter motor, which will be activated just at the point the key is fully turned, then it will drop back to normal operation.

@patrickjsimons
Copy link
Author

check this link https://modbmw.com/shop/ibus-interface/ and this one for you'r project http://www.navcoder.com/downloads/NavCoderDownload.htm#navcoderrelease

In my original post above I was using the MCP 2003 transceiver. This was pending delivery of a number of TH3122 transceivers, which are much better as they have built in collision detection. The Modbmw iBus interface above also uses the TH3122 chip.

@gicking gicking closed this as completed Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants