Mikroelektronika MIKROE-724 データシート
250
mikoBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
CANxInitialize
Prototype
sub procedure CANxInitialize(dim SJW, BRP, PHSEG1, PHSEG2, PROPSEG, CAN_
CONFIG_FLAGS as 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 defined in MCU’s datasheet (CAN Module)
-
BRP
as defined in MCU’s datasheet (CAN Module)
-
PHSEG1
as defined in MCU’s datasheet (CAN Module)
-
PHSEG2
as defined in MCU’s datasheet (CAN Module)
-
PROPSEG
as defined in MCU’s datasheet (CAN Module)
-
CAN_CONFIG_FLAGS
is formed from predefined 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
flags along with the sampling rules
dim can_config_flags as word
...
can_config_flags = _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
CAN1Initialize(1,3,3,3,1,can_config_flags) ‘ 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.