User manual
294
mikoC PRO for dsPIC
MikroElektronika
CANSPISetBaudRate
Prototype
void CANSPISetBaudRate(char SJW, char BRP, char PHSEG1, char PHSEG2, char
PROPSEG, char CANSPI_CONFIG_FLAGS);
Returns Nothing.
Description Sets the CANSPI module baud rate. Due to complexity of the CAN protocol, you can not simply force
a bps value. Instead, use this function when the CANSPI module is in Cong mode.
SAM, SEG2PHTS and WAKFIL bits are set according to CANSPI_CONFIG_FLAGS value. Refer to
datasheet for details.
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)
- CANSPI_CONFIG_FLAGS is formed from predened constants. See CANSPI_CONFIG_FLAGS
constants.
Returns Nothing.
Requires The CANSPI module must be in Cong mode, otherwise the function will be ignored. See
CANSPISetOperationMode.
The CANSPI routines are supported only by MCUs with the SPI module.
MCU has to be properly connected to mikroElektronika’s CANSPI Extra Board or similar hardware.
See connection example at the bottom of this page.
Example
// set required baud rate and sampling rules
char CANSPI_CONFIG_FLAGS;
...
CANSPISetOperationMode(_CANSPI_MODE_CONFIG,0xFF); // set CONFIGURATION
mode (CANSPI module must be in cong mode for baud rate settings)
CANSPI_CONFIG_FLAGS = _CANSPI_CONFIG_SAMPLE_THRICE &
_CANSPI_CONFIG_PHSEG2_PRG_ON &
_CANSPI_CONFIG_STD_MSG &
_CANSPI_CONFIG_DBL_BUFFER_ON &
_CANSPI_CONFIG_VALID_XTD_MSG &
_CANSPI_CONFIG_LINE_FILTER_OFF;
CANSPISetBaudRate(1, 1, 3, 3, 1, CANSPI_CONFIG_FLAGS);
Notes None.