Mikroelektronika MIKROE-442 데이터 시트

다운로드
페이지 726
mikroBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
255
CANxWrite
Prototype
sub function CANxWrite(dim id as longintdim byref data_ as byte[1], dim 
dataLen, CAN_TX_MSG_FLAGS as word) as word
Description If  at  least  one  empty  Transmit  Buffer  is  found,  the  function  sends  message  in  the  queue  for 
transmission.
Parameters 
id
: CAN message identifier. Valid values: 11 or 29 bit values, depending on message type (standard 
or extended) 
data
: data to be sent  
dataLen
: data length. Valid values:
 0..8 
CAN_RX_MSG_FLAGS
: message flags. Valid values: 
CAN_TX_MSG_FLAGS
 constants. See CAN_TX_
MSG_FLAGS constants. 
Returns
0
 if all Transmit Buffers are busy 
0xFFFF
 if at least one Transmit Buffer is available 
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
‘ send message extended CAN message with appropriate ID and data
dim tx_flags as word
    data as byte[8]
    msg_id as longint
...
CAN1SetOperationMode(_CAN_MODE_NORMAL,0xFF)  ‘ set NORMAL mode (CAN1 must 
be in mode in which transmission is possible)
tx_flags = _CAN_TX_PRIORITY_0  and            
           _CAN_TX_XTD_FRAME   and             
           _CAN_TX_NO_RTR_FRAME              ‘ set message flags
CAN1Write(msg_id, data, 1, tx_flags)
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.