CANBUS Receiving Hardware ID - Page 1
Forum section: electronics / general

author: Sparky84
author_rank: Newbie
timestamp: June 23, 2025, 10:44:33 am
content: Hello,I am using a Arduino Due and I am struggling to communicate with a CAN hardware device and receive back its hardware ID. To confirm the Arduino Due CAN interface is wired correctly, I have done the example ping pong test and this works great.Program structure:Send *IDN? to CAN hardware device and receive back ID and print to terminal.Looking at my attached code, can you see any obvious mistakes?Many thanks in advance.Thanks,Sparky84Code:// Required libraries#include "variant.h"#include <due_can.h>//Leave defined if you use native port, comment if using programming port#define Serial SerialUSBvoid setup(){Serial.begin(115200);// Initialize CAN0, Set the proper baud rates hereCan0.begin(CAN_BPS_250K);Can0.watchFor();}void sendData(){CAN_FRAME outgoing;outgoing.id = 0x00; // ***** 0x400outgoing.extended = false;outgoing.priority = 4; //0-15 lower is higher priorityoutgoing.data.byte = 0x00;outgoing.data.byte = 0x2a; // *outgoing.data.byte = 0x49; // Ioutgoing.data.byte = 0x44; // Doutgoing.data.byte = 0x4e; // Noutgoing.data.byte = 0x3f; // ?outgoing.data.byte = 0x00;outgoing.data.byte = 0x00;Can0.sendFrame(outgoing);}void loop(){CAN_FRAME incoming;static unsigned long lastTime = 0;if (Can0.available() > 0){Can0.read(incoming);for (int count = 0; count < incoming.length; count++){Serial.print(incoming.data.bytes, HEX);}Serial.print("\r\n");}if ((millis() - lastTime) > 1000){lastTime = millis();sendData();}}

author: Siwastaja
author_rank: Super Contributor
timestamp: June 23, 2025, 10:54:06 am
content: What is this "CAN hardware device" and why do you expect it would respond to the payload you are sending to it? I have never heard about any CAN device using this kind of SCPI-like protocol.One small obvious mistake in code is not setting the length field.

author: Sparky84
author_rank: Newbie
timestamp: June 23, 2025, 11:08:25 am
content: Hello Siwastaja,I am trying to communicate with an obsolete RF switch. It is a bit of a last ditch attempt to save an expensive part. I have found an old datasheet (not available on the internet) and I am trying to get initial comms with the switch. My first step is to try and retrieve the device ID, which is not currently working. So after checking the wiring, I was just confirming my code. Should the CAN message start at byte or byte? And would you say I am sending the message correctly.Many thanks,Sparky84

author: Siwastaja
author_rank: Super Contributor
timestamp: June 23, 2025, 11:33:02 am
content: Well, what does that datasheet say about communications? Is there any kind of specification of the communication protocol?Easiest way to check if the CAN packet is emitted correctly is to get another CAN interface (any USB CAN converter) and connect it to the same bus, and sniff the traffic.Also, if your aim is to make that RF switch operate, and not write your own piece of CAN software, you can remove a lot of unknowns by just using a USB-CAN converter on an usual PC instead of writing an Arduino project.

author: Sparky84
author_rank: Newbie
timestamp: June 23, 2025, 11:55:13 am
content: The switch is essentially a black box with a 4 wire interface:1) 24V2) CAN_L3) CAN_H4) RTNHowever I do know the below software (see app note link) from NI used to talk to the RF switch. On page 3 I am trying to send it the *IDN? command. I will take your advice and try the USB-CAN on a PC route to speed up my testing time.https://www.mpgdover.com/content/dam/mpg/documents/manuals/CANbus_switch_GPIB_configuration-DKM.pdfFeel free to post any other ideas / comments.Thanks,Sparky84

author: Siwastaja
author_rank: Super Contributor
timestamp: June 23, 2025, 12:28:06 pm
content: I'm confused. That document talks about a GPIB interface, even suggests an adapter and shows a photograph of the typical GPIB connector.But GPIB is not CAN. You are saying there is only a 4-wire connector clearly with CAN signals.So something's not matching here. Do you have any documentation about the actual product you are trying to communicate with, that you can share?You seem to be expecting that the device would use some sort of GPIB*-over-CAN protocol... What makes you think so?*) not referring to physical signalling, but typical ASCII payload

author: Sparky84
author_rank: Newbie
timestamp: June 24, 2025, 08:15:33 am
content: Hello Siwastaja,I am trying to replicate an old achieve system. I understand the PC was able to send *IDN? through the below system and it would control the switch.* PC(running windows XP and NI CANBUS software) --> GPIB to CAN black box --> RF SwitchDue to the (NI CANBUS software) and (GPIB to CAN black box) no longer being available, I have built the below circuit to send CAN commands to the switch.* Arduino DUE --> CANBUS breakout board --> RF SwitchSee attached for the schematic diagram.Thanks,Spark84

author: Siwastaja
author_rank: Super Contributor
timestamp: June 24, 2025, 09:15:31 am
content: Two possibilities to consider:1) The RF switch has its own CAN protocol (to me this seems likely), and the black box was converting GPIB commands to the RF switch's CAN protocol2) RF switch indeed communicates with the ASCII GPIB commands wrapped in CAN packets (which to me seems strange, but of course it's possible)IMO the first step is to figure out the protocol expected by the RF switch. If no documentation is available, then that means reverse-engineering, and that would be far easier if you had a complete working system (e.g., with said black box) you can sniff.

author: eutectique
author_rank: Frequent Contributor
timestamp: June 24, 2025, 10:08:33 am
content: You might want to see this:https://www.eevblog.com/forum/rf-microwave/how-to-control-dowkey-microwave-coaxial-switch-with-can-interface/msg1149236/#msg1149236

author: m k
author_rank: Super Contributor
timestamp: June 24, 2025, 10:51:09 am
content: Quote from: Siwastaja on June 24, 2025, 09:15:31 amI didn't know that SCPI is an additional layer of GPIB so close that standard commands are the same and must be so.

author: Siwastaja
author_rank: Super Contributor
timestamp: June 24, 2025, 11:40:06 am
content: Quote from: m k on June 24, 2025, 10:51:09 amThanks - I of course mean SCPI. GPIB is just the physical interface, which seemingly is not present here. SCPI messaging nowadays more usually rides on top of asynchronous serial bus (RS232 physical). And it's entirelypossibleto wrap this kind of ASCII character based protocol in CAN packets, by ignoring that CAN bus is not designed for such use in mind and that would not be very optimal use of the bus. I just questioned it because I have never heard about it.But seeing the link posted by eutectique, it seems there after all is a specific CAN protocol (not SCPI) for this RF switch, and what's best, it might be a very simple one. OP should try to send the small binary commands as outlined in that post.

author: Sparky84
author_rank: Newbie
timestamp: June 24, 2025, 12:57:47 pm
content: Hello,Thanks for all your inputs - great find eutectique :-)So essentially moving forward, purchase something like the below USB-CAN controller (note it can work at 10 Kbps to power the switch), and send commands to the switch via a PC.https://thepihut.com/products/usb-to-can-adapterAnd then try to get comms with the switch using Andrey_irk's byte codes:https://www.eevblog.com/forum/rf-microwave/how-to-control-dowkey-microwave-coaxial-switch-with-can-interface/msg1149236/#msg1149236With this confirmed, I can then roll the commands into my C code.Lastly do you notice any errors in my C code or schematic diagram?Thanks,Sparky84

author: HwAoRrDk
author_rank: Super Contributor
timestamp: June 24, 2025, 05:26:02 pm
content: I think it would be infeasible for the device to talk SCPI over raw CAN due to the limitation on length of the data payload of a CAN frame: just 8 bytes. (Although, CAN-FD supports 64, but it sounds like we're not dealing with that here.) You wouldn't be able to fit all but the most trivial of SCPI commands into 8 bytes, even when abbreviating the commands, and many types of response also probably won't fit within that limit.It's therefore likely that the CAN communication has some kind of higher-level protocol layer in-between CAN and SCPI. I'm thinking some kind of multi-frame transport likeISO-TP. Or maybeCANopen.