Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

Set custom bit timing instead of standard baud rate for LIN, CAN, CAN-FD from XNET C API

 

"nixnet.h" provided a function "nxAdvCANBaudRate_Set" which calculated baud rate from bit timings.

 

I would like to know how this calculation works for  LIN, CAN, and CAN-FD?

 

Can some one explain it in brief with some examples  ? how to find out what parameters to "nxAdvCANBaudRate_Set" function will give me a valid baud valid?

 

// Session properties (including runtime interface properties)

   // Macro to set nxPropSession_IntfBaudRate for an advanced CAN baud rate (bit timings)
   // If you pass a basic baud rate like 125000 or 500000, NI-XNET calculates bit timings for you
#define nxAdvCANBaudRate_Set(TimeQuantum, TimeSeg0, TimeSeg1, SyncJumpWidth) ( \
            (((u32)TimeQuantum) & 0x0000FFFF) | \
            (((u32)TimeSeg0 << 16) & 0x000F0000) | \
            (((u32)TimeSeg1 << 20) & 0x00700000) | \
            (((u32)SyncJumpWidth << 24) & 0x03000000) | \
            ((u32)0x80000000) )

 

0 Kudos
Message 1 of 5
(5,065 Views)

I referred to following section in the documentation but was not able to undertand how I would make a general function using "nxAdvCANBaudRate_Set" so that I can set speed for CAN, LIN, CAN-FD.

 

I plan on creating a function where a speed is passed and the function would store those values in a struct (TimeQuantum, TimeSeg0, TimeSeg1, SyncJumpWidth) and use this struct during create session.

 

http://www.ni.com/pdf/manuals/372840k.pdf#page=1049

 

http://www.ni.com/pdf/manuals/372840k.pdf#page=983

 

For LIN session

As a test I passes "l_baud = nxAdvCANBaudRate_Set(125, 8, 1, 1);" I got l_baud = 2165833853 (0x8118007D) which I assume means baud rate of 125 kbps

 

Any help is appreciated.

 

 

 

 

 

0 Kudos
Message 2 of 5
(5,043 Views)

I have not used that function before, but the NI X-NET Hardware and Software Manual has a ton of information on the C API. I would suggest taking a look in there (starting on page 5-1).

 

NI X-NET Hardware and Software Manual

http://www.ni.com/pdf/manuals/372840h.pdf

 

I also do know that you can set custom baud rates in LabVIEW; it could be helpful to look at some resources for LV and then map it to the C API. For example, I'll include the following link for your reference:

 

How Can I Set Custom Baud Rates on XNET Devices?

http://digital.ni.com/public.nsf/allkb/EED45251DB3B870786257736006A722B?OpenDocument

 

Best of luck!

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

Thanks TheXiadow

 

I referred following link you suggested and it helps me to get started. Looks like for LIN and CAN (speed from 5 kbaud to 1000 kbaud) I can use this method to findout what would be the "TimeQuantum, TimeSeg0, TimeSeg1, SyncJumpWidth" parameters.

 

 

How Can I Set Custom Baud Rates on XNET Devices?

http://digital.ni.com/public.nsf/allkb/EED45251DB3B870786257736006A722B?OpenDocument

 

 

But how do I set custom speed for CAN-FD "set property for nxPropSession_IntfCanFdBaudRate"? Is it even possible? 

0 Kudos
Message 4 of 5
(4,991 Views)

If you look in the NI-XNET manual I linked in my last post, there is information about setting custom baud rates for specifically the nxPropSession_IntfCanFdBaudRate property. On pages 5-268 and 5-269, it provides information on when you set the upper nibble to clear (you can set numeric baud rates) and when you set the upper nibble to 0x8 (you can set custom baud rate programming).

0 Kudos
Message 5 of 5
(4,967 Views)