User manual

248
mikoPascal PRO for dsPIC30/33 and PIC24
MikroElektronika
CANxInitialize
Prototype
procedure CANxInitialize(SJW, BRP, PHSEG1, PHSEG2, PROPSEG, CAN_CONFIG_
FLAGS : word);
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 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.
Example
// initialize the CAN1 module with appropriate baud rate and message
acceptance ags along with the sampling rules
var can_cong_ags : word;
...
can_cong_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_cong_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.