Kvaser Linux CANLIB
|
The bus parameters include the bit rate, the position of the sampling point etc. For a detailed discussion of these parameters, refer to our web site, http://www.kvaser.com; they are also described in most CAN controller data sheets.
Use canSetBusParams to set the bus parameters. CANLIB provides a few default set of parameters for the most common bus speeds; you can specify any of the BAUD_xxx constants (defined in canlib.h) in the call to canSetBusParams and set the other parameters to 0. Here's a list of the BAUD_xxx constants that are currently defined.
Example. To set the bus speed to 500 kbit/s:
stat = canSetBusParams(hnd, BAUD_500K, 0, 0, 0, 0, 0);
To set a bit rate that is not predefined, you have to calculate the appropriate bus parameters yourself. See the on-line help for a detailed explanation of the different parameters you can pass to canSetBusParams.
Example. Set the speed to 111111 kbit/s, the sampling point to 75%, the SJW to 2 and the number of samples to 1:
stat = canSetBusParams(hnd, 111111, 5, 2, 2, 1, 0);
If you feel more comfortable to use the almost-standard way of specifying the bus parameters using the register layout of the 82c200 CAN controller, you can call canSetBusParamsC200 instead.
Example. To set the bus speed to 33.333 kbit/s:
stat = canSetBusParamsC200(hnd, 0x5D, 0x05);
This also sets the sampling point to 87.5% of a bit, and the SJW to 2 quanta.