Mikroelektronika MIKROE-724 データシート

ページ / 726
252
mikoBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
CANxSetMask
Prototype
sub  procedure  CANxSetMask(dim  CAN_MASK  as  word,  dim  val  as  longint,  dim 
CAN_CONFIG_FLAGS as word)
Description Function sets mask for advanced filtering of messages. Given 
value
 is bit adjusted to appropriate 
buffer mask registers.
Parameters 
CAN_MASK
:  CAN  module  mask  number.  Valid  values:
  CAN_MASK
  constants.  See  CAN_MASK 
constants. 
val
: mask register value. This value is bit-adjusted to appropriate buffer mask registers 
CAN_CONFIG_FLAGS
: selects type of message to filter. Valid values: 
- _CAN_CONFIG_ALL_VALID_MSG, 
- _CAN_CONFIG_MATCH_MSG_TYPE & _CAN_CONFIG_STD_MSG, 
- _CAN_CONFIG_MATCH_MSG_TYPE & _CAN_CONFIG_XTD_MSG. 
See CAN_CONFIG_FLAGS constants.  
Returns
Nothing.
Requires
MCU with the CAN module.
MCU must be connected to the CAN transceiver (MCP2551 or similar) which is connected to the CAN 
bus.
CAN must be in Config mode, otherwise the function will be ignored. See CANxSetOperationMode.
Example
‘ set appropriate filter mask and message type value
CAN1SetOperationMode(_CAN_MODE_CONFIG,0xFF) ‘ set CONFIGURATION mode (CAN1 
module must be in config mode for mask settings)
‘ Set all B1 mask bits to 1 (all filtered bits are relevant)
‘ Note that -1 is just a cheaper way to write 0xFFFFFFFF.
‘ Complement will do the trick and fill it up with ones.
CAN1SetMask(_CAN_MASK_B1,  -1,  _CAN_CONFIG_MATCH_MSG_TYPE  and  _CAN_CONFIG_
XTD_MSG)
Notes
- CAN library routine require you to specify the module you want to use. To use the desired CAN 
module, simply change the letter 
x in the routine prototype for a number from 1 to 2
- Number of CAN modules per MCU differs from chip to chip. Please, read the appropriate datasheet 
before utilizing this library.