06-06-2017 10:48 AM
How can I set up my CAN communication for single wire and what all properties need to be set? Is there any example to set up single wire CAN communication?
Solved! Go to Solution.
06-06-2017 10:55 AM - edited 06-06-2017 10:56 AM
I know you specifically asked for C code but until someone else chimes in I'll mention how to do this in LabVIEW, since the interface is shared and this might help you find what you need anyway.
With a session reference in XNet you create a property node under the Interface >> CAN >> Transceiver Type and set it to SW (single wire). The reference comes from the Create Session function.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
06-07-2017 01:19 PM
We have a lot of documentation here in the XNET Hardware and Software Manual. Specifically, I'd recommend taking a look at p. 3-11, which gives an overview of the Single Wire CAN Physical Layer, and pp. 5-277 -- 5-281, which discuss the C syntax for the CAN Transceiver State and CAN Transceiver Type properties.
Hooovahh is correct in his implementation, and the API is the same between LabVIEW and C, so any properties/settings that are accessible in LabVIEW should be usable in C as well.
Nick
Applications Engineer
National Instruments
06-07-2017 01:35 PM - edited 06-07-2017 01:38 PM
Thanks Hooovahh and Nick for your inputs. I got it working right after I posted my question. I used CAN Transceiver State and CAN Transceiver Type properties and CAN communication was normal.
One issue I am facing is setting up baud rate, when I set baud rate explicitly as 33333 it works. But when I try to use "nxAdvCANBaudRate_Set(TimeQuantum, TimeSeg0, TimeSeg1, SyncJumpWidth) macro with BTR values I get error passive error and at times bus-off state.
For BTR values I am using the bus monitor custom Baud Rate utility but those value don't seem to be working from C Code. From Bus monitor they work fine. Any idea what I might be doing wrong?
baudRate = nxAdvCANBaudRate_Set((14 * 25), 54, 23, 15);
06-08-2017 09:56 AM
The values in the bus monitor use the 64 bit version of Interface:64bit Baud Rate and the macro is setup for the 32 bit version.
As the help page shows, the valid ranges for properties is different between the high precision 64 bit version and the normal precision 32 bit versions. Example, a SJW of 15 requires high precision mode (64 bit) because normal precision mode only allows values for 0-3.
The macro can easily be modified to match the 64 bit table shown in the link above.