User manual
mikroC PRO for dsPIC
MikroElektronika
277
CANxInitialize
Prototype
void CANxInitialize(unsigned int SJW, unsigned int BRP, unsigned int PHSEG1,
unsigned int PHSEG2, unsigned int PROPSEG, unsigned int CAN_CONFIG_FLAGS);
Description Initializes the CAN module.
The internal dsPIC30F CAN module is set to:
- Disable CAN capture
- Continue CAN operation in Idle mode
- Do not abort pending transmissions
- Fcan clock : 4*Tcy (Fosc)
- Baud rate is set according to given parameters
- CAN mode is set to Normal
- Filter and mask registers IDs are set to zero
- Filter and mask message frame type is set according to CAN_CONFIG_FLAGS value
SAM, SEG2PHTS, WAKFIL and DBEN bits are set according to CAN_CONFIG_FLAGS value.
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.
Example
// initialize the CAN1 module with appropriate baud rate and message
acceptance ags along with the sampling rules
unsigned int can_cong_ags;
...
can_cong_ags = _CAN_CONFIG_SAMPLE_THRICE & // Form value to be used
_CAN_CONFIG_PHSEG2_PRG_ON & // with
CAN1Initialize
_CAN_CONFIG_STD_MSG &
_CAN_CONFIG_DBL_BUFFER_ON &
_CAN_CONFIG_MATCH_MSG_TYPE &
_CAN_CONFIG_LINE_FILTER_OFF;
CAN1Initialize(1,3,3,3,1,can_cong_ags); // initialize the CAN1 module
Notes - CAN mode NORMAL will be set on exit.
- 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.