gicking / LIN_master_portable_Arduino

Portable LIN Master Node Emulation for Arduino
MIT License
9 stars 2 forks source link

Sending messages to LIN #2

Closed axeless closed 12 months ago

axeless commented 12 months ago

Greetings. Please tell me which transceiver to use? I have a mcp2004a and tja1020. But I can’t figure out how to send a message to the bus. I would be grateful if you write to send and read messages from the bus.

gicking commented 12 months ago

hi Iliyas,

both LIN transceivers should do. I assume that you just haven't switched the transceiver to "normal mode" (tja1020), respectively "operation mode" (mcp2004a). Basically you first have to fully activate the LIN transceiver. Of course this is assuming that the electrical connections are correct...?

For details please see pages 3, 4 and 14 in tja1020 datasheet, respectively pages 1, 4 and 7 in mcp2004a datasheet.

axeless commented 12 months ago

hi Iliyas,

both LIN transceivers should do. I assume that you just haven't switched the transceiver to "normal mode" (tja1020), respectively "operation mode" (mcp2004a). Basically you first have to fully activate the LIN transceiver. Of course this is assuming that the electrical connections are correct...?

For details please see pages 3, 4 and 14 in tja1020 datasheet, respectively pages 1, 4 and 7 in mcp2004a datasheet.

I connected everything according to the datasheet, there are no problems with that. I didn’t find in your examples, sending and reading the bus

axeless commented 12 months ago

Works! I didn't connect the tja1020 fault pin correctly. Now I see messages in lin. But now I have another question, how to correct the CRC?

This sends esp32

image

This is via Lin Hacker

image

As you can see, the checksums are different, but the message is the same.

And 1 more question, as you can see in the first image there is ID B4, with data. When I press a button on the device, the first byte changes. How can I read its state, and change the sendMasterRequest message.

example: ID B4 | 02 00 00 00 00 00 00 --> non press ID B4 | 02 23 00 00 00 00 00 --> where 23 button press ID 78 | 02 00 00 00 00 00 00 --> change on press button ID B4 --> ID 78 | 02 11 00 00 00 00 00

axeless commented 12 months ago

@gicking Help please

gicking commented 12 months ago

Hi Iliyas,

Ad 1) This just seems to be a LIN version mismatch. You can check here that 0x63 is the frame checksum for LIN2.x, and 0xDB is the checksum for LIN1.x. Just change “LIN_Master::LIN_V2” to “LIN_Master::LIN_V1” in your ESP32 code. Please let me know if this solves the checksum issue.

Ad 2) before I can (hopefully) answer your question, I have some of my

If the answer to both questions is yes, then it depends whether you use blocking or non-blocking calls:

Blocking: (see this example)

  1. request data from slave using LIN.receiveSlaveResponseBlocking(Version, Id, NumData, Data[])
  2. the data bytes sent by the slave are stored in Data[]

Non-Blocking: (see this example)

  1. initiate slave response frame using LIN.receiveSlaveResponse(Version, Id, NumData)
  2. wait until frame has completed: LIN.getState() == LIN_Master::STATE_DONE
  3. read frame data using LIN.getFrame(Type, Id, NumData, Data[])
  4. the data bytes sent by the slave are stored in Data[]

Georg

PS: sorry for the 12h response time. I wish I didn't have a day job, then I could be faster... ;-)

axeless commented 12 months ago

Hello. Пlad to hear from you.

I will check the checksum as soon as I buy a new essp 32. I connected it incorrectly and broke it :(

I am sending 2 messages. ID 78, I send with bytes, and B4 I send as a master without bytes, only ID. The bus has a button device that responds to ID B4.

Could you write a small example of how I can read the state of B4, where it changes by pressing the D1 buttons. And if D1 == 23 then change the message in ID 78.

Sorry for my English ;)

gicking commented 12 months ago

sure, just one question: which LIN version do the devices "speak"?

axeless commented 12 months ago

Lin v2

gicking commented 12 months ago

Here is a small example. It does compile, but of course I cannot check whether it works. Let me know if it does.

LIN_Example_ESP32.zip

axeless commented 12 months ago

Thank you for helping. Doesn't work, even stopped sending data to LIN. I think maybe the problem is in LIN(Serial2, PIN_LIN_RX, PIN_LIN_TX, "ESP32");

In the previous one, where simply sending two IDs worked, it was LIN_Master_HardwareSerial_ESP32 LIN(Serial2, PIN_LIN_RX, PIN_LIN_TX, "LIN_HW");

I tried to change it, but nothing worked. There is still silence in the bus.

I checked everything and I have LINv1 Sorry for misleading you

gicking commented 12 months ago

can you please send me your project that (almost) worked?

axeless commented 12 months ago
image

When I started after many reboots esp32. Still, a message went into the bus. But there is an error in the console.

axeless commented 12 months ago

can you please send me your project that (almost) worked?

I used your example with LIN_HardwareSerial_ESP32_Background.ino. I only changed the message IDs

gicking commented 12 months ago

pins Rx and Tx are the same as in the example?

axeless commented 12 months ago

Yes that's right.

image

Now he is sending messages to the bus. But it doesn’t respond to pressing

image
gicking commented 12 months ago

what have you changed that it works now?

gicking commented 12 months ago

and what is the console output for button pressed and not pressed?

axeless commented 12 months ago

what have you changed that it works now?

I changed LIN_Master_HardwareSerial_ESP32 LIN(Serial2, PIN_LIN_RX, PIN_LIN_TX, "LIN_HW");

And filled it in again. After being idle for 1 minute, it started working.

axeless commented 12 months ago
image

The console still shows error 0x4

gicking commented 12 months ago

WTF?

axeless commented 12 months ago

WTF?

If you don’t know, then neither do I))

gicking commented 12 months ago

0x04 = timeout

gicking commented 12 months ago

to me that smells like the Tx path is ok, but receiving doesn't work

gicking commented 12 months ago

for a master request frame 0x04=timeout can only happen if the LIN echo is not received. But you already confirmed that sending works

gicking commented 12 months ago

which transceiver are you using?

axeless commented 12 months ago

image I used this diagram

gicking commented 12 months ago

with ESP32 you should increase R1 to 50k. It is less robust that ATTiny. I assume VD3 is a 3.3V Zener diode?

axeless commented 12 months ago
image

I installed the resistor and now the RX is working. But now there are no messages in LIN

gicking commented 12 months ago

with button pressed? Why is response D[1]=0x03?

axeless commented 12 months ago

D[1]=0x03 - not pressed. D[1]=0x23 - pressed

gicking commented 12 months ago

How do you supply the ESP32? Like in the above picture?

gicking commented 12 months ago

do you have Teamviewer?

axeless commented 12 months ago

yes

gicking commented 12 months ago

can you launch it and give me your ID?

gicking commented 12 months ago

just a sec. Seems like Teamviewer suddenly requires an account

axeless commented 12 months ago

trzkzmv3 new password

gicking commented 12 months ago

I can see your screen :-) Can we phone via Teamviewer?

gicking commented 12 months ago

as requested here's a small project to switch through states 0..3 via a button. To add debouncing I adapted the example found here

You just have to set the master request value D[1] according to countPress sketch_sep26a.zip

axeless commented 12 months ago

Thank you very much for your help.

axeless commented 12 months ago

@gicking Hello again. I figured out why the analyzer did not see the message. The period was too fast.

After adding: unsigned long timeLast = millis(); timeLast = millis();

Everything has returned to normal.

I have other difficulties now. I'm not good at programming, but even chatGPT couldn't help me.

Since I read button presses on a car device, your example does not suit me. If you can help me: I would really appreciate it.

I have the following: When you press the button, 0x23 comes. When you release 0x03. When you press it once, you need to constantly send a message with ID78 and the first byte 33. If you press the button again, then send it with byte 22, and again 11. The fourth time send 00. In this case, the message must be sent constantly. I tried this:

switch(messageCount) { case 0: memset(dataTx, 0x00, 8); dataTx[0] = 0x02; dataTx[1] = 0x33; error = LIN.sendMasterRequestBlocking(LIN_Master::LIN_V1, 0x78, 8, dataTx); Serial.println("1 press"); break; case 1: memset(dataTx, 0x00, 8); dataTx[0] = 0x02; dataTx[1] = 0x22; error = LIN.sendMasterRequestBlocking(LIN_Master::LIN_V1, 0x78, 8, dataTx); Serial.println("2 press"); break; case 2: memset(dataTx, 0x00, 8); dataTx[0] = 0x02; dataTx[1] = 0x11; error = LIN.sendMasterRequestBlocking(LIN_Master::LIN_V1, 0x78, 8, dataTx); Serial.println("3 press"); break; default: Serial.println("END"); break; }

But it didn't work out for me. I don't understand how to send a message all the time. help me please

gicking commented 12 months ago

ad 1) yes, you are correct, I forgot timeLast = millis();. Darn!

ad 2) can you please try LIN_Example_ESP32.zip and let me know if it works

axeless commented 12 months ago

It works!! Thank you.

gicking commented 12 months ago

you're welcome. Happy Coding!

gicking commented 12 months ago

issue solved