How Can I Set Custom or Nonstandard Baud Rates in NI-CAN?

Updated Apr 28, 2023

Reported In

Hardware

  • USB-8473

Driver

  • NI-CAN

Issue Details

I understand that NI-CAN supports many nonstandard baud rates. How can I use nonstandard baud rates? Also, how can I programmatically write to the bit timing registers?

Solution

In order to specify custom baud rates, you will need to manually assign either the Bit Timing Register Values formatted as a hexadecimal value or by editing the Segment of the Bit Timing Register.  Depending on your software, and which API you are using will dictate how to do this.

To programmatically change the baud rate in your CAN application, you will be using the ncSetAttr.vi which can be found under Measurement I/O»CAN»Frame API»Advanced on the Functions Palette.  This function inputs the Object Handle, the Attribute ID, the Attribute Value, and an error input.  To change the baud rate, select Baud Rate from the AttrID connector Enum and create either a constant or an indicator for AttrValue.

For standard baud rates, you can manually enter the decimal value of that baud rate.  For examples, 125000 baud is a standard rate.  A list of standard baud rates can be found in Measurement & Automation Explorer as part of the drop-down menu under Properties for a CAN port.

To set a baud rate that is not listed from that list requires a different approach.  For example, if you wanted to set a baud rate of 533333 baud, you will need to manually set this value.  To do this, open Measurement & Automation Explorer and right-click on a CAN port and select Properties.

From here, select Advanced and click Baud Rate.

From this point, you will need to set your baud rate.  In this case, we are using 533.333 kBaud. Keep in mind that this field is in units of kilobaud.  It is important to note that there are some values that are not possible to achieve.  If you enter an invalid number, you will get a message similar that reads:

Baud Rate will be changed to the nearest valid value (xxx.yyy kBaud)
Where xxx.yyy is the closest valid baud rate to value you entered

After entering this value, click Create List.  From this point, select one of the Bit Timing Registers that the list has generated and select Use.

At this point, your Port Properties window should like like the image found below.  Notice that the baud rate is the baud rate that you requested.  More importantly however are the values found in BTR1 and BTR0 boxes shown in the image below, in this case BTR0=0x00 and BTR1=0x66.  These values are hexadecimal values which is indicated by the prefix 0x.

The BTR values are the values we need to programmatically change the baud rate.  In your program, you will use the ncSetAttr.vi with the AttrID value set to Baud Rate and the AttrValue set to the appropriate hexadecimal value which is determined below.

For non-standard baud rates, the ncSetAttr.vi is expecting a hexadecimal value from AttrValue formatted in the following way:
AttrValue = 8000XXYY where
XX = the value of BTR1
YY = the value of BTR0

In our case of 533.333 kBaud, our AttrValue will be 80006600. 

Entering the AttrValue will update the BTR0 and BTR1 registers to set the Baud Rate.