Mikroelektronika MIKROE-350 Fiche De Données

Page de 526
CANSPISetBaudRate
177
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroBasic PRO for AVR
CHAPTER 6
Prototype
sub procedure CANSPISetBaudRate(dim SJW as bytedim BRP as byte,
dim PHSEG1 
as byte, dim PHSEG2 as byte, dim PROPSEG as bytedim
CAN_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 sub function when the
CANSPI module is in Config mode.
SAM, SEG2PHTS
and 
WAKFIL
bits are set according to 
CAN_CONFIG_FLAGS
value.
Refer to datasheet for details.
Parameters:
SJW
as defined in CAN controller's datasheet 
BRP
as defined in CAN controller's datasheet 
PHSEG1
as defined in CAN controller's datasheet 
PHSEG2
as defined in CAN controller's datasheet 
PROPSEG
as defined in CAN controller's datasheet 
CAN_CONFIG_FLAGS
is formed from predefined constants (see CANSPI constants) 
Requires
The CANSPI module must be in Config mode, otherwise the sub 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 can_config_flags as byte
...  
CANSPISetOperationMode(CANSPI_MODE_CONFIG, 0xFF)              '
set CONFIGURATION mode (CANSPI module mast be in config mode for
baud rate settings)
can_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, can_config_flags)