User manual

Table Of Contents
mikroC PRO for PIC32
MikroElektronika
275
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 Cong mode.
SAM, SEG2PHTS and WAKFIL bits are set according to CANSPI_CONFIG_FLAGS value. Refer to
datasheet for details.
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)
- CANSPI_CONFIG_FLAGS is formed from predened constants. See CANSPI_CONFIG_FLAGS
constants.
Returns Nothing.
Requires The CANSPI module must be in Cong 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 cong 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.