User manual

278
mikoC PRO for dsPIC
MikroElektronika
CANxSetBaudRate
Prototype
void CANxSetBaudRate(unsigned int SJW, unsigned int BRP, unsigned int PHSEG1,
unsigned int PHSEG2, unsigned int PROPSEG, unsigned int CAN_CONFIG_FLAGS);
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
unsigned int can_cong_ags;
...
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 & // Form value to be used
_CAN_CONFIG_PHSEG2_PRG_ON & // with CAN1SetBaudRate
_CAN_CONFIG_STD_MSG &
_CAN_CONFIG_DBL_BUFFER_ON &
_CAN_CONFIG_MATCH_MSG_TYPE &
_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.