User manual
mikroBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
251
CANxSetBaudRate
Prototype
sub procedure CANxSetBaudRate(dim SJW, BRP, PHSEG1, PHSEG2, PROPSEG, CAN_
CONFIG_FLAGS as word)
Description Sets CAN baud rate. Due to complexity of the CAN protocol, you can not simply force a bps value.
Instead, use this function when CAN is in Cong mode. Refer to datasheet for details.
SAM, SEG2PHTS and WAKFIL bits are set according to CAN_CONFIG_FLAGS value. Refer to
datasheet for details.
Parameters - SJW as dened in MCU’s datasheet (CAN Module)
- BRP as dened in MCU’s datasheet (CAN Module)
- PHSEG1 as dened in MCU’s datasheet (CAN Module)
- PHSEG2 as dened in MCU’s datasheet (CAN Module)
- PROPSEG as dened in MCU’s datasheet (CAN Module)
- CAN_CONFIG_FLAGS is formed from predened constants. See CAN_CONFIG_FLAGS constants.
Returns Nothing.
Requires MCU with the CAN module.
MCU must be connected to the CAN transceiver (MCP2551 or similar) which is connected to the CAN
bus.
CAN must be in Cong mode, otherwise the function will be ignored. See CANxSetOperationMode.
Example
‘ set required baud rate and sampling rules
dim can_cong_ags as word
...
CAN1SetOperationMode(_CAN_MODE_CONFIG,0xFF) ‘ set CONFIGURATION mode (CAN1
module must be in cong mode for baud rate settings)
can_cong_ags = _CAN_CONFIG_SAMPLE_THRICE and ‘ Form value to be used
_CAN_CONFIG_PHSEG2_PRG_ON and ‘ with CAN1Initialize
_CAN_CONFIG_STD_MSG and
_CAN_CONFIG_DBL_BUFFER_ON and
_CAN_CONFIG_MATCH_MSG_TYPE and
_CAN_CONFIG_LINE_FILTER_OFF
CAN1SetBaudRate(1,3,3,3,1,can_cong_ags) ‘ set the CAN1 module baud rate
Notes - CAN library routine require you to specify the module you want to use. To use the desired CAN
module, simply change the letter x in the routine prototype for a number from 1 to 2.
- Number of CAN modules per MCU differs from chip to chip. Please, read the appropriate datasheet
before utilizing this library.