Mikroelektronika MIKROE-724 データシート
mikroBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
267
CANSPISetBaudRate
Prototype
sub procedure CANSPISetBaudRate(dim SJW, BRP, PHSEG1, PHSEG2, PROPSEG,
CANSPI_CONFIG_FLAGS as byte)
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 Config mode.
SAM
,
SEG2PHTS
and
WAKFIL
bits are set according to CANSPI_CONFIG_FLAGS value. Refer to
datasheet for details.
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)
-
CANSPI_CONFIG_FLAGS
is formed from predefined constants. See CANSPI_CONFIG_FLAGS
constants.
Returns
Nothing.
Requires
The CANSPI module must be in Config 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
dim CANSPI_CONFIG_FLAGS as byte
...
CANSPISetOperationMode(_CANSPI_MODE_CONFIG,0xFF) ‘ set CONFIGURATION mode
(CANSPI1 module mast be in config mode for baud rate settings)
CANSPI_CONFIG_FLAGS = _CANSPI_CONFIG_SAMPLE_THRICE and
_CANSPI_CONFIG_PHSEG2_PRG_ON and
_CANSPI_CONFIG_STD_MSG and
_CANSPI_CONFIG_DBL_BUFFER_ON and
_CANSPI_CONFIG_VALID_XTD_MSG and
_CANSPI_CONFIG_LINE_FILTER_OFF
CANSPISetBaudRate(1, 1, 3, 3, 1, CANSPI_CONFIG_FLAGS)
Notes
None.