Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

Single Wire CAN for NI 8513/2 using C code

Solved!
Go to solution

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?

0 Kudos
Message 1 of 5
(3,441 Views)

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.

 

Single Wire Software Select.png

0 Kudos
Message 2 of 5
(3,438 Views)
Solution
Accepted by Hooovahh

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

0 Kudos
Message 3 of 5
(3,391 Views)

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); 

 

0 Kudos
Message 4 of 5
(3,386 Views)

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.

 

Jeff L
National Instruments
0 Kudos
Message 5 of 5
(3,344 Views)