User manual
330
mikoC PRO for dsPIC
MikroElektronika
ECANxSetBaudRate
Prototype
void ECANxSetBaudRate(unsigned int SJW, unsigned int BRP, unsigned int
PHSEG1, unsigned int PHSEG2, unsigned int PROPSEG, unsigned int ECAN_CONFIG_
FLAGS);
Description Sets ECAN module baud rate. Due to complexity of the ECAN protocol, you can not simply force the
bps value. Instead, use this function when ECAN is in Cong mode. Refer to datasheet for details.
SAM, SEG2PHTS and WAKFIL 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.
The ECAN module must be in Cong mode, otherwise the function will be ignored. See
ECANxSetOperationMode.
Example
// set required baud rate and sampling rules
unsigned int ecan_cong_ags;
...
ECAN1SetOperationMode(_ECAN_MODE_CONFIG,0xFF); // set CONFIGURATION
mode (ECAN1 module mast be in cong mode for baud rate settings)
ecan_cong_ags = _ECAN_CONFIG_SAMPLE_THRICE & // Form value to
be used
_ECAN_CONFIG_PHSEG2_PRG_ON & // with
ECAN1SetBaudRate
_ECAN_CONFIG_XTD_MSG &
_ECAN_CONFIG_MATCH_MSG_TYPE &
_ECAN_CONFIG_LINE_FILTER_OFF;
ECAN1SetBaudRate(1, 3, 3, 3, 1, ecan_cong_ags); // set ECAN1 module
baud rate
Notes - 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.