User manual

254
mikoBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
CANxRead
Prototype
sub function CANxRead(dim byref id as longint, dim byref data as byte[1],
dim dataLen, CAN_RX_MSG_FLAGS as word) as word
Description If at least one full Receive Buffer is found, it will be processed in the following way:
- Message ID is retrieved and stored to location pointed by id pointer
- Message data is retrieved and stored to array pointed by data pointer
- Message length is retrieved and stored to location pointed by dataLen pointer
- Message ags are retrieved and stored to location pointed by CAN_RX_MSG_FLAGS pointer
Parameters - id: message identier address
- data: an array of bytes up to 8 bytes in length
- dataLen: data length address
- CAN_RX_MSG_FLAGS: message ags address. For message receive ags format refer to CAN_RX_
MSG_FLAGS constants. See CAN_RX_MSG_FLAGS constants.
Returns - 0 if nothing is received
- 0xFFFF if one of the Receive Buffers is full (message received)
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 Cong mode, otherwise the function will be ignored. See CANxSetOperationMode.
Example
check the CAN1 module for received messages. If any was received do
something.
dim msg_rcvd, rx_ags, data_len as word
data as byte[8]
msg_id as longint
...
CAN1SetOperationMode(_CAN_MODE_NORMAL,0xFF) set NORMAL mode (CAN1 module
must be in mode in which receive is possible)
...
rx_ags = 0 ‘ clear message ags
if (msg_rcvd = CAN1Read(msg_id, data, data_len, rx_ags)<>0) then
...
end if
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.