Mikroelektronika MIKROE-742 데이터 시트

다운로드
페이지 532
CANSPISetBaudRate
191
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroPASCAL PRO for AVR
CHAPTER 6
Prototype
procedure CANSPISetBaudRate(SJW: byte; BRP: byte; PHSEG1: byte;
PHSEG2: byte; PROPSEG: byte; CAN_CONFIG_FLAGS: 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 
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 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
var can_config_flags: 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);