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 Cong 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 dened in MCU’s datasheet (CAN Module)
- BRP as dened in MCU’s datasheet (CAN Module)
- PHSEG1 as dened in MCU’s datasheet (CAN Module)
- PHSEG2 as dened in MCU’s datasheet (CAN Module)
- PROPSEG as dened in MCU’s datasheet (CAN Module)
- CAN_CONFIG_FLAGS is formed from predened 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 Cong mode, otherwise the function will be ignored. See CANxSetOperationMode.
Example
‘ set required baud rate and sampling rules
dim can_cong_ags as word
...
CAN1SetOperationMode(_CAN_MODE_CONFIG,0xFF) set CONFIGURATION mode (CAN1
module must be in cong mode for baud rate settings)
can_cong_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_cong_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.