CAN BUS message sending when receiving a trigger CAN message

Hello. I can't code but maybe somebody has an example of a code that can send can bus message after it has received a specific message? What I need to do is set letters N, D and R on the dashboard cluster in a car when gear shifter position is selected. With a gear shifter position change the car sends a message with the same ID where it changes first 2 bytes for each position N, D and R. Now I need the arduino to capture each message from the gear shifter and start sending one of the 3 possible messages back onto the can bus at a specified rate (in ms) until another message is received that would trigger another one of the 3 messages. I don't know if I should use a DUE with 2 SN65HVD230 transcievers for this which I have but never used before - I am not sure how to use it with it lacking EEPROM etc it might be too difficult to set up as I don't code but I could follow instructions. Or would arduino UNO and a MCP2515 shield would be sufficient which I have used with simple example programs to send can messages. Does anybody have any code that would do something like the above? I could fill in my messages or edit a little bit? Thank you very much.

Ok so I set up arduino DUE with two SN65HVD230 Can transcievers and due_can and can_common libraries and to my surprise it works - apparently DUE is saving parameters to it's flash. I used an example from the library that works as a bridge between two buses (actually it is the same bus I just cut the wires and placed Due in the middle to connect the bus back up) both ways but first modifies some frames. Now I need help with the code. I did use 3 if statements to change the messages from the gear lever into messages that I found should engage the correct image on the dashboard cluster. It works on the bench but sadly not in the car and I don't know why. When I wire it in the car it does not execute any of the first 3 if statements and simply does not send the required message although it passes all the other traffic through. Code below. I only need it to execute one of those if statements at a time depending on where the gear lever is. Can I use any other statements not to modify the gear lever message itself (ID 302) but modify the original displaying message (ID 303)? I don't code but how would I write a code to do the following: if ID 302 data byte[0] is 0x01 then change a message with ID 303 data byte[1] to 0x02 etc? So as not to change id 302 into 303 but change 303 into 303 but with different data bytes when message 302 is received. Thanks

Hi marty900, could you share the link or the libraries you used for your project? Would you share the code too? I built my own CAN bridge, but i'd like to follow the example you mentioned in order to understand better how to receive a frame message to one CAN port, modify it and send the frame message modified to the other port...thank you a lot

@marty900 @cluster92 not sure if you got these working since but i've got an example code to gateway messages (passing some through and modifying others) here https://togglebit.net/how-to-gateway-messages/

Also i'm crowdfunding a new more rugged package for these type applications on CrowdSupply, as the new CANFD standard has been put into production. Would like any feedback! https://www.crowdsupply.com/togglebit/canfduino

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.