User manual
mikroC PRO for dsPIC
MikroElektronika
327
ECANxInitialize
Prototype
void ECANxInitialize(unsigned int SJW, unsigned int BRP, unsigned int
PHSEG1, unsigned int PHSEG2, unsigned int PROPSEG, unsigned int ECAN_CONFIG_
FLAGS);
Description Initializes the ECAN module.
The internal ECAN module is set to:
- Disable ECAN capture
- Continue ECAN operation in Idle mode
- Abort all pending transmissions
- Clear all transmit control registers
- Fcan clock : Fcy (Fosc/2)
- Baud rate is set according to given parameters
- ECAN mode is set to Normal
- Filter and mask registers remain unchanged
SAM, SEG2PHTS, WAKFIL and DBEN bits are set according to the ECAN_CONFIG_FLAGS value.
Parameters - SJW as dened in MCU’s datasheet (ECAN Module)
- BRP as dened in MCU’s datasheet (ECAN Module)
- PHSEG1 as dened in MCU’s datasheet (ECAN Module)
- PHSEG2 as dened in MCU’s datasheet (ECAN Module)
- PROPSEG as dened in MCU’s datasheet (ECAN Module)
- ECAN_CONFIG_FLAGS ECAN module conguration ags. Each bit corresponds to the appropriate
ECAN module parameter. Should be formed out of predened ECAN ag constants. See ECAN_
CONFIG_FLAGS constants.
Returns Nothing.
Requires The ECAN routines are supported only by MCUs with the ECAN module.
Microcontroller must be connected to ECAN transceiver which is connected to the ECAN bus.
Example
// initialize the ECAN1 module with appropriate baud rate and message
acceptance ags along with the sampling rules
unsigned int ecan_cong_ags;
...
ecan_cong_ags = _ECAN_CONFIG_SAMPLE_THRICE & // Form value to be
used
_ECAN_CONFIG_PHSEG2_PRG_ON & // with
ECANInitialize
_ECAN_CONFIG_XTD_MSG &
_ECAN_CONFIG_MATCH_MSG_TYPE &
_ECAN_CONFIG_LINE_FILTER_OFF;
ECAN1Initialize(1, 3, 3, 3, 1, ecan_cong_ags); // initialize the ECAN1
module
Notes - ECAN mode NORMAL will be set on exit.
- ECAN library routine require you to specify the module you want to use. To select the desired ECAN
module, simply change the letter x in the routine prototype for a number from 1 to 2.
- Number of ECAN modules per MCU differs from chip to chip. Please, read the appropriate datasheet
before utilizing this library.